Skip to content

Commit de01e72

Browse files
committed
dashboard/app: gcsPayloadHandler ungzip the gcs content
All API handlers expect input stream to be ungzipped. This handler shouldn't be the exception.
1 parent 9d70ccd commit de01e72

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

dashboard/app/api.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ func contextNamespace(c context.Context) string {
174174
return c.Value(&contextKeyNamespace).(string)
175175
}
176176

177+
// gcsPayloadHandler json.Decode the gcsURL from payload and stream pointed content.
178+
// This function streams ungzipped content in order to be aligned with other wrappers/handlers.
177179
func gcsPayloadHandler(handler APIHandler) APIHandler {
178180
return func(c context.Context, payload io.Reader) (interface{}, error) {
179181
var gcsURL string
@@ -194,7 +196,15 @@ func gcsPayloadHandler(handler APIHandler) APIHandler {
194196
if err != nil {
195197
return nil, fmt.Errorf("gcsFile.Reader: %w", err)
196198
}
197-
return handler(c, gcsPayloadReader)
199+
gz, err := gzip.NewReader(gcsPayloadReader)
200+
if err != nil {
201+
return nil, fmt.Errorf("gzip.NewReader: %w", err)
202+
}
203+
// Close() generates error in case of the corrupted data.
204+
// In order to check the data checksum all the data should be read.
205+
// We don't guarantee all the data will be read - let's ignore.
206+
defer gz.Close()
207+
return handler(c, gz)
198208
}
199209
}
200210

0 commit comments

Comments
 (0)