1
0
Fork 0

tools/web: improve redirection reliability

This commit is contained in:
nemunaire 2017-07-04 07:26:37 +02:00
parent 6ac9fc4857
commit b4218478bd
1 changed files with 6 additions and 2 deletions

View File

@ -14,7 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from urllib.parse import urlparse, urlsplit, urlunsplit
from urllib.parse import urljoin, urlparse, urlsplit, urlunsplit
from nemubot.exception import IMException
@ -156,7 +156,11 @@ def getURLContent(url, body=None, timeout=7, header=None):
elif ((res.status == http.client.FOUND or
res.status == http.client.MOVED_PERMANENTLY) and
res.getheader("Location") != url):
return getURLContent(res.getheader("Location"), timeout=timeout)
return getURLContent(
urljoin(url, res.getheader("Location")),
body=body,
timeout=timeout,
header=header)
else:
raise IMException("A HTTP error occurs: %d - %s" %
(res.status, http.client.responses[res.status]))