jenkins-bot has submitted this change and it was merged.
Change subject: Preserve HTTP worker state after exception
......................................................................
Preserve HTTP worker state after exception
threadedhttp.Http.request set self.follow_redirects=False before calling its
parent method, and reset it afterwards. However if there was an exception
in the parent method, self.follow_redirects was not reset and changed
the behaviour of subsequent requests handled by the HTTP worker.
Change-Id: I1b917fbcea4ad51a958ec19faea4f2618662f6a8
---
M pywikibot/comms/threadedhttp.py
M tests/http_tests.py
2 files changed, 20 insertions(+), 1 deletion(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py
index af9ce82..8de4213 100644
--- a/pywikibot/comms/threadedhttp.py
+++ b/pywikibot/comms/threadedhttp.py
@@ -230,7 +230,8 @@
except Exception as e: # what types?
# return exception instance to be retrieved by the calling thread
return e
- self.follow_redirects = follow_redirects
+ finally:
+ self.follow_redirects = follow_redirects
# return connection to pool
self.connection_pool.push_connection(conn_key,
diff --git a/tests/http_tests.py b/tests/http_tests.py
index abef94a..fdcd478 100644
--- a/tests/http_tests.py
+++ b/tests/http_tests.py
@@ -114,6 +114,24 @@
http.fetch,
uri='http://getstatuscode.com/504')
+ def test_follow_redirects(self):
+ """Test follow 301 redirects after an exception works correctly."""
+ # to be effective, this exception should be raised in httplib2
+ self.assertRaises(Exception,
+ http.fetch,
+ uri='invalid://url')
+
+ # The following will redirect from ' ' -> '_', and maybe to https://
+ r = http.fetch(uri='http://en.wikipedia.org/wiki/Main%20Page')
+ self.assertEqual(r.status, 200)
+ self.assertIn('//en.wikipedia.org/wiki/Main_Page',
+ r.response_headers['content-location'])
+
+ r = http.fetch(uri='http://www.gandi.eu')
+ self.assertEqual(r.status, 200)
+ self.assertEqual(r.response_headers['content-location'],
+ 'http://www.gandi.net')
+
class ThreadedHttpTestCase(TestCase):
--
To view, visit https://gerrit.wikimedia.org/r/178789
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I1b917fbcea4ad51a958ec19faea4f2618662f6a8
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits