From 9a2e080a6eb80210c3a4c002d5f8d9da2f50ee50 Mon Sep 17 00:00:00 2001 From: nishi Date: Wed, 24 Jan 2024 14:05:28 +0000 Subject: [PATCH] obeys content-length now git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@61 d27a3e52-49c5-7645-884c-6793ebffc270 --- Library/Core.c | 6 +++--- Library/HTTP.c | 7 +++++++ W3Version.h.p | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Library/Core.c b/Library/Core.c index 7bb77a8..4dc7159 100644 --- a/Library/Core.c +++ b/Library/Core.c @@ -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; diff --git a/Library/HTTP.c b/Library/HTTP.c index 9bf2995..a4b1329 100644 --- a/Library/HTTP.c +++ b/Library/HTTP.c @@ -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; } diff --git a/W3Version.h.p b/W3Version.h.p index 3244913..7a9e31a 100644 --- a/W3Version.h.p +++ b/W3Version.h.p @@ -6,7 +6,7 @@ extern "C" { #endif -#define LIBW3_VERSION "1.3B" \ +#define LIBW3_VERSION "1.3C" \ SUFFIX #ifdef __cplusplus -- 2.43.0