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,23 +685,42 @@ xhr_send(JSContext *ctx, unsigned int argc, JS::Value *rval)
|
|||||||
|
|
||||||
if (xhr->method == POST && argc == 1) {
|
if (xhr->method == POST && argc == 1) {
|
||||||
body = jsval_to_string(ctx, args[0]);
|
body = jsval_to_string(ctx, args[0]);
|
||||||
xhr->uri->post = body;
|
|
||||||
char *url2 = get_uri_string(xhr->uri, URI_DIR_LOCATION | URI_PATH | URI_USER | URI_PASSWORD | URI_POST);
|
|
||||||
|
|
||||||
if (!url2) {
|
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);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
done_uri(xhr->uri);
|
||||||
|
xhr->uri = get_uri(url2, URI_DIR_LOCATION | URI_PATH | URI_USER | URI_PASSWORD | URI_POST);
|
||||||
|
mem_free(url2);
|
||||||
mem_free(body);
|
mem_free(body);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
done_uri(xhr->uri);
|
|
||||||
xhr->uri = get_uri(url2, URI_DIR_LOCATION | URI_PATH | URI_USER | URI_PASSWORD | URI_POST);
|
|
||||||
mem_free(url2);
|
|
||||||
mem_free(body);
|
|
||||||
}
|
}
|
||||||
xhr->download.data = xhr;
|
xhr->download.data = xhr;
|
||||||
xhr->download.callback = (download_callback_T *)xhr_loading_callback;
|
xhr->download.callback = (download_callback_T *)xhr_loading_callback;
|
||||||
|
|
||||||
if (xhr->uri) {
|
if (xhr->uri) {
|
||||||
load_uri(xhr->uri, doc_view->session->referrer, &xhr->download, PRI_MAIN, CACHE_MODE_NORMAL, -1);
|
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();
|
args.rval().setUndefined();
|
||||||
|
|
||||||
|
@ -1205,6 +1205,9 @@ connection_timeout_1(struct connection *conn)
|
|||||||
void
|
void
|
||||||
set_connection_timeout(struct connection *conn)
|
set_connection_timeout(struct connection *conn)
|
||||||
{
|
{
|
||||||
|
if (conn->xhr_timeout) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
kill_timer(&conn->timer);
|
kill_timer(&conn->timer);
|
||||||
|
|
||||||
install_timer(&conn->timer, (milliseconds_T)
|
install_timer(&conn->timer, (milliseconds_T)
|
||||||
@ -1214,6 +1217,19 @@ set_connection_timeout(struct connection *conn)
|
|||||||
* 500), (void (*)(void *)) connection_timeout_1, 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
|
void
|
||||||
abort_all_connections(void)
|
abort_all_connections(void)
|
||||||
|
@ -65,6 +65,7 @@ struct connection {
|
|||||||
|
|
||||||
int tries;
|
int tries;
|
||||||
timer_id_T timer;
|
timer_id_T timer;
|
||||||
|
milliseconds_T xhr_timeout;
|
||||||
|
|
||||||
unsigned int running:1;
|
unsigned int running:1;
|
||||||
unsigned int unrestartable:1;
|
unsigned int unrestartable:1;
|
||||||
@ -111,6 +112,7 @@ void abort_all_connections(void);
|
|||||||
void abort_background_connections(void);
|
void abort_background_connections(void);
|
||||||
|
|
||||||
void set_connection_timeout(struct connection *);
|
void set_connection_timeout(struct connection *);
|
||||||
|
void set_connection_timeout_xhr(struct connection *conn, milliseconds_T timeout);
|
||||||
|
|
||||||
void shutdown_connection_stream(struct connection *conn);
|
void shutdown_connection_stream(struct connection *conn);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user