()
| 50 | } |
| 51 | |
| 52 | func ContentEncoding() gin.HandlerFunc { |
| 53 | return func(c *gin.Context) { |
| 54 | var ( |
| 55 | body io.ReadCloser |
| 56 | err error |
| 57 | ) |
| 58 | |
| 59 | contentEncoding := c.Request.Header.Get("Content-Encoding") |
| 60 | switch contentEncoding { |
| 61 | case "": |
| 62 | body = c.Request.Body |
| 63 | case "gzip": |
| 64 | body, err = gzip.NewReader(c.Request.Body) |
| 65 | default: |
| 66 | err = fmt.Errorf("unsupported content encoding: %s", contentEncoding) |
| 67 | } |
| 68 | |
| 69 | if err != nil { |
| 70 | httpbase.BadRequest(c, err.Error()) |
| 71 | c.Abort() |
| 72 | return |
| 73 | } |
| 74 | defer body.Close() |
| 75 | |
| 76 | c.Request.Body = body |
| 77 | c.Request.Header.Del("Content-Encoding") |
| 78 | |
| 79 | c.Next() |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | func GetCurrentUserFromHeader() gin.HandlerFunc { |
| 84 | userStore := database.NewUserStore() |
no test coverage detected