Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/api/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func NewHTTPClient(opts ClientOptions) (*http.Client, error) {
func inspectableMIMEType(t string) bool {
return strings.HasPrefix(t, "text/") ||
strings.HasPrefix(t, "application/x-www-form-urlencoded") ||
strings.HasPrefix(t, "application/octocat-stream") ||
jsonTypeRE.MatchString(t)
}

Expand Down
56 changes: 56 additions & 0 deletions pkg/api/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,59 @@ func printPendingMocks(mocks []gock.Mock) string {
}
return fmt.Sprintf("%d unmatched mocks: %s", len(paths), strings.Join(paths, ", "))
}

func TestInspectableMIMEType(t *testing.T) {
tests := []struct {
name string
mimeType string
want bool
}{
{
name: "text/plain is inspectable",
mimeType: "text/plain",
want: true,
},
{
name: "text/html is inspectable",
mimeType: "text/html",
want: true,
},
{
name: "application/json is inspectable",
mimeType: "application/json",
want: true,
},
{
name: "application/json with charset is inspectable",
mimeType: "application/json; charset=utf-8",
want: true,
},
{
name: "application/x-www-form-urlencoded is inspectable",
mimeType: "application/x-www-form-urlencoded",
want: true,
},
{
name: "application/octocat-stream is inspectable",
mimeType: "application/octocat-stream",
want: true,
},
{
name: "application/octet-stream is not inspectable",
mimeType: "application/octet-stream",
want: false,
},
{
name: "image/png is not inspectable",
mimeType: "image/png",
want: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := inspectableMIMEType(tt.mimeType)
assert.Equal(t, tt.want, got)
})
}
}