daaku / go.httpgzip

Package httpgzip provides a http handler wrapper to transparently add gzip compression.
https://godoc.org/github.com/daaku/go.httpgzip
62 stars 6 forks source link

Question about content type sniffing #1

Closed cgt closed 11 years ago

cgt commented 11 years ago

What is the purpose of this code in gzipResponseWriter.Write:

if !w.sniffDone {
    if w.Header().Get("Content-Type") == "" {
        w.Header().Set("Content-Type", http.DetectContentType(b))
    }
    w.sniffDone = true
}

When would w.sniffDone ever be true when that first if statement is executed? Wouldn't it be easier to just write w.Header().Set("Content-Type", http.DetectContentType(b))? I may be missing something here, but some clarification would be nice.

Thank you, cgtdk

daaku commented 11 years ago

Thanks for the report -- it was indeed not being used correctly!