← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Steve Kowalik has proposed merging lp:~stevenk/launchpad/fetchpage-does-not-send-headers-always into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #943261 in Launchpad itself: "Always gets a 404 from the VLC Trac, even when said Trac is online"
  https://bugs.launchpad.net/launchpad/+bug/943261

For more details, see:
https://code.launchpad.net/~stevenk/launchpad/fetchpage-does-not-send-headers-always/+merge/132638

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.
-- 
https://code.launchpad.net/~stevenk/launchpad/fetchpage-does-not-send-headers-always/+merge/132638
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~stevenk/launchpad/fetchpage-does-not-send-headers-always into lp:launchpad.
=== modified file 'lib/lp/bugs/externalbugtracker/base.py'
--- lib/lp/bugs/externalbugtracker/base.py	2012-11-01 04:46:03 +0000
+++ lib/lp/bugs/externalbugtracker/base.py	2012-11-02 00:42:25 +0000
@@ -238,6 +238,8 @@
 
         A BugTrackerConnectError will be raised if anything goes wrong.
         """
+        if not isinstance(page, urllib2.Request):
+            page = urllib2.Request(page, headers=self._getHeaders())
         try:
             return self.urlopen(page, data)
         except (urllib2.HTTPError, urllib2.URLError) as val:
@@ -265,10 +267,8 @@
             instead.  Do this only if you are sure that repeated POST to
             this page is safe, as is usually the case with search forms.
         """
-        url = "%s/%s" % (self.baseurl, page)
         post_data = urllib.urlencode(form)
-
-        response = self._post(url, data=post_data)
+        response = self._post("%s/%s" % (self.baseurl, page), data=post_data)
 
         if repost_on_redirect and response.url != url:
             response = self._post(response.url, data=post_data)


Follow ups