mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-15 20:25:18 +02:00
Add handling for HTTP Code 302 generated by HTTP/2 calls (#229)
* Update initial Curl 7.62.0 fix with a better solution which handles the redirect's given by HTTP/2 connections (credit @Popa21) * Use HTTP/1.1 for session uploads otherwise the response when using HTTP/2 generates a 'JSONValue is not an object' error
This commit is contained in:
parent
7f5b5d981b
commit
8a98bf3e30
|
@ -60,9 +60,8 @@ final class OneDriveApi
|
|||
http.dnsTimeout = (dur!"seconds"(5));
|
||||
http.dataTimeout = (dur!"seconds"(3600));
|
||||
|
||||
// Specify which HTTP version to use
|
||||
// Curl 7.62.0 defaults to http2, we need to use http 1.1
|
||||
http.handle.set(CurlOption.http_version,2);
|
||||
// Specify how many redirects should be allowed
|
||||
http.maxRedirects(5);
|
||||
|
||||
if (debugHttp) {
|
||||
http.verbose = true;
|
||||
|
@ -252,8 +251,11 @@ final class OneDriveApi
|
|||
}
|
||||
http.method = HTTP.Method.put;
|
||||
http.url = uploadUrl;
|
||||
// when using microsoft graph the auth code is different
|
||||
//addAccessTokenHeader();
|
||||
|
||||
// Specify which HTTP version to use for session uploads
|
||||
// Curl 7.62.0 defaults to HTTP/2, we need to use HTTP/1.1
|
||||
http.handle.set(CurlOption.http_version,2);
|
||||
|
||||
import std.conv;
|
||||
string contentRange = "bytes " ~ to!string(offset) ~ "-" ~ to!string(offset + offsetSize - 1) ~ "/" ~ to!string(fileSize);
|
||||
http.addRequestHeader("Content-Range", contentRange);
|
||||
|
@ -558,6 +560,10 @@ final class OneDriveApi
|
|||
//log.vlog("OneDrive Response: '", http.statusLine.code, " - ", http.statusLine.reason, "'");
|
||||
break;
|
||||
|
||||
// 302 - resource found and available at another location, redirect
|
||||
case 302:
|
||||
break;
|
||||
|
||||
// 400 - Bad Request
|
||||
case 400:
|
||||
// Bad Request .. how should we act?
|
||||
|
@ -631,9 +637,9 @@ final class OneDriveApi
|
|||
log.vlog("OneDrive returned a 'HTTP 5xx Server Side Error' - gracefully handling error");
|
||||
break;
|
||||
|
||||
// Default - all other errors that are not a 2xx
|
||||
// Default - all other errors that are not a 2xx or a 302
|
||||
default:
|
||||
if (http.statusLine.code / 100 != 2) {
|
||||
if (http.statusLine.code / 100 != 2 && http.statusLine.code != 302) {
|
||||
throw new OneDriveException(http.statusLine.code, http.statusLine.reason, response);
|
||||
break;
|
||||
}
|
||||
|
@ -671,6 +677,5 @@ unittest
|
|||
assert(e.httpStatusCode == 412);
|
||||
}
|
||||
onedrive.deleteById(item["id"].str, item["eTag"].str);
|
||||
|
||||
onedrive.http.shutdown();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue