@@ -100,10 +100,10 @@ func (c *CompressResponseWriter) WriteHeader(status int) {
100
100
101
101
func (c * CompressResponseWriter ) Close () error {
102
102
if c .compressionType != "" {
103
- c .compressWriter .Close ()
103
+ _ = c .compressWriter .Close ()
104
104
}
105
105
if w , ok := c .ResponseWriter .(io.Closer ); ok {
106
- w .Close ()
106
+ _ = w .Close ()
107
107
}
108
108
// Non-blocking write to the closenotifier, if we for some reason should
109
109
// get called multiple times
@@ -135,26 +135,36 @@ func (c *CompressResponseWriter) Write(b []byte) (int, error) {
135
135
136
136
if c .compressionType != "" {
137
137
return c .compressWriter .Write (b )
138
- } else {
139
- return c .ResponseWriter .Write (b )
140
138
}
139
+
140
+ return c .ResponseWriter .Write (b )
141
141
}
142
142
143
+ // DetectCompressionType method detects the comperssion type
144
+ // from header "Accept-Encoding"
143
145
func (c * CompressResponseWriter ) DetectCompressionType (req * Request , resp * Response ) {
144
146
if Config .BoolDefault ("results.compressed" , false ) {
145
147
acceptedEncodings := strings .Split (req .Request .Header .Get ("Accept-Encoding" ), "," )
146
148
147
149
largestQ := 0.0
148
150
chosenEncoding := len (compressionTypes )
149
151
152
+ // I have fixed one edge case for issue #914
153
+ // But it's better to cover all possible edge cases or
154
+ // Adapt to https://github.com/golang/gddo/blob/master/httputil/header/header.go#L172
150
155
for _ , encoding := range acceptedEncodings {
151
156
encoding = strings .TrimSpace (encoding )
152
157
encodingParts := strings .SplitN (encoding , ";" , 2 )
153
158
154
159
// If we are the format "gzip;q=0.8"
155
160
if len (encodingParts ) > 1 {
161
+ q := strings .TrimSpace (encodingParts [1 ])
162
+ if len (q ) == 0 || ! strings .HasPrefix (q , "q=" ) {
163
+ continue
164
+ }
165
+
156
166
// Strip off the q=
157
- num , err := strconv .ParseFloat (strings . TrimSpace ( encodingParts [ 1 ]) [2 :], 32 )
167
+ num , err := strconv .ParseFloat (q [2 :], 32 )
158
168
if err != nil {
159
169
continue
160
170
}
0 commit comments