http: prevent HTTP 'connection' header from being added twice (#2480)

* http: prevent HTTP 'connection' header from being added twice

* misc fix

Co-authored-by: sandeep <sandeep@projectdiscovery.io>
This commit is contained in:
M. Ángel Jimeno 2022-08-24 20:55:02 +02:00 committed by GitHub
parent cdb9e617e6
commit ecb3f21076
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -586,7 +586,7 @@ func (h *httpRawUnsafeRequest) Execute(filePath string) error {
ts := testutils.NewTCPServer(nil, defaultStaticPort, func(conn net.Conn) {
defer conn.Close()
_, _ = conn.Write([]byte("HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 36\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nThis is test raw-unsafe-matcher test"))
_, _ = conn.Write([]byte("HTTP/1.1 200 OK\r\nContent-Length: 36\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nThis is test raw-unsafe-matcher test"))
})
defer ts.Close()

View File

@ -237,6 +237,7 @@ func (request *Request) Compile(options *protocols.ExecuterOptions) error {
NoTimeout: false,
FollowRedirects: request.Redirects,
CookieReuse: request.CookieReuse,
Connection: &httpclientpool.ConnectionConfiguration{},
}
// If we have request level timeout, ignore http client timeouts
for _, req := range request.Raw {
@ -248,7 +249,7 @@ func (request *Request) Compile(options *protocols.ExecuterOptions) error {
// if the headers contain "Connection" we need to disable the automatic keep alive of the standard library
if _, hasConnectionHeader := request.Headers["Connection"]; hasConnectionHeader {
connectionConfiguration.Connection = &httpclientpool.ConnectionConfiguration{DisableKeepAlive: false}
connectionConfiguration.Connection.DisableKeepAlive = true
}
client, err := httpclientpool.Get(options.Options, connectionConfiguration)