]> Nishi Git Mirror - libw3.git/commitdiff
obeys content-length now
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Wed, 24 Jan 2024 14:05:28 +0000 (14:05 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Wed, 24 Jan 2024 14:05:28 +0000 (14:05 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@61 d27a3e52-49c5-7645-884c-6793ebffc270

Library/Core.c
Library/HTTP.c
W3Version.h.p

index 7bb77a8969b99186d87ec508bb13ad57fa122e16..4dc71599eafe851f21530e7ccc9a5f89ee93c459 100644 (file)
@@ -63,11 +63,11 @@ struct W3* W3_Create(const char* protocol, const char* hostname, int port) {
        w3->ssl_ctx = NULL;
 #endif
        if(strcmp(protocol, "file") != 0) {
-               if(strcmp(protocol, "http") == 0){
+               if(strcmp(protocol, "http") == 0) {
 #ifdef SSL_SUPPORT
-               }else if(strcmp(protocol, "https") == 0){
+               } else if(strcmp(protocol, "https") == 0) {
 #endif
-               }else{
+               } else {
                        __W3_Debug("Protocol", "Not suppported");
                        W3_Free(w3);
                        w3 = NULL;
index 9bf2995cf03474783840b66a61313c0d94c00276..a4b13298f62e134fb97d72904c6a412967fcf9c0 100644 (file)
@@ -71,6 +71,7 @@ void __W3_HTTP_Request(struct W3* w3) {
        char* chunk = NULL;
        bool breakchunk = false;
        int chunksize;
+       size_t allsize = -1;
        while(true) {
                int l = __W3_Auto_Read(w3, buf, w3->readsize);
                if(l <= 0) break;
@@ -147,6 +148,8 @@ void __W3_HTTP_Request(struct W3* w3) {
                                                                                        }
                                                                                        if(strcasecmp(data, "transfer-encoding") == 0 && strcasecmp(data + k + 1, "chunked") == 0) {
                                                                                                chunked = true;
+                                                                                       } else if(strcasecmp(data, "content-length") == 0) {
+                                                                                               allsize = atoi(data + k + 1);
                                                                                        }
                                                                                }
                                                                                break;
@@ -228,6 +231,10 @@ void __W3_HTTP_Request(struct W3* w3) {
                                                func(w3, buffer, l - i);
                                                free(buffer);
                                        }
+                                       allsize -= l - i;
+                                       if(allsize == 0) {
+                                               breakchunk = 1;
+                                       }
                                }
                                break;
                        }
index 3244913e278eca52ff8920a2768fa69e08d79cb5..7a9e31a7267220638d1eb5c25b911d0e27108834 100644 (file)
@@ -6,7 +6,7 @@
 extern "C" {
 #endif
 
-#define LIBW3_VERSION "1.3B" \
+#define LIBW3_VERSION "1.3C" \
 SUFFIX
 
 #ifdef __cplusplus