Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] Do not set Referer by default when its value is None #475

Merged
merged 1 commit into from Dec 24, 2013

Conversation

dangra
Copy link
Member

@dangra dangra commented Nov 25, 2013

Another implementation for #473, alternative #474.

closes #473.

@nramirezuy
Copy link
Contributor

I like more this approach than #474

@pablohoffman
Copy link
Member

Me too. How about a test? :)

@redapple
Copy link
Contributor

Well, @dangra knows where to throw in his magic ;-) I had no clue in #474

@dangra
Copy link
Member Author

dangra commented Dec 17, 2013

please review.

headers={'X-Set': '1', 'X-False': '', 'X-Unset': None})
spider = SingleRequestSpider(seed=req)
yield docrawl(spider)
self.assertTrue('response' in spider.meta)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use self.assertIn because we dropped 2.6 support. I believe the advantage is a nicer failure message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed by dangra@3e84c70

@dangra
Copy link
Member Author

dangra commented Dec 17, 2013

I appreciate if someone else can provide some documentation wording for this feature before it's merged.

@dangra
Copy link
Member Author

dangra commented Dec 18, 2013

Looks good to anyone? I'll merge if noone chime in :)

@redapple
Copy link
Contributor

Checked network traffic with Wireshark.
It works as expected for the "Referer" header for example.

@kmike
Copy link
Member

kmike commented Dec 18, 2013

I'd prefer an even more "functional-style" test - e.g. check that Referer header is not set when None is used and is set if None is not used (no explicit Referer header and explicit empty Referer header). Checking for setdefault looks like checking against implementation details.

As for the docs, it seems that "unset" would be a bit misleading - we can't unset a header in Request constructor because the header can be added later by a middleware, and the feature should still work. It is more like "preventing header from being sent".

@dangra
Copy link
Member Author

dangra commented Dec 19, 2013

@kmike: you're right, I'll add a test for Referer header and move the unittest to scrapy.tests.test_http_headers.

@dangra
Copy link
Member Author

dangra commented Dec 24, 2013

@kmike : review latest changes to tests cases.

# start requests doesn't set Referer header
echo0 = json.loads(spider.meta['responses'][2].body)
self.assertNotIn('Referer', echo0['headers'])
# following request set Referer to start request url
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sets

@kmike
Copy link
Member

kmike commented Dec 24, 2013

Looks good!

dangra added a commit that referenced this pull request Dec 24, 2013
[MRG] Do not set Referer by default when its value is None
@dangra dangra merged commit e910255 into scrapy:master Dec 24, 2013
@dangra dangra deleted the 473-do-not-send-header branch December 24, 2013 13:20
pablohoffman added a commit that referenced this pull request Dec 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to not send specific headers in HTTP requests
5 participants