Skip to content

Commit 44bef5d

Browse files
author
j.s@google.com
committed
Allows the Location header in a 302 redirect to be provided as location. Resolves issue 113.
1 parent 3ac0b66 commit 44bef5d

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/gdata/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ def request(self, method=None, uri=None, auth_token=None,
281281
# exists since the redirects are only used in the calendar API.
282282
elif response.status == 302:
283283
if redirects_remaining > 0:
284-
location = response.getheader('Location')
284+
location = (response.getheader('Location')
285+
or response.getheader('location'))
285286
if location is not None:
286287
m = re.compile('[\?\&]gsessionid=(\w*)').search(location)
287288
if m is not None:

src/gdata/service.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,8 @@ def Get(self, uri, extra_headers=None, redirects_remaining=4,
10941094
return feed
10951095
elif server_response.status == 302:
10961096
if redirects_remaining > 0:
1097-
location = server_response.getheader('Location')
1097+
location = (server_response.getheader('Location')
1098+
or server_response.getheader('location'))
10981099
if location is not None:
10991100
m = re.compile('[\?\&]gsessionid=(\w*)').search(location)
11001101
if m is not None:
@@ -1341,7 +1342,8 @@ def PostOrPut(self, verb, data, uri, extra_headers=None, url_params=None,
13411342
return feed
13421343
elif server_response.status == 302:
13431344
if redirects_remaining > 0:
1344-
location = server_response.getheader('Location')
1345+
location = (server_response.getheader('Location')
1346+
or server_response.getheader('location'))
13451347
if location is not None:
13461348
m = re.compile('[\?\&]gsessionid=(\w*)').search(location)
13471349
if m is not None:
@@ -1438,7 +1440,8 @@ def Delete(self, uri, extra_headers=None, url_params=None,
14381440
return True
14391441
elif server_response.status == 302:
14401442
if redirects_remaining > 0:
1441-
location = server_response.getheader('Location')
1443+
location = (server_response.getheader('Location')
1444+
or server_response.getheader('location'))
14421445
if location is not None:
14431446
m = re.compile('[\?\&]gsessionid=(\w*)').search(location)
14441447
if m is not None:

tests/gdata_tests/client_test.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,25 @@ def test_redirects(self):
255255
except gdata.client.RedirectError, err:
256256
self.assert_(str(err).startswith('Too many redirects from server'))
257257

258+
def test_lowercase_location(self):
259+
client = gdata.client.GDClient()
260+
client.http_client = atom.mock_http_core.MockHttpClient()
261+
# Add the redirect response for the initial request.
262+
first_request = atom.http_core.HttpRequest('http://example.com/1',
263+
'POST')
264+
# In some environments, notably App Engine, the HTTP headers which come
265+
# back from a server will be normalized to all lowercase.
266+
client.http_client.add_response(first_request, 302, None,
267+
{'location': 'http://example.com/1?gsessionid=12'})
268+
second_request = atom.http_core.HttpRequest(
269+
'http://example.com/1?gsessionid=12', 'POST')
270+
client.http_client.AddResponse(second_request, 200, 'OK', body='Done')
271+
272+
response = client.Request('POST', 'http://example.com/1')
273+
self.assertEqual(response.status, 200)
274+
self.assertEqual(response.reason, 'OK')
275+
self.assertEqual(response.read(), 'Done')
276+
258277
def test_exercise_exceptions(self):
259278
# TODO
260279
pass

0 commit comments

Comments
 (0)