mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Avoid repeated initialization
This commit is contained in:
parent
82ec555d70
commit
999c1a21ac
1 changed files with 5 additions and 6 deletions
|
|
@ -475,19 +475,18 @@ type gzipResponseWriter struct {
|
||||||
resp http.ResponseWriter
|
resp http.ResponseWriter
|
||||||
|
|
||||||
gz *gzip.Writer
|
gz *gzip.Writer
|
||||||
contentLength uint64 // total length of the uncompressed response
|
contentLength uint64 // total length of the uncompressed response
|
||||||
written uint64 // amount of written bytes from the uncompressed response
|
written uint64 // amount of written bytes from the uncompressed response
|
||||||
hasLength bool // true if uncompressed response had Content-Length
|
hasLength bool // true if uncompressed response had Content-Length
|
||||||
inited bool // true after init was called for the first time
|
inited atomic.Bool // true after init was called for the first time
|
||||||
}
|
}
|
||||||
|
|
||||||
// init runs just before response headers are written. Among other things, this function
|
// init runs just before response headers are written. Among other things, this function
|
||||||
// also decides whether compression will be applied at all.
|
// also decides whether compression will be applied at all.
|
||||||
func (w *gzipResponseWriter) init() {
|
func (w *gzipResponseWriter) init() {
|
||||||
if w.inited {
|
if w.inited.CompareAndSwap(false, true) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.inited = true
|
|
||||||
|
|
||||||
hdr := w.resp.Header()
|
hdr := w.resp.Header()
|
||||||
length := hdr.Get("content-length")
|
length := hdr.Get("content-length")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue