X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuclient.git;a=blobdiff_plain;f=uclient-http.c;h=3ffb88c001dfc4bd8d7219e87b898a2a03af398a;hp=7e930d7e5ed019a66b8dbf901aab685b0f720d7d;hb=149f5dc44b699d8ed15ef076ea17306e09988d4c;hpb=d2d1a9c477abe660e01943b3fee069b28b6610e0 diff --git a/uclient-http.c b/uclient-http.c index 7e930d7..3ffb88c 100644 --- a/uclient-http.c +++ b/uclient-http.c @@ -115,18 +115,17 @@ static int uclient_do_connect(struct uclient_http *uh, const char *port) if (uh->uc.url->port) port = uh->uc.url->port; - fd = usock(USOCK_TCP | USOCK_NONBLOCK, uh->uc.url->host, port); + memset(&uh->uc.remote_addr, 0, sizeof(uh->uc.remote_addr)); + + fd = usock_inet(USOCK_TCP | USOCK_NONBLOCK, uh->uc.url->host, port, &uh->uc.remote_addr); if (fd < 0) return -1; ustream_fd_init(&uh->ufd, fd); - memset(&uh->uc.local_addr, 0, sizeof(uh->uc.local_addr)); - memset(&uh->uc.remote_addr, 0, sizeof(uh->uc.remote_addr)); - sl = sizeof(uh->uc.local_addr); + memset(&uh->uc.local_addr, 0, sl); getsockname(fd, &uh->uc.local_addr.sa, &sl); - getpeername(fd, &uh->uc.remote_addr.sa, &sl); return 0; } @@ -212,6 +211,7 @@ static void uclient_http_reset_state(struct uclient_http *uh) static void uclient_http_init_request(struct uclient_http *uh) { + uh->seq++; uclient_http_reset_state(uh); blob_buf_init(&uh->meta, 0); } @@ -540,6 +540,9 @@ uclient_http_send_headers(struct uclient_http *uh) if (uh->state >= HTTP_STATE_HEADERS_SENT) return; + if (uh->uc.proxy_url) + url = uh->uc.proxy_url; + ustream_printf(uh->us, "%s %s HTTP/1.1\r\n" "Host: %s\r\n", @@ -547,7 +550,7 @@ uclient_http_send_headers(struct uclient_http *uh) url->location, url->host); blobmsg_for_each_attr(cur, uh->headers.head, rem) - ustream_printf(uh->us, "%s: %s\n", blobmsg_name(cur), (char *) blobmsg_data(cur)); + ustream_printf(uh->us, "%s: %s\r\n", blobmsg_name(cur), (char *) blobmsg_data(cur)); if (uh->req_type == REQ_POST || uh->req_type == REQ_PUT) ustream_printf(uh->us, "Transfer-Encoding: chunked\r\n"); @@ -562,6 +565,7 @@ uclient_http_send_headers(struct uclient_http *uh) static void uclient_http_headers_complete(struct uclient_http *uh) { enum auth_type auth_type = uh->auth_type; + int seq = uh->uc.seq; uh->state = HTTP_STATE_RECV_DATA; uh->uc.meta = uh->meta.head; @@ -578,7 +582,7 @@ static void uclient_http_headers_complete(struct uclient_http *uh) if (uh->uc.cb->header_done) uh->uc.cb->header_done(&uh->uc); - if (uh->eof) + if (uh->eof || seq != uh->uc.seq) return; if (uh->req_type == REQ_HEAD || uh->uc.status_code == 204) { @@ -826,6 +830,7 @@ static int uclient_setup_https(struct uclient_http *uh) uh->ussl.notify_error = uclient_ssl_notify_error; uh->ussl.notify_verify_error = uclient_ssl_notify_verify_error; uh->ussl.notify_connected = uclient_ssl_notify_connected; + uh->ussl.server_name = uh->uc.url->host; uh->ssl_ops->init(&uh->ussl, &uh->ufd.stream, uh->ssl_ctx, false); uh->ssl_ops->set_peer_cn(&uh->ussl, uh->uc.url->host); @@ -1114,6 +1119,7 @@ const struct uclient_backend uclient_backend_http = { .connect = uclient_http_connect, .disconnect = uclient_http_request_disconnect, .update_url = uclient_http_free_url_state, + .update_proxy_url = uclient_http_free_url_state, .read = uclient_http_read, .write = uclient_http_send_data,