mirror of https://github.com/daffainfo/nuclei.git
add header nil check (#4766)
parent
236f3fc1e3
commit
4b55c26fc0
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"compress/zlib"
|
"compress/zlib"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -19,11 +20,18 @@ import (
|
||||||
// and fills body buffer with actual response body.
|
// and fills body buffer with actual response body.
|
||||||
func readNNormalizeRespBody(rc *ResponseChain, body *bytes.Buffer) (err error) {
|
func readNNormalizeRespBody(rc *ResponseChain, body *bytes.Buffer) (err error) {
|
||||||
response := rc.resp
|
response := rc.resp
|
||||||
|
if response == nil {
|
||||||
|
return fmt.Errorf("something went wrong response is nil")
|
||||||
|
}
|
||||||
// net/http doesn't automatically decompress the response body if an
|
// net/http doesn't automatically decompress the response body if an
|
||||||
// encoding has been specified by the user in the request so in case we have to
|
// encoding has been specified by the user in the request so in case we have to
|
||||||
// manually do it.
|
// manually do it.
|
||||||
|
|
||||||
origBody := rc.resp.Body
|
origBody := rc.resp.Body
|
||||||
|
if origBody == nil {
|
||||||
|
// skip normalization if body is nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
// wrap with decode if applicable
|
// wrap with decode if applicable
|
||||||
wrapped, err := wrapDecodeReader(response)
|
wrapped, err := wrapDecodeReader(response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -41,6 +49,9 @@ func readNNormalizeRespBody(rc *ResponseChain, body *bytes.Buffer) (err error) {
|
||||||
}
|
}
|
||||||
if stringsutil.ContainsAny(err.Error(), "unexpected EOF", "read: connection reset by peer", "user canceled") {
|
if stringsutil.ContainsAny(err.Error(), "unexpected EOF", "read: connection reset by peer", "user canceled") {
|
||||||
// keep partial body and continue (skip error) (add meta header in response for debugging)
|
// keep partial body and continue (skip error) (add meta header in response for debugging)
|
||||||
|
if response.Header == nil {
|
||||||
|
response.Header = make(http.Header)
|
||||||
|
}
|
||||||
response.Header.Set("x-nuclei-ignore-error", err.Error())
|
response.Header.Set("x-nuclei-ignore-error", err.Error())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue