mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
[xhr] Handle timeout. Also hexify post body
Timeout is silent now.
This commit is contained in:
parent
8c2f1092f6
commit
5dc479386e
@ -685,8 +685,23 @@ xhr_send(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
|
||||
if (xhr->method == POST && argc == 1) {
|
||||
body = jsval_to_string(ctx, args[0]);
|
||||
xhr->uri->post = body;
|
||||
|
||||
if (body) {
|
||||
struct string post;
|
||||
if (!init_string(&post)) {
|
||||
mem_free(body);
|
||||
}
|
||||
|
||||
add_to_string(&post, "text/plain\n");
|
||||
for (int i = 0; body[i]; i++) {
|
||||
char p[3];
|
||||
|
||||
ulonghexcat(p, NULL, (int)body[i], 2, '0', 0);
|
||||
add_to_string(&post, p);
|
||||
}
|
||||
xhr->uri->post = post.source;
|
||||
char *url2 = get_uri_string(xhr->uri, URI_DIR_LOCATION | URI_PATH | URI_USER | URI_PASSWORD | URI_POST);
|
||||
done_string(&post);
|
||||
|
||||
if (!url2) {
|
||||
mem_free(body);
|
||||
@ -697,11 +712,15 @@ xhr_send(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
||||
mem_free(url2);
|
||||
mem_free(body);
|
||||
}
|
||||
}
|
||||
xhr->download.data = xhr;
|
||||
xhr->download.callback = (download_callback_T *)xhr_loading_callback;
|
||||
|
||||
if (xhr->uri) {
|
||||
load_uri(xhr->uri, doc_view->session->referrer, &xhr->download, PRI_MAIN, CACHE_MODE_NORMAL, -1);
|
||||
if (xhr->timeout) {
|
||||
set_connection_timeout_xhr(xhr->download.conn, xhr->timeout);
|
||||
}
|
||||
}
|
||||
args.rval().setUndefined();
|
||||
|
||||
|
@ -1205,6 +1205,9 @@ connection_timeout_1(struct connection *conn)
|
||||
void
|
||||
set_connection_timeout(struct connection *conn)
|
||||
{
|
||||
if (conn->xhr_timeout) {
|
||||
return;
|
||||
}
|
||||
kill_timer(&conn->timer);
|
||||
|
||||
install_timer(&conn->timer, (milliseconds_T)
|
||||
@ -1214,6 +1217,19 @@ set_connection_timeout(struct connection *conn)
|
||||
* 500), (void (*)(void *)) connection_timeout_1, conn);
|
||||
}
|
||||
|
||||
static void
|
||||
connection_timeout_xhr_1(struct connection *conn)
|
||||
{
|
||||
install_timer(&conn->timer, conn->xhr_timeout / 2, (void (*)(void *)) connection_timeout, conn);
|
||||
}
|
||||
|
||||
void
|
||||
set_connection_timeout_xhr(struct connection *conn, milliseconds_T timeout)
|
||||
{
|
||||
kill_timer(&conn->timer);
|
||||
conn->xhr_timeout = timeout;
|
||||
install_timer(&conn->timer, timeout / 2, (void (*)(void *)) connection_timeout_xhr_1, conn);
|
||||
}
|
||||
|
||||
void
|
||||
abort_all_connections(void)
|
||||
|
@ -65,6 +65,7 @@ struct connection {
|
||||
|
||||
int tries;
|
||||
timer_id_T timer;
|
||||
milliseconds_T xhr_timeout;
|
||||
|
||||
unsigned int running:1;
|
||||
unsigned int unrestartable:1;
|
||||
@ -111,6 +112,7 @@ void abort_all_connections(void);
|
||||
void abort_background_connections(void);
|
||||
|
||||
void set_connection_timeout(struct connection *);
|
||||
void set_connection_timeout_xhr(struct connection *conn, milliseconds_T timeout);
|
||||
|
||||
void shutdown_connection_stream(struct connection *conn);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user