Skip to content
Closed
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 @@ -129,6 +129,7 @@ func NewHTTPClient(opts ClientOptions) (*http.Client, error) {

func inspectableMIMEType(t string) bool {
return strings.HasPrefix(t, "text/") ||
strings.HasPrefix(t, "application/octocat-stream") ||
strings.HasPrefix(t, "application/x-www-form-urlencoded") ||
jsonTypeRE.MatchString(t)
}
Expand Down
21 changes: 21 additions & 0 deletions pkg/api/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ func TestHTTPClient(t *testing.T) {
assert.Equal(t, 200, res.StatusCode)
}

func TestInspectableMIMEType(t *testing.T) {
tests := []struct {
name string
mime string
want bool
}{
{name: "JSON", mime: "application/json", want: true},
{name: "text", mime: "text/plain", want: true},
{name: "form data", mime: "application/x-www-form-urlencoded", want: true},
{name: "octocat stream", mime: "application/octocat-stream", want: true},
{name: "octocat stream with parameters", mime: "application/octocat-stream; charset=utf-8", want: true},
{name: "binary", mime: "application/octet-stream", want: false},
}

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

func TestNewHTTPClient(t *testing.T) {
testutils.StubConfig(t, "")

Expand Down