github.com/blend/go-sdk@v1.20220411.3/web/gzip_middleware.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package web 9 10 import ( 11 "github.com/blend/go-sdk/webutil" 12 ) 13 14 // GZip is a middleware the implements gzip compression for requests that opt into it. 15 func GZip(action Action) Action { 16 return func(r *Ctx) Result { 17 if webutil.HeaderAny(r.Request.Header, webutil.HeaderAcceptEncoding, webutil.ContentEncodingGZIP) { 18 r.Response.Header().Set(webutil.HeaderContentEncoding, webutil.ContentEncodingGZIP) 19 r.Response.Header().Set(webutil.HeaderVary, webutil.HeaderAcceptEncoding) 20 r.Response = webutil.NewGZipResponseWriter(r.Response) 21 } 22 return action(r) 23 } 24 }