contrib icon indicating copy to clipboard operation
contrib copied to clipboard

Added support for compressed POST requests.

Open oryband opened this issue 10 years ago • 16 comments

Updated tests and example. Added comments to satisfy golint.

Please close and don't merge #36 , this is the updated PR.

oryband avatar May 11 '15 13:05 oryband

may this be a different middleware?

manucorporat avatar May 20 '15 01:05 manucorporat

could be, because it uses different http headers. But I think it better encapsulates gzip library this way.

bolshoy avatar May 20 '15 09:05 bolshoy

@bolshoy I may want to provide gzipped responses but I don't want to with requests. ok, how about this: same package but different middlewares.

manucorporat avatar May 20 '15 09:05 manucorporat

also, I did some changes. Please, pull the last version! https://github.com/gin-gonic/contrib/blob/3c2269fb077feca1b0e6aa61cddfbe775b8230cb/gzip/gzip.go#L18-L36

manucorporat avatar May 20 '15 09:05 manucorporat

@manucorporat different middlewares ok, but there's already a "gzip" folder, so either both of them in subfolders or two separate folders for request/reply gzip support.

bolshoy avatar May 20 '15 11:05 bolshoy

you mean request/response, not "reply"

oryband avatar May 20 '15 11:05 oryband

nah, same folder. KISS, just create a new .go file.

manucorporat avatar May 20 '15 12:05 manucorporat

gin.Use(gzip.Compress(level)) // gzip responses
gin.Use(gzip.Decompress()) // requests 
// gin.Use(gzip.Request()) // ??requests 

or

// choose gzip or deflate (zlib in practice)
gin.Use(compress.Gzip(level)) // gzip responses
gin.Use(compress.Deflate(level)) // zlib responses
gin.Use(compress.Decompress()) // requests (gzip and deflate)
// gin.Use(compress.Request()) // ??requests (gzip and deflate)

or

gin.Use(compress.With(compress.Gzip, compress.Deflate)) // gzip has higher priority
gin.Use(compress.With(compress.Deflate, compress.Gzip)) // deflate has higher priority
gin.Use(compress.With(compress.Gzip)) // only gzip is supported
gin.Use(compress.Requests()) // uncompress requests

manucorporat avatar May 20 '15 12:05 manucorporat

@mopemope

manucorporat avatar May 20 '15 13:05 manucorporat

Also, we should consider to skip compression for already compressed formats. Here a list: gif, jpeg, png, avi, mov, mp3

manucorporat avatar May 20 '15 13:05 manucorporat

@manucorporat

Here are some of the settings we need to consider (loosely based on http://httpd.apache.org/docs/2.2/mod/mod_deflate.html):

compress filters

  • input
  • output

compression format support

  • gzip
  • deflate
  • bzip2, etc

additional compression settings (output only)

  • compression level
  • buf-size etc
  • force-gzip (response always compressed)
  • mime types to compress (default: text/html text/plain text/xml text/css text/javascript application/javascript application/json)

There should be some defaults in case no explicit settings are provided, but the full config may look like this:

inputOptions := map[string]interface{}{
    "format": ["gzip", "deflate", "bzip2"],
}
outputOptions := map[string]interface{}{
    "format": ["gzip", "deflate", "bzip2"],
    "level": 8,
    "buf-size": 8096,
    "force": false,
    "mime-types": ["text/html", "text/javascript", "application/javascript", "application/json"],
}
gin.Use(compress.InputFilter(inputOptions))
gin.Use(compress.OutputFilter(outputOptions))

bolshoy avatar May 21 '15 12:05 bolshoy

@manucorporat we're working on an update for this branch right now to fit v1.0 changes, please don't merge yet. @bolshoy fyi

oryband avatar May 27 '15 09:05 oryband

@manucorporat Separated input and output filters, added output options and mime type detection by URL extension.

bolshoy avatar May 28 '15 13:05 bolshoy

:+1: yay!

please merge :)

oryband avatar May 28 '15 13:05 oryband

@manucorporat maybe merge this? been some time

oryband avatar Jul 27 '15 07:07 oryband

@manucorporat ping

oryband avatar Aug 23 '15 14:08 oryband