gin-gonic / gin

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
https://gin-gonic.com/
MIT License
76.74k stars 7.91k forks source link

Transparent decompression for gzip, deflate, etc? #3918

Open skandragon opened 3 months ago

skandragon commented 3 months ago

Description

I expected gzip and deflate and other types to be automatically handed, for some reason, or at least have a common middleware that would handle this. Is this not the case?

How to reproduce

package main

import (
    "github.com/gin-gonic/gin"
)

func main() {
    g := gin.Default()
    g.POST("/json", func(c *gin.Context) {
        var messages []string
        if err := c.ShouldBindJSON(&messages); err != nil {
            c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
                        return
                }

    })
    g.Run(":9000")
}

And now send it compressed requests.

Expectations

I should be able to send compressed data and have it automatically uncompressed.

Actual result

Environment

RedCrazyGhost commented 2 months ago

This requires you to handle the client-side and server-side code yourself. The data has been compressed during network transmission. This issue can be moved to https://github.com/gin-gonic/contrib for questioning https://github.com/rickb777/servefiles Maybe this is to want you.