uclient-http: allow .header_done() callback to reset the connection
[project/uclient.git] / uclient-http.c
index af43b05..7e930d7 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;
@@ -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;
 
@@ -931,7 +939,7 @@ uclient_http_set_header(struct uclient *cl, const char *name, const char *value)
 }
 
 static int
-uclient_http_send_data(struct uclient *cl, char *buf, unsigned int len)
+uclient_http_send_data(struct uclient *cl, const char *buf, unsigned int len)
 {
        struct uclient_http *uh = container_of(cl, struct uclient_http, uc);