Skip to content

Commit 932926d

Browse files
committed
fix: check for empty body in response using http.NoBody
1 parent 9a731fd commit 932926d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

responses/validate_body_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,9 @@ paths:
532532
response := &http.Response{
533533
Header: http.Header{},
534534
StatusCode: http.StatusOK,
535-
Body: nil, // invalid response body
535+
// The http Client and Transport guarantee that Body is always non-nil
536+
// and will be set to [http.NoBody] if no body is present.
537+
Body: http.NoBody,
536538
}
537539
response.Header.Set(helpers.ContentTypeHeader, helpers.JSONContentType)
538540

responses/validate_response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func ValidateResponseSchema(
4545

4646
var validationErrors []*errors.ValidationError
4747

48-
if response == nil || response.Body == nil {
48+
if response == nil || response.Body == http.NoBody {
4949
// cannot decode the response body, so it's not valid
5050
violation := &errors.SchemaValidationFailure{
5151
Reason: "response is empty",

0 commit comments

Comments
 (0)