Skip to content

Commit

Permalink
Merge pull request #352 from liggitt/revert-content-type
Browse files Browse the repository at this point in the history
Revert content type change
  • Loading branch information
k8s-ci-robot committed Jan 6, 2023
2 parents 5d2cb3a + d69dee3 commit e202aff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
3 changes: 0 additions & 3 deletions pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ func (o *OpenAPIService) RegisterOpenAPIVersionedService(servePath string, handl
return
}
}
contentType := accepts.Type + "/" + accepts.SubType
w.Header().Set("Content-Type", contentType)

// ETag must be enclosed in double quotes: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
w.Header().Set("Etag", strconv.Quote(etag))
// ServeContent will take care of caching using eTag.
Expand Down
38 changes: 15 additions & 23 deletions pkg/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,22 @@ func TestRegisterOpenAPIVersionedService(t *testing.T) {
client := server.Client()

tcs := []struct {
acceptHeader string
respStatus int
respBody []byte
expectedContentType string
acceptHeader string
respStatus int
respBody []byte
}{
{"", 200, returnedJSON, "application/json"},
{"*/*", 200, returnedJSON, "application/json"},
{"application/*", 200, returnedJSON, "application/json"},
{"application/json", 200, returnedJSON, "application/json"},
{"test/test", 406, []byte{}, "application/json"},
{"application/test", 406, []byte{}, "application/json"},
{"application/test, */*", 200, returnedJSON, "application/json"},
{"application/test, application/json", 200, returnedJSON, "application/json"},
{"application/com.github.proto-openapi.spec.v2@v1.0+protobuf", 200, returnedPb, "application/com.github.proto-openapi.spec.v2@v1.0+protobuf"},
{"application/json, application/com.github.proto-openapi.spec.v2@v1.0+protobuf", 200, returnedJSON, "application/json"},
{"application/com.github.proto-openapi.spec.v2@v1.0+protobuf, application/json", 200, returnedPb, "application/com.github.proto-openapi.spec.v2@v1.0+protobuf"},
{"application/com.github.proto-openapi.spec.v2@v1.0+protobuf; q=0.5, application/json", 200, returnedJSON, "application/json"},
{"", 200, returnedJSON},
{"*/*", 200, returnedJSON},
{"application/*", 200, returnedJSON},
{"application/json", 200, returnedJSON},
{"test/test", 406, []byte{}},
{"application/test", 406, []byte{}},
{"application/test, */*", 200, returnedJSON},
{"application/test, application/json", 200, returnedJSON},
{"application/com.github.proto-openapi.spec.v2@v1.0+protobuf", 200, returnedPb},
{"application/json, application/com.github.proto-openapi.spec.v2@v1.0+protobuf", 200, returnedJSON},
{"application/com.github.proto-openapi.spec.v2@v1.0+protobuf, application/json", 200, returnedPb},
{"application/com.github.proto-openapi.spec.v2@v1.0+protobuf; q=0.5, application/json", 200, returnedJSON},
}

for _, tc := range tcs {
Expand All @@ -85,13 +84,6 @@ func TestRegisterOpenAPIVersionedService(t *testing.T) {
if resp.StatusCode != tc.respStatus {
t.Errorf("Accept: %v: Unexpected response status code, want: %v, got: %v", tc.acceptHeader, tc.respStatus, resp.StatusCode)
}
if resp.StatusCode != 200 {
continue
}

if got := resp.Header.Get("Content-Type"); got != tc.expectedContentType {
t.Errorf("Content-Type: Unexpected content type, want: %v, got: %v", tc.expectedContentType, got)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
Expand Down

0 comments on commit e202aff

Please sign in to comment.