Uploader.GetResponse(): Add flag to enable returning non-2xx responses

This allows handling of HTTP responses with non-2xx status codes in uploader code, e.g. to handle REST API errors.
This commit is contained in:
tinybarks 2018-09-13 02:55:59 +09:00
parent 52e3ec4a87
commit 28180cf86a
No known key found for this signature in database
GPG key ID: D999045C35D5795A

View file

@ -350,7 +350,7 @@ protected UploadResult SendRequestFileRange(string url, Stream data, string file
}
protected HttpWebResponse GetResponse(HttpMethod method, string url, Stream data = null, string contentType = null, Dictionary<string, string> args = null,
NameValueCollection headers = null, CookieCollection cookies = null)
NameValueCollection headers = null, CookieCollection cookies = null, bool allowNon2xxResponses = false)
{
IsUploading = true;
StopUploadRequested = false;
@ -381,6 +381,12 @@ protected HttpWebResponse GetResponse(HttpMethod method, string url, Stream data
return (HttpWebResponse)request.GetResponse();
}
catch (WebException we) when (we.Response != null && allowNon2xxResponses)
{
// if we.Response != null, then the request was successful, but
// returned a non-200 status code
return we.Response as HttpWebResponse;
}
catch (Exception e)
{
if (!StopUploadRequested)