Skip to content
Myr

Fixing User-agent header problem introduced with Python 2.7.1

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by robmadole · committed by robmadole · parent be22804 · Browse files · 2 files+22 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+22 added−11 removed

  • other:+22 added−11 removed

2 files+22 added−11 removed

modified:requests/core.py+14 added-5 removed
120 unmodified lines
121 auth_manager.add_auth(self.url, self.auth)122123 _handlers.append(self.auth.handler)124125 if _handlers:126 _handlers.extend(get_handlers())127 opener = urllib2.build_opener(*_handlers)128 return opener.open129 else:125 if not _handlers:126 return urllib2.urlopen127128 _handlers.extend(get_handlers())129 opener = urllib2.build_opener(*_handlers)130131 if self.headers:132 # Allow default headers in the opener to be overloaded133 normal_keys = [k.capitalize() for k in self.headers]134 for key, val in opener.addheaders[:]:135 if key not in normal_keys:136 continue137 # Remove it, we have a value to take its place138 opener.addheaders.remove((key, val))139140 return opener.open141142 def _build_response(self, resp):143 """Build internal Response object from given response."""144 145 self.response.status_code = getattr(resp, 'code', None)
366 unmodified lines
modified:test_requests.py+8 added-6 removed
27 unmodified lines
28 r = requests.get('https://google.com')29 self.assertEqual(r.status_code, 200)3031 def test_HTTP_200_OK_GET_WITH_PARAMS(self):3232 heads = {'User-agent': 'Mozilla/5.0'}33 34 r = requests.get('http://www.google.com/search', params={'q': 'test'}, headers=heads)35 self.assertEqual(r.status_code, 200)363837 def test_HTTP_200_OK_GET_WITH_MIXED_PARAMS(self):4038 heads = {'User-agent': 'Mozilla/5.0'}3940 r = requests.get('http://google.com/search?test=true', params={'q': 'test'}, headers=heads)41 self.assertEqual(r.status_code, 200)4243 def test_user_agent_transfers(self):44 """Issue XX"""45 heads = {'User-agent':46 'Mozilla/5.0 (github.com/kennethreitz/requests)'}4748 r = requests.get('http://whatsmyua.com', headers=heads);49 self.assertTrue(heads['User-agent'] in r.content)50 51 def test_HTTP_200_OK_HEAD(self):52 r = requests.head('http://google.com')53 self.assertEqual(r.status_code, 200)
15 unmodified lines
69 # reset auto authentication70 requests.auth_manager.empty()7172 def test_POSTBIN_GET_POST_FILES(self):6873 bin = requests.post('http://www.postbin.org/')74 print bin.url75 self.assertEqual(bin.status_code, 200)76
3 unmodified lines
80 post2 = requests.post(bin.url, files={'some': open('test_requests.py')})81 self.assertEqual(post2.status_code, 201)8283 def test_POSTBIN_GET_POST_FILES_WITH_PARAMS(self):8084 bin = requests.post('http://www.postbin.org/')85 86 self.assertEqual(bin.status_code, 200)87
1 unmodified line
89 self.assertEqual(post2.status_code, 201)909192 def test_POSTBIN_GET_POST_FILES_WITH_HEADERS(self):9093 bin = requests.post('http://www.postbin.org/')94 self.assertEqual(bin.status_code, 200)9596 post2 = requests.post(bin.url, files={'some': open('test_requests.py')},
37 unmodified lines