question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Override "Connection" in headers will result in two "Connection" in headers.

See original GitHub issue

If I try to override the “Connection” in the headers with either custome_settings

custom_settings = {
        'DEFAULT_REQUEST_HEADERS': {
            'Connection' : 'Keep-Alive'
        }
}

or within the request headers

headers = {}
 headers['Connection'] : 'Keep-Alive'
 headers['User-Agent'] : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36'

for url in urls:
     yield scrapy.Request(url, headers=headers, callback = self.parse)

It will result with a request with two "Connection"s in the header.

GET http://example.com HTTP/1.1
Connection: close
Connection: Keep-Alive
User-Agent: Scrapy/1.4.0 (+http://scrapy.org)
Accept-Encoding: gzip,deflate

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
cathalgarveycommented, Feb 16, 2018

Hey folks, I fired up Wireshark and tried to reproduce this, with no success, on Python 3.5 and Scrapy 1.5.0.

If I issue the following:

>>> req = scrapy.Request('http://httpbin.org/headers', headers={'Connection': 'wat'})
>>> fetch(req)

…then I see in Wireshark the following request firing:

GET /headers HTTP/1.1
Accept-Language: en
Accept-Encoding: gzip,deflate
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Connection: wat
User-Agent: Scrapy/1.5.0 (+https://scrapy.org)
Host: httpbin.org

(I did try sending ‘keep-alive’ first, and that also works as expected. I just felt like mixing it up a bit).

Interestingly, and disappointingly, the response from httpbin.org/headers always includes the header ‘Connection: close’, reducing its usefulness for debugging this issue.

Can anyone provide me with a reproducible test case so I can further test this?

0reactions
kmikecommented, Mar 10, 2018

@cathalgarvey in a link @tlinhart posted (https://github.com/scrapy/scrapy/issues/2970#issuecomment-360706840) Connection header is set only when body is not None. So it affects POST, PUT and other requests with non-empty bodies; it doesn’t affect usual GET requests, which your Wireshark experiment shows. Though it uses .setdefault, so it shoudn’t override an existing header value…

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to override "Connection : close" in header Scrapy?
Show activity on this post. However the request is not overriding the value. Instead it is just appending another "Connection" into the request ......
Read more >
Connection - HTTP - MDN Web Docs
The Connection general header controls whether the network connection stays open after the current transaction finishes.
Read more >
HTTP headers | Connection - GeeksforGeeks
The HTTP Connection header is a general type header that allows the sender or client to specify options that are desired for that...
Read more >
respond iRule command sends double Connection headers in ...
This is the result of a known issue. The HTTP::respond iRule command sends double Connection headers when using a user-specified Connection: ...
Read more >
HTTP header manipulation - Envoy Proxy
The HTTP connection manager manipulates several HTTP headers both during decoding ... or an https scheme over an unencrypted connection will result in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found