.
This commit is contained in:
parent
95d74c2ef4
commit
a66e58193f
25 changed files with 2600 additions and 93 deletions
|
|
@ -48,6 +48,10 @@ iptr net_get_last_error(void) {
|
|||
}
|
||||
|
||||
http_res_t http_request(http_request_desc_t *req) {
|
||||
return http_request_cb(req, NULL, NULL);
|
||||
}
|
||||
|
||||
http_res_t http_request_cb(http_request_desc_t *req, http_request_callback_fn callback, void *userdata) {
|
||||
HINTERNET connection = NULL;
|
||||
HINTERNET request = NULL;
|
||||
BOOL result = FALSE;
|
||||
|
|
@ -135,7 +139,14 @@ http_res_t http_request(http_request_desc_t *req) {
|
|||
(DWORD)req->body.len
|
||||
);
|
||||
if (!result) {
|
||||
err("call to HttpSendRequest failed: %v", os_get_error_string(os_get_last_error()));
|
||||
iptr error = os_get_last_error();
|
||||
if (error == ERROR_INTERNET_NAME_NOT_RESOLVED) {
|
||||
err("invalid url: %v", req->url);
|
||||
}
|
||||
else {
|
||||
err("call to HttpSendRequest failed: %lld", error);
|
||||
// os_get_error_string(error));
|
||||
}
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
|
@ -186,7 +197,12 @@ http_res_t http_request(http_request_desc_t *req) {
|
|||
if (!read_success || read == 0) {
|
||||
break;
|
||||
}
|
||||
ostr_puts(&body, strv(read_buffer, read));
|
||||
|
||||
strview_t chunk = strv(read_buffer, read);
|
||||
if (callback) {
|
||||
callback(chunk, userdata);
|
||||
}
|
||||
ostr_puts(&body, chunk);
|
||||
}
|
||||
|
||||
res.body = strv(ostr_to_str(&body));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue