ignore empty writes
[project/uclient.git] / uclient-http.c
index 1ab1f46..05dd3aa 100644 (file)
@@ -496,6 +496,8 @@ uclient_http_send_headers(struct uclient_http *uh)
        uclient_http_add_auth_header(uh);
 
        ustream_printf(uh->us, "\r\n");
+
+       uh->state = HTTP_STATE_HEADERS_SENT;
 }
 
 static void uclient_http_headers_complete(struct uclient_http *uh)
@@ -516,7 +518,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->req_type == REQ_HEAD) {
+       if (uh->req_type == REQ_HEAD || uh->uc.status_code == 204) {
                uh->eof = true;
                uclient_notify_eof(uh);
        }
@@ -799,7 +801,7 @@ uclient_http_set_request_type(struct uclient *cl, const char *type)
 }
 
 int
-uclient_http_reset_headers(struct uclient *cl, const char *name, const char *value)
+uclient_http_reset_headers(struct uclient *cl)
 {
        struct uclient_http *uh = container_of(cl, struct uclient_http, uc);
 
@@ -833,10 +835,11 @@ uclient_http_send_data(struct uclient *cl, char *buf, unsigned int len)
 
        uclient_http_send_headers(uh);
 
-       ustream_printf(uh->us, "%X\r\n", len);
-       if (len > 0)
+       if (len > 0) {
+               ustream_printf(uh->us, "%X\r\n", len);
                ustream_write(uh->us, buf, len, false);
-       ustream_printf(uh->us, "\r\n");
+               ustream_printf(uh->us, "\r\n");
+       }
 
        return len;
 }
@@ -850,6 +853,8 @@ uclient_http_request_done(struct uclient *cl)
                return -1;
 
        uclient_http_send_headers(uh);
+       if (uh->req_type == REQ_POST)
+               ustream_printf(uh->us, "0\r\n\r\n");
        uh->state = HTTP_STATE_REQUEST_DONE;
 
        return 0;