mirror of
https://github.com/abraunegg/onedrive
synced 2024-06-04 15:02:25 +02:00
Update HTTP/2 handling for session uploads (#233)
* Remove HTTP 1.1 downgrade for session uploads * Handle HTTP/2 0 (zero) response code for successful session data upload * Add debugging for actual server response, not curl interpreted response when using --debug-https
This commit is contained in:
parent
df7ff4f7b7
commit
f785396643
|
@ -251,11 +251,7 @@ final class OneDriveApi
|
||||||
}
|
}
|
||||||
http.method = HTTP.Method.put;
|
http.method = HTTP.Method.put;
|
||||||
http.url = uploadUrl;
|
http.url = uploadUrl;
|
||||||
|
|
||||||
// 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;
|
import std.conv;
|
||||||
string contentRange = "bytes " ~ to!string(offset) ~ "-" ~ to!string(offset + offsetSize - 1) ~ "/" ~ to!string(fileSize);
|
string contentRange = "bytes " ~ to!string(offset) ~ "-" ~ to!string(offset + offsetSize - 1) ~ "/" ~ to!string(fileSize);
|
||||||
http.addRequestHeader("Content-Range", contentRange);
|
http.addRequestHeader("Content-Range", contentRange);
|
||||||
|
@ -334,7 +330,7 @@ final class OneDriveApi
|
||||||
auto response = perform();
|
auto response = perform();
|
||||||
checkHttpCode(response);
|
checkHttpCode(response);
|
||||||
if (.debugResponse){
|
if (.debugResponse){
|
||||||
log.vlog("OneDrive Response: ", response);
|
log.vlog("OneDrive API Response: ", response);
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
@ -483,9 +479,15 @@ final class OneDriveApi
|
||||||
char[] content;
|
char[] content;
|
||||||
http.onReceive = (ubyte[] data) {
|
http.onReceive = (ubyte[] data) {
|
||||||
content ~= data;
|
content ~= data;
|
||||||
|
// HTTP Server Response Code Debugging
|
||||||
|
if (.debugResponse){
|
||||||
|
log.vlog("OneDrive HTTP Server Response: ", http.statusLine.code);
|
||||||
|
}
|
||||||
|
|
||||||
return data.length;
|
return data.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
http.perform();
|
http.perform();
|
||||||
} catch (CurlException e) {
|
} catch (CurlException e) {
|
||||||
|
@ -511,7 +513,7 @@ final class OneDriveApi
|
||||||
// https://developer.overdrive.com/docs/reference-guide
|
// https://developer.overdrive.com/docs/reference-guide
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Error response handling
|
HTTP/1.1 Response handling
|
||||||
|
|
||||||
Errors in the OneDrive API are returned using standard HTTP status codes, as well as a JSON error response object. The following HTTP status codes should be expected.
|
Errors in the OneDrive API are returned using standard HTTP status codes, as well as a JSON error response object. The following HTTP status codes should be expected.
|
||||||
|
|
||||||
|
@ -544,10 +546,16 @@ final class OneDriveApi
|
||||||
507 Insufficient Storage The maximum storage quota has been reached.
|
507 Insufficient Storage The maximum storage quota has been reached.
|
||||||
509 Bandwidth Limit Exceeded Your app has been throttled for exceeding the maximum bandwidth cap. Your app can retry the request again after more time has elapsed.
|
509 Bandwidth Limit Exceeded Your app has been throttled for exceeding the maximum bandwidth cap. Your app can retry the request again after more time has elapsed.
|
||||||
|
|
||||||
|
HTTP/2 Response handling
|
||||||
|
|
||||||
|
0 OK
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
switch(http.statusLine.code)
|
switch(http.statusLine.code)
|
||||||
{
|
{
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
// 200 - OK
|
// 200 - OK
|
||||||
case 200:
|
case 200:
|
||||||
// No Log ..
|
// No Log ..
|
||||||
|
|
Loading…
Reference in a new issue