From 4608a22c0d800c545242dacc4bcbb75a0bca1544 Mon Sep 17 00:00:00 2001 From: chenyong <1521761801@qq.com> Date: Thu, 23 Aug 2018 12:10:13 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=A4=B4=E9=83=A8=E6=95=B0=E6=8D=AE=E6=97=B6=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=20OK=20=E5=8D=95=E7=8B=AC=E6=8D=A2=E8=A1=8C=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyong <1521761801@qq.com> --- src/webclient.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/webclient.c b/src/webclient.c index 8fa2406..8826239 100644 --- a/src/webclient.c +++ b/src/webclient.c @@ -545,7 +545,7 @@ int webclient_resp_status_get(struct webclient_session *session) * * @param session webclient session * - * @return response content length + * @return response status code */ int webclient_content_length_get(struct webclient_session *session) { @@ -689,19 +689,26 @@ int webclient_handle_response(struct webclient_session *session) } /* get HTTP status code */ - mime_ptr = strstr(session->header->buffer, "HTTP/1."); - if (mime_ptr != RT_NULL) + mime_ptr = web_strdup(session->header->buffer); + if(mime_ptr == RT_NULL) + { + return -WEBCLIENT_NOMEM; + } + + if(strstr(mime_ptr, "HTTP/1.")) { - mime_ptr += strlen("HTTP/1.x"); + char *ptr = mime_ptr; - while (*mime_ptr && (*mime_ptr == ' ' || *mime_ptr == '\t')) - mime_ptr++; + ptr += strlen("HTTP/1.x"); + + while (*ptr && (*ptr == ' ' || *ptr == '\t')) + ptr++; /* Terminate string after status code */ - for (i = 0; ((mime_ptr[i] != ' ') && (mime_ptr[i] != '\t')); i++); - mime_ptr[i] = '\0'; + for (i = 0; ((ptr[i] != ' ') && (ptr[i] != '\t')); i++); + ptr[i] = '\0'; - session->resp_status = (int) strtol(mime_ptr, RT_NULL, 10); + session->resp_status = (int) strtol(ptr, RT_NULL, 10); } /* get content length */ @@ -722,6 +729,11 @@ int webclient_handle_response(struct webclient_session *session) session->chunk_offset = 0; } + if (mime_ptr) + { + web_free(mime_ptr); + } + if (rc < 0) { return rc;