Skip to content

Commit 95c6219

Browse files
committed
debugging
1 parent e0408d5 commit 95c6219

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

response/error.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func HandleAPIErrorResponse(resp *http.Response, sugar *zap.SugaredLogger) *APIE
5454
return apiError
5555
}
5656

57-
mimeType, _ := parseDispositionHeader(resp.Header.Get("Content-Type"))
57+
mimeType, _ := parseHeader(resp.Header.Get("Content-Type"))
5858
switch mimeType {
5959
case "application/json":
6060
parseJSONResponse(bodyBytes, apiError)

response/parse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import "strings"
66
// parseHeader generalizes the parsing of headers like Content-Type and Content-Disposition.
77
// It extracts the main value (e.g., MIME type for Content-Type) and any parameters (like charset).
88
// TODO we need to talk about what this does.
9-
func parseDispositionHeader(header string) (string, map[string]string) {
9+
func parseHeader(header string) (string, map[string]string) {
1010
parts := strings.SplitN(header, ";", 2)
1111
mainValue := strings.TrimSpace(parts[0])
1212

response/success.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func HandleAPISuccessResponse(resp *http.Response, out interface{}, sugar *zap.S
5252
sugar.Debug("LOGHERE-HandleApiSuccessResponse")
5353
sugar.Debugw("Headers:", "content-type", contentType, "content-disposition", contentDisposition)
5454

55-
if handler, ok = responseUnmarshallers[contentType]; ok {
55+
contentTypeNoParams, _ := parseHeader(contentType)
56+
57+
if handler, ok = responseUnmarshallers[contentTypeNoParams]; ok {
5658
return handler(bodyReader, out, sugar, contentType)
5759
}
5860

@@ -125,7 +127,7 @@ func handleBinaryData(reader io.Reader, sugar *zap.SugaredLogger, out interface{
125127
}
126128

127129
if contentDisposition != "" {
128-
_, params := parseDispositionHeader(contentDisposition)
130+
_, params := parseHeader(contentDisposition)
129131
if filename, ok := params["filename"]; ok {
130132
sugar.Debug("Extracted filename from Content-Disposition", zap.String("filename", filename))
131133
}

response/t_parse_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestParseContentTypeHeader(t *testing.T) {
3535

3636
for _, tt := range tests {
3737
t.Run(tt.name, func(t *testing.T) {
38-
gotType, gotParams := parseDispositionHeader(tt.header)
38+
gotType, gotParams := parseHeader(tt.header)
3939
if gotType != tt.wantType {
4040
t.Errorf("ParseContentTypeHeader() gotType = %v, want %v", gotType, tt.wantType)
4141
}
@@ -70,7 +70,7 @@ func TestParseContentDisposition(t *testing.T) {
7070

7171
for _, tt := range tests {
7272
t.Run(tt.name, func(t *testing.T) {
73-
gotType, gotParams := parseDispositionHeader(tt.header)
73+
gotType, gotParams := parseHeader(tt.header)
7474
if gotType != tt.wantType {
7575
t.Errorf("ParseContentDisposition() gotType = %v, want %v", gotType, tt.wantType)
7676
}

0 commit comments

Comments
 (0)