Handle HTTP 202 HEAD&GET with a retry (#791)

* Handle HTTP 202
Fixes #564
After some testing, it seems GitHub seems to be able to process the chrunching of statistics
for every repository I tested in around 2 seconds. So a delay of around 5 seconds should be
plenty to be very certain that the next try should succeed.
Another option would be to put this value lower and possibly waste an extra retry on it.

* Only re-request data if HEAD or GET (those are 'safe')
to e.g. avoid running a duplicate POST or PUT, that can change stuff on the server
Using RFC 2616 and https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html as guideline

* Fix testStatistics

* change wait time to 2 secs
This commit is contained in:
Maarten Fonville
2018-06-22 16:54:32 +08:00
committed by Wan Liuyang
parent 8bdac23ca1
commit 3aead15818
5 changed files with 64 additions and 67 deletions
+6
View File
@@ -30,6 +30,7 @@
# Copyright 2017 Simon <spam@esemi.ru> #
# Copyright 2018 R1kk3r <R1kk3r@users.noreply.github.com> #
# Copyright 2018 sfdye <tsfdye@gmail.com> #
# Copyright 2018 Maarten Fonville <maarten.fonville@gmail.com> #
# #
# This file is part of PyGithub. #
# http://pygithub.readthedocs.io/ #
@@ -57,6 +58,7 @@ import os
import re
import requests
import sys
import time
import urllib
import urlparse
from io import IOBase
@@ -402,6 +404,10 @@ class Requester:
self.__log(verb, url, requestHeaders, input, status, responseHeaders, output)
if status == 202 and (verb == 'GET' or verb == 'HEAD'): # only for requests that are considered 'safe' in RFC 2616
time.sleep(Consts.PROCESSING_202_WAIT_TIME)
return self.__requestRaw(original_cnx, verb, url, requestHeaders, input)
if status == 301 and 'location' in responseHeaders:
return self.__requestRaw(original_cnx, verb, responseHeaders['location'], requestHeaders, input)