Przeglądaj źródła

Merge pull request #58 from Shadowyingjian/master

[update] 添加可以识别部分服务器返回 header 字段中的"Content-Type" 为小写的"content-type"的功…
朱天龙 (Armink) 6 lat temu
rodzic
commit
f445b728f8
1 zmienionych plików z 34 dodań i 2 usunięć
  1. 34 2
      src/webclient.c

+ 34 - 2
src/webclient.c

@@ -46,6 +46,38 @@
 
 extern long int strtol(const char *nptr, char **endptr, int base);
 
+static int webclient_strncasecmp(const char *a, const char *b, size_t n)
+{
+    uint8_t c1, c2;
+    if (n <= 0)
+        return 0;
+    do {
+        c1 = tolower(*a++);
+        c2 = tolower(*b++);
+    } while (--n && c1 && c1 == c2);
+    return c1 - c2;
+}
+
+static const char *webclient_strstri(const char* str, const char* subStr)
+{
+    int len = strlen(subStr);
+
+    if(len == 0)
+    {
+        return RT_NULL;
+    }
+
+    while(*str)
+    {
+        if(webclient_strncasecmp(str, subStr, len) == 0)
+        {
+            return str;
+        }
+        ++str;
+    }
+    return RT_NULL;
+}
+
 static int webclient_send(struct webclient_session* session, const unsigned char *buffer, size_t len, int flag)
 {
 #ifdef WEBCLIENT_USING_MBED_TLS
@@ -530,7 +562,7 @@ const char *webclient_header_fields_get(struct webclient_session *session, const
     resp_buf = session->header->buffer;
     while (resp_buf_len < session->header->length)
     {
-        if (rt_strstr(resp_buf, fields))
+        if (webclient_strstri(resp_buf, fields))
         {
             char *mime_ptr = RT_NULL;
 
@@ -1554,7 +1586,7 @@ int webclient_request_header_add(char **request_header, const char *fmt, ...)
  */
 int webclient_request(const char *URI, const char *header, const char *post_data, unsigned char **response)
 {
-    struct webclient_session *session;
+    struct webclient_session *session = RT_NULL;
     int rc = WEBCLIENT_OK;
     int totle_length = 0;