@@ -51,8 +51,8 @@ func (c *HttpCtx) Redirect(url string, code int) {
5151 http .Redirect (c .Resp , c .Req , url , code )
5252}
5353
54- func (c * HttpCtx ) WriteString (s string ) {
55- io .WriteString (c .Resp , s )
54+ func (c * HttpCtx ) WriteString (s string ) ( n int , err error ) {
55+ return io .WriteString (c .Resp , s )
5656}
5757
5858func (c * HttpCtx ) SetCookie (k * http.Cookie ) {
@@ -174,6 +174,7 @@ func (h *Midware) head(rw http.ResponseWriter, r *http.Request, conn *tcp.Conn)
174174 writer : nil ,
175175 stdrw : rw ,
176176 acceptEncoding : r .Header .Get ("Accept-Encoding" ),
177+ HeaderRef : rw .Header (),
177178 }
178179
179180 r .Header .Del ("Accept-Encoding" ) // we don't want the backend to encode. WE DO IT.
@@ -207,6 +208,8 @@ type NgResponseWriter struct {
207208 writer io.Writer
208209 stdrw http.ResponseWriter
209210
211+ HeaderRef http.Header
212+
210213 acceptEncoding string
211214
212215 code int
@@ -241,13 +244,13 @@ func (w *NgResponseWriter) Header() http.Header {
241244
242245func (w * NgResponseWriter ) BypassEncoding () {
243246 if w .acceptEncoding != "" {
244- w .Header () .Set ("Accept-Encoding" , w .acceptEncoding )
247+ w .HeaderRef .Set ("Accept-Encoding" , w .acceptEncoding )
245248 w .acceptEncoding = ""
246249 }
247250}
248251
249252func (w * NgResponseWriter ) initForWrite () {
250- w .Header () .Set ("Server" , utils .ServerSign )
253+ w .HeaderRef .Set ("Server" , utils .ServerSign )
251254 switch w .code {
252255 case StatusSwitchingProtocols : // do nothing
253256 return
@@ -256,11 +259,11 @@ func (w *NgResponseWriter) initForWrite() {
256259 w .code = StatusOK
257260 fallthrough
258261 default : // init encode
259- if w .Header () .Get ("Content-Encoding" ) == "" &&
262+ if w .HeaderRef .Get ("Content-Encoding" ) == "" &&
260263 w .acceptEncoding != "" { // if the content hasn't encoded,then we encode it here
261- ContentLength , _ := strconv .ParseUint (w .Header () .Get ("Content-Length" ), 10 , 64 ) // get the content length
262- ContentType := w .Header () .Get ("Content-Type" ) // get the content type
263- IsDownloading := strings .HasPrefix (w .Header () .Get ("Content-Disposition" ), "attachment" ) // check if this request is a download action
264+ ContentLength , _ := strconv .ParseUint (w .HeaderRef .Get ("Content-Length" ), 10 , 64 ) // get the content length
265+ ContentType := w .HeaderRef .Get ("Content-Type" ) // get the content type
266+ IsDownloading := strings .HasPrefix (w .HeaderRef .Get ("Content-Disposition" ), "attachment" ) // check if this request is a download action
264267 switch {
265268 case IsDownloading : // don't encode if is downloading
266269 // case ContentLength <= 1024: // don't encode if size too small
@@ -281,8 +284,8 @@ func (w *NgResponseWriter) initForWrite() {
281284 }
282285 }
283286 if w .encoding != EncodingRAW {
284- w .Header () .Add ("Content-Encoding" , w .encoding .String ())
285- w .Header () .Del ("Content-Length" ) // delete the content length that is no more correct after the encode
287+ w .HeaderRef .Add ("Content-Encoding" , w .encoding .String ())
288+ w .HeaderRef .Del ("Content-Length" ) // delete the content length that is no more correct after the encode
286289
287290 _w := encoderpool [w .encoding ].Get ().(io.Writer ) //get encoder from pool
288291 _w .(reSetter ).Reset (w .stdrw ) // reset the encoder
0 commit comments