uclient-http: end custom header lines with CRLF
[project/uclient.git] / uclient-http.c
index 9f9fac9..d96094d 100644 (file)
@@ -41,6 +41,7 @@ enum request_type {
        REQ_HEAD,
        REQ_POST,
        REQ_PUT,
+       REQ_DELETE,
        __REQ_MAX
 };
 
@@ -58,6 +59,7 @@ static const char * const request_types[__REQ_MAX] = {
        [REQ_HEAD] = "HEAD",
        [REQ_POST] = "POST",
        [REQ_PUT] = "PUT",
+       [REQ_DELETE] = "DELETE",
 };
 
 struct uclient_http {
@@ -71,6 +73,7 @@ struct uclient_http {
        struct ustream_ssl ussl;
 
        struct uloop_timeout disconnect_t;
+       unsigned int seq;
 
        bool ssl_require_validation;
        bool ssl;
@@ -194,6 +197,7 @@ static void uclient_notify_eof(struct uclient_http *uh)
 
 static void uclient_http_reset_state(struct uclient_http *uh)
 {
+       uh->seq++;
        uclient_backend_reset_state(&uh->uc);
        uh->read_chunked = -1;
        uh->content_length = -1;
@@ -543,7 +547,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");
@@ -639,6 +643,7 @@ error:
 static void __uclient_notify_read(struct uclient_http *uh)
 {
        struct uclient *uc = &uh->uc;
+       unsigned int seq = uh->seq;
        char *data;
        int len;
 
@@ -673,6 +678,9 @@ static void __uclient_notify_read(struct uclient_http *uh)
                        *sep = 0;
                        cur_len = sep + 2 - data;
                        uclient_parse_http_line(uh, data);
+                       if (seq != uh->seq)
+                               return;
+
                        ustream_consume(uh->us, cur_len);
                        len -= cur_len;