Merge lp:~stevenk/launchpad/fetchpage-does-not-send-headers-always into lp:launchpad

Proposed by Steve Kowalik on 2012-11-02
Status: Merged
Approved by: Steve Kowalik on 2012-11-02
Approved revision: no longer in the source branch.
Merged at revision: 16227
Proposed branch: lp:~stevenk/launchpad/fetchpage-does-not-send-headers-always
Merge into: lp:launchpad
Diff against target: 24 lines (+3/-3)
1 file modified
lib/lp/bugs/externalbugtracker/base.py (+3/-3)
To merge this branch: bzr merge lp:~stevenk/launchpad/fetchpage-does-not-send-headers-always
Reviewer Review Type Date Requested Status
Ian Booth (community) 2012-11-02 Approve on 2012-11-02
Review via email: mp+132638@code.launchpad.net

Commit Message

ExternalBugTracker._fetchPage() did not send headers if it was a passed a string, so make use of a Request object so it does.

Description of the Change

This is the second part of the bugfix for the linked bug.

ExternalBugTracker._fetchPage() did not send headers if it was a passed a string, rather than a urlllib2.Request object. I did consider that during the original branch, but discounted it. Of course, now I have egg on my face because the Trac (and Roundup) classes use _fetchPage(), rather than _getPage(). I attempted to force the two classes to use _getPage(), but couldn't get them working, so decided to just play the ol' switcheroo in _fetchPage() itself.

Claw back to neutral LoC by collapsing some lines.

To post a comment you must log in.
Ian Booth (wallyworld) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/externalbugtracker/base.py'
2--- lib/lp/bugs/externalbugtracker/base.py 2012-11-01 04:46:03 +0000
3+++ lib/lp/bugs/externalbugtracker/base.py 2012-11-02 00:42:25 +0000
4@@ -238,6 +238,8 @@
5
6 A BugTrackerConnectError will be raised if anything goes wrong.
7 """
8+ if not isinstance(page, urllib2.Request):
9+ page = urllib2.Request(page, headers=self._getHeaders())
10 try:
11 return self.urlopen(page, data)
12 except (urllib2.HTTPError, urllib2.URLError) as val:
13@@ -265,10 +267,8 @@
14 instead. Do this only if you are sure that repeated POST to
15 this page is safe, as is usually the case with search forms.
16 """
17- url = "%s/%s" % (self.baseurl, page)
18 post_data = urllib.urlencode(form)
19-
20- response = self._post(url, data=post_data)
21+ response = self._post("%s/%s" % (self.baseurl, page), data=post_data)
22
23 if repost_on_redirect and response.url != url:
24 response = self._post(response.url, data=post_data)