jpatokal / mediawiki-gateway

Ruby framework for MediaWiki API manipulation
Other
133 stars 50 forks source link

Follow the redirection if a HTTP 301, 302, or 307 is returned #86

Closed branliu0 closed 9 years ago

branliu0 commented 9 years ago

This is a small fix to make the API follow any HTTP 3xx redirects that MediaWiki may return. I bumped into this recently after Wikipedia turned on HTTPS-always, and I had been previously using the HTTP endpoint. Right now, if you hit a redirect, then you get an extremely cryptic error message MediaWiki::Exception: Bad response:

The gist of the fix is: RestClient normally will follow redirects for you, but if you pass a block to RestClient::Request.execute, then it does not follow redirects. So here is the simplest fix for following redirects.

I manually tested this: Before my change, using the HTTP endpoint would result in an error. After the change, I can successfully make queries, even when initializing the Gateway to the HTTP endpoint.

jpatokal commented 9 years ago

Brilliant, thank you!