You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"net/http""strings""github.com/gin-gonic/gin"
)
funcmain() {
r:=gin.Default()
r.GET("/", func(c*gin.Context) {
// Why not set extra headers as usual (as c.JSON or c.Data)?c.Writer.Header().Set("X-Extra-Header", "extra value")
c.DataFromReader(http.StatusOK, 5, gin.MIMEHTML, strings.NewReader("1234\n"), nil) // If I don't want to set extra headers it crashes
})
r.Run(":5000")
}
Description
gin.Context.DataFromReader
crashes if I don't set extra headers.I think this little fix would be the best solution to keep API and not to compel me to write
map[string]string{}
each time.I also have question why extra headers does not replace global headers here?
https://github.com/gin-gonic/gin/blob/master/render/reader.go#L41
How to reproduce
Expectations
Successful response
Actual result
recovered panic and 500 HTTP response
Environment
The text was updated successfully, but these errors were encountered: