mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-10 16:03:15 -04:00
Windows: Fix getting errors when downloading something, waiting several minutes, then trying to download from that same address again
This commit is contained in:
parent
efb8de3e69
commit
2dc6834e0b
@ -132,5 +132,7 @@ enum CC_ERRORS {
|
|||||||
HTTP_ERR_RELATIVE = 0xCCDED069UL, /* Unsupported relative URL format */
|
HTTP_ERR_RELATIVE = 0xCCDED069UL, /* Unsupported relative URL format */
|
||||||
HTTP_ERR_INVALID_BODY= 0xCCDED06AUL, /* HTTP message doesn't have Content-Length or use Chunked transfer encoding */
|
HTTP_ERR_INVALID_BODY= 0xCCDED06AUL, /* HTTP message doesn't have Content-Length or use Chunked transfer encoding */
|
||||||
HTTP_ERR_CHUNK_SIZE = 0xCCDED06BUL, /* HTTP message chunk has negative size/length */
|
HTTP_ERR_CHUNK_SIZE = 0xCCDED06BUL, /* HTTP message chunk has negative size/length */
|
||||||
|
|
||||||
|
SSL_ERR_CONTEXT_DEAD = 0xCCDED070UL, /* Server shutdown the SSL context and it must be recreated */
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -943,8 +943,24 @@ static void Http_AddHeader(struct HttpRequest* req, const char* key, const cc_st
|
|||||||
String_Format2((cc_string*)req->meta, "%c:%s\r\n", key, value);
|
String_Format2((cc_string*)req->meta, "%c:%s\r\n", key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cc_result HttpBackend_PerformRequest(struct HttpClientState* state) {
|
||||||
|
cc_result res;
|
||||||
|
|
||||||
|
res = ConnectionPool_Open(&state->conn, &state->url);
|
||||||
|
if (res) { HttpConnection_Close(state->conn); return res; }
|
||||||
|
|
||||||
|
res = HttpClient_SendRequest(state);
|
||||||
|
if (res) { HttpConnection_Close(state->conn); return res; }
|
||||||
|
|
||||||
|
res = HttpClient_ParseResponse(state);
|
||||||
|
if (res) HttpConnection_Close(state->conn);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
static cc_result HttpBackend_Do(struct HttpRequest* req, cc_string* urlStr) {
|
static cc_result HttpBackend_Do(struct HttpRequest* req, cc_string* urlStr) {
|
||||||
struct HttpClientState state;
|
struct HttpClientState state;
|
||||||
|
cc_bool retried = false;
|
||||||
int redirects = 0;
|
int redirects = 0;
|
||||||
cc_result res;
|
cc_result res;
|
||||||
|
|
||||||
@ -953,15 +969,13 @@ static cc_result HttpBackend_Do(struct HttpRequest* req, cc_string* urlStr) {
|
|||||||
state.req = req;
|
state.req = req;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
res = ConnectionPool_Open(&state.conn, &state.url);
|
res = HttpBackend_PerformRequest(&state);
|
||||||
if (res) { HttpConnection_Close(state.conn); return res; }
|
/* TODO: Can we handle this while preserving the TCP connection */
|
||||||
|
if (res == SSL_ERR_CONTEXT_DEAD && !retried) {
|
||||||
res = HttpClient_SendRequest(&state);
|
Platform_LogConst("KILLIN AND TRYIN AGAIN");
|
||||||
if (res) { HttpConnection_Close(state.conn); return res; }
|
res = HttpBackend_PerformRequest(&state);
|
||||||
|
retried = true;
|
||||||
res = HttpClient_ParseResponse(&state);
|
}
|
||||||
http_curProgress = 100;
|
|
||||||
if (state.autoClose) HttpConnection_Close(state.conn);
|
|
||||||
|
|
||||||
if (res || !HttpClient_IsRedirect(req)) break;
|
if (res || !HttpClient_IsRedirect(req)) break;
|
||||||
if (redirects >= 20) return HTTP_ERR_REDIRECTS;
|
if (redirects >= 20) return HTTP_ERR_REDIRECTS;
|
||||||
|
@ -348,6 +348,9 @@ cc_result SSL_Read(void* ctx_, cc_uint8* data, cc_uint32 count, cc_uint32* read)
|
|||||||
return SSL_ReadDecrypted(ctx, data, count, read);
|
return SSL_ReadDecrypted(ctx, data, count, read);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO properly close the connection with TLS shutdown when this happens */
|
||||||
|
if (sec == SEC_I_CONTEXT_EXPIRED) return SSL_ERR_CONTEXT_DEAD;
|
||||||
|
|
||||||
if (sec != SEC_E_INCOMPLETE_MESSAGE) return sec;
|
if (sec != SEC_E_INCOMPLETE_MESSAGE) return sec;
|
||||||
/* SEC_E_INCOMPLETE_MESSAGE case - still need to read more data from the server first */
|
/* SEC_E_INCOMPLETE_MESSAGE case - still need to read more data from the server first */
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user