mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 11:42:25 -05:00 
			
		
		
		
	[feature] Gin enable gzip encoding (#405)
* add gin gzip dependency * add gzip middleware to router * go mod tidy
This commit is contained in:
		
					parent
					
						
							
								23034ec145
							
						
					
				
			
			
				commit
				
					
						a089a98ea9
					
				
			
		
					 11 changed files with 442 additions and 5 deletions
				
			
		
							
								
								
									
										39
									
								
								vendor/github.com/gin-contrib/gzip/gzip.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								vendor/github.com/gin-contrib/gzip/gzip.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,39 @@ | |||
| package gzip | ||||
| 
 | ||||
| import ( | ||||
| 	"compress/gzip" | ||||
| 
 | ||||
| 	"github.com/gin-gonic/gin" | ||||
| ) | ||||
| 
 | ||||
| const ( | ||||
| 	BestCompression    = gzip.BestCompression | ||||
| 	BestSpeed          = gzip.BestSpeed | ||||
| 	DefaultCompression = gzip.DefaultCompression | ||||
| 	NoCompression      = gzip.NoCompression | ||||
| ) | ||||
| 
 | ||||
| func Gzip(level int, options ...Option) gin.HandlerFunc { | ||||
| 	return newGzipHandler(level, options...).Handle | ||||
| } | ||||
| 
 | ||||
| type gzipWriter struct { | ||||
| 	gin.ResponseWriter | ||||
| 	writer *gzip.Writer | ||||
| } | ||||
| 
 | ||||
| func (g *gzipWriter) WriteString(s string) (int, error) { | ||||
| 	g.Header().Del("Content-Length") | ||||
| 	return g.writer.Write([]byte(s)) | ||||
| } | ||||
| 
 | ||||
| func (g *gzipWriter) Write(data []byte) (int, error) { | ||||
| 	g.Header().Del("Content-Length") | ||||
| 	return g.writer.Write(data) | ||||
| } | ||||
| 
 | ||||
| // Fix: https://github.com/mholt/caddy/issues/38 | ||||
| func (g *gzipWriter) WriteHeader(code int) { | ||||
| 	g.Header().Del("Content-Length") | ||||
| 	g.ResponseWriter.WriteHeader(code) | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue