]> Nishi Git Mirror - libw3.git/commitdiff
header support
authornishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Sun, 21 Jan 2024 14:27:51 +0000 (14:27 +0000)
committernishi <nishi@d27a3e52-49c5-7645-884c-6793ebffc270>
Sun, 21 Jan 2024 14:27:51 +0000 (14:27 +0000)
git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@38 d27a3e52-49c5-7645-884c-6793ebffc270

Example/fetch.c
Library/HTTP.c

index 64afe18d829b5153927fa85b21fc110ae7202728..ac17c18ebd5a52ec6aa90895f945f7f373f172b5 100644 (file)
@@ -18,6 +18,10 @@ void status(struct W3* w3, int status){
        printf("Response code is %d\n", status);
 }
 
+void header(struct W3* w3, char* key, char* value){
+       printf("Header: %s is `%s'\n", key, value);
+}
+
 int main(int argc, char** argv){
        if(argv[1] != NULL && strcmp(argv[1], "--version") == 0){
                printf("LibW3 %s\n", LIBW3_VERSION);
@@ -34,6 +38,7 @@ int main(int argc, char** argv){
                W3_Set_Path(w3, argv[2]);
                W3_On(w3, "status", (void*)status);
                W3_On(w3, "data", (void*)fetch_data);
+               W3_On(w3, "header", (void*)header);
                W3_Send_Request(w3);
                W3_Free(w3);
        }else{
index 39e379b8364e103a27267d65221e9d4fdd2dbdbc..e8f5ec5e5bb5b578f6cdeddd92e52a45c53b91d2 100644 (file)
@@ -114,6 +114,19 @@ void __W3_HTTP_Request(struct W3* w3){
                                                                char* data = __W3_Strdup(headers + start);
                                                                int k;
                                                                for(k = 0; data[k] != 0; k++){
+                                                                       if(data[k] == ':'){
+                                                                               data[k] = 0;
+                                                                               k++;
+                                                                               for(; data[k] != 0 && data[k] != ' ' && data[k] != '\t'; k++) data[k] = 0;
+                                                                               if(data[k] == ' ' || data[k] == '\t'){
+                                                                                       void* funcptr = __W3_Get_Event(w3, "header");
+                                                                                       if(funcptr != NULL){
+                                                                                               void(*func)(struct W3*, char*, char*) = (void(*)(struct W3*, char*, char*))funcptr;
+                                                                                               func(w3, data, data + k + 1);
+                                                                                       }
+                                                                               }
+                                                                               break;
+                                                                       }
                                                                }
                                                                free(data);
                                                                start = incr + 1;