httpheaderread.c (1543B)
1 /************************************************************************* 2 * This file is part of Crosroads 1.23, a load balancer and fail over 3 * utility for TCP. Copyright (c) Karel Kubat, distributed under GPL. 4 * Visit http://crossroads.e-tunity.com for information. 5 *************************************************************************/ 6 #include "crossroads.h" 7 8 // #define DEBUG 9 10 #ifdef DEBUG 11 static void debughdr (HttpHeader *h) { 12 int i; 13 msg ("http header read: %d headers so far", h->nheader); 14 for (i = 0; i < h->nheader; i++) 15 msg ("http header read: header[%d] '%s'", 16 i, h->header[i]); 17 } 18 19 #define SHOWHEADERS(h) debughdr((h)) 20 #else 21 #define SHOWHEADERS(h) 22 #endif 23 24 void http_header_read (HttpHeader *h, int sock, CopyDirection dir) { 25 unsigned char *cp; 26 int last_is_nl = 0, at_start = 1; 27 28 msg ("Service %s: reading HTTP headers from %s", 29 activeservice->name, 30 dir == dir_client_to_server ? "client" : "server"); 31 while (1) { 32 cp = net_bufread (sock, 1, 0, dir == dir_client_to_server); 33 // msg ("http header read: got char %d (%c)", *cp, *cp); 34 // SHOWHEADERS(h); 35 if (*cp == '\r') 36 continue; 37 if (*cp == '\n') { 38 if (last_is_nl && h->nheader) 39 break; 40 last_is_nl++; 41 continue; 42 } 43 if (at_start || last_is_nl) { 44 h->header = xrealloc (h->header, (h->nheader + 1) * sizeof(char*)); 45 h->header[h->nheader] = 0; 46 h->nheader++; 47 at_start = 0; 48 } 49 h->header[h->nheader - 1] = xstrcatch (h->header[h->nheader - 1], *cp); 50 last_is_nl = 0; 51 } 52 53 SHOWHEADERS(h); 54 }