X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fuclient.git;a=blobdiff_plain;f=uclient-http.c;h=5e5f9961e20d6ffc56de980123f1e2d35862c53a;hp=fa66f78a0562ffe5a867154a2572422f412a70cb;hb=c35d9db9362e095553f2c043b1a2bf195435bc09;hpb=fe0f1a36109384eaad8b3d0f1438d9321581e47c diff --git a/uclient-http.c b/uclient-http.c index fa66f78..5e5f996 100644 --- a/uclient-http.c +++ b/uclient-http.c @@ -108,6 +108,8 @@ static const char * const uclient_http_prefix[] = { [__PREFIX_MAX] = NULL }; +static int uclient_http_connect(struct uclient *cl); + static int uclient_do_connect(struct uclient_http *uh, const char *port) { socklen_t sl; @@ -190,6 +192,9 @@ static void uclient_notify_eof(struct uclient_http *uh) return; } + if (uh->content_length < 0 && uh->read_chunked >= 0) + uh->uc.data_eof = true; + uclient_backend_set_eof(&uh->uc); if (uh->connection_close) @@ -575,7 +580,7 @@ static void uclient_http_headers_complete(struct uclient_http *uh) if (auth_type == AUTH_TYPE_UNKNOWN && uh->uc.status_code == 401 && (uh->req_type == REQ_HEAD || uh->req_type == REQ_GET)) { - uclient_http_init_request(uh); + uclient_http_connect(&uh->uc); uclient_http_send_headers(uh); uh->state = HTTP_STATE_REQUEST_DONE; return; @@ -661,28 +666,33 @@ static void __uclient_notify_read(struct uclient_http *uh) return; if (uh->state < HTTP_STATE_RECV_DATA) { - char *sep; + char *sep, *next; int cur_len; do { - sep = strstr(data, "\r\n"); + sep = strchr(data, '\n'); if (!sep) break; + next = sep + 1; + if (sep > data && sep[-1] == '\r') + sep--; + /* Check for multi-line HTTP headers */ if (sep > data) { - if (!sep[2]) + if (!*next) return; - if (isspace(sep[2]) && sep[2] != '\r') { + if (isspace(*next) && *next != '\r' && *next != '\n') { sep[0] = ' '; - sep[1] = ' '; + if (sep + 1 < next) + sep[1] = ' '; continue; } } *sep = 0; - cur_len = sep + 2 - data; + cur_len = next - data; uclient_parse_http_line(uh, data); if (seq != uh->seq) return; @@ -848,7 +858,7 @@ static int uclient_http_connect(struct uclient *cl) struct uclient_http *uh = container_of(cl, struct uclient_http, uc); int ret; - if (!cl->eof || uh->disconnect) + if (!cl->eof || uh->disconnect || uh->connection_close) uclient_http_disconnect(uh); uclient_http_init_request(uh); @@ -1061,7 +1071,7 @@ uclient_http_read(struct uclient *cl, char *buf, unsigned int len) return len; } -bool uclient_http_redirect(struct uclient *cl) +int uclient_http_redirect(struct uclient *cl) { struct uclient_http *uh = container_of(cl, struct uclient_http, uc); struct blobmsg_policy location = { @@ -1093,7 +1103,9 @@ bool uclient_http_redirect(struct uclient *cl) free(cl->url); cl->url = url; - uclient_http_connect(cl); + if (uclient_http_connect(cl)) + return -1; + uclient_http_request_done(cl); return true;