netutils/webserver: fix chunked-encoding problem.
authorJunyeon LEE <junyeon2.lee@samsung.com>
Mon, 3 Jul 2017 14:13:26 +0000 (23:13 +0900)
committerEunBong Song <eunb.song@samsung.com>
Wed, 30 Aug 2017 04:15:42 +0000 (21:15 -0700)
This commit fixes chunked encoding problem in webserver. Webserver
sometimes misunderstood received data whether chunked or content-length.
This problem is caused by uninitialized request structure and fixed it.

Additinally, chunked routine added in PUT callback.

Change-Id: If63dace52e03feb3b71a4fc18f957c8822ec13d3
Signed-off-by: Junyeon LEE <junyeon2.lee@samsung.com>
apps/examples/webserver/webserver_main.c
apps/netutils/webserver/http_client.c

index b422bba..e976950 100644 (file)
@@ -156,6 +156,16 @@ void http_put_callback(struct http_client_t *client,  struct http_req_message *r
 {
        printf("===== PUT CALLBACK url : %s entity size : %d =====\n", req->url, strlen(req->entity));
 
+       /*
+        * in callback for POST and PUT request,
+        * entity must be checked it is null when received chunked entity.
+        * if it has chunked encoding entity, it must not send response.
+        */
+       if (req->encoding == HTTP_CHUNKED_ENCODING && req->entity[0] != '\0') {
+               printf("chunk : %s\n", req->entity);
+               return;
+       }
+
        if (http_send_response(client, 200, "PUT SUCCESS", NULL) < 0) {
                printf("Error: Fail to send response\n");
        }
@@ -184,7 +194,7 @@ void http_post_callback(struct http_client_t *client, struct http_req_message *r
         * if it has chunked encoding entity, it must not send response.
         */
        if (req->encoding == HTTP_CHUNKED_ENCODING && req->entity[0] != '\0') {
-               printf("chunk : \n%s\n", req->entity);
+               printf("chunk : %s\n", req->entity);
                return;
        }
 
index f5b0ca1..b2e7a3d 100644 (file)
@@ -378,7 +378,7 @@ int http_recv_and_handle_request(struct http_client_t *client, struct http_keyva
        int buf_len = 0;
        int remain = HTTP_CONF_MAX_REQUEST_LENGTH;
        int enc = HTTP_CONTENT_LENGTH;
-       struct http_req_message req;
+       struct http_req_message req = {0, };
        int state = HTTP_REQUEST_HEADER;
        struct http_message_len_t mlen = {0,};
        struct sockaddr_in addr;
@@ -401,6 +401,7 @@ int http_recv_and_handle_request(struct http_client_t *client, struct http_keyva
        req.url = url;
        req.headers = request_params;
        req.client_ip = addr.sin_addr.s_addr;
+       req.encoding = HTTP_CONTENT_LENGTH;
 
        while (!read_finish) {
                if (remain <= 0) {