X-Git-Url: http://www.dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fhtparser.c;h=92445d7bf85f7554a7a6ef0066d28314963f63f7;hb=b71ad67f41a9e99bd243d57b5038de28f1696f27;hp=1dbb8eeef429e4f0148ebad1270b15e24e8ec1b7;hpb=27ca317cc6d19aa6080eae9a446212e928696bf5;p=ashd.git diff --git a/src/htparser.c b/src/htparser.c index 1dbb8ee..92445d7 100644 --- a/src/htparser.c +++ b/src/htparser.c @@ -280,15 +280,35 @@ static int http10keep(struct hthead *req, struct hthead *resp) } } +static char *connid(void) +{ + static struct charbuf cur; + int i; + char *ret; + + for(i = 0; i < cur.d; i++) { + if((++cur.b[i]) > 'Z') + cur.b[i] = 'A'; + else + goto done; + } + bufadd(cur, 'A'); +done: + ret = memcpy(smalloc(cur.d + 1), cur.b, cur.d); + ret[cur.d] = 0; + return(ret); +} + void serve(FILE *in, struct conn *conn) { int pfds[2]; FILE *out; struct hthead *req, *resp; - char *hd; + char *hd, *id; off_t dlen; int keep; + id = connid(); out = NULL; req = resp = NULL; while(plex >= 0) { @@ -297,6 +317,7 @@ void serve(FILE *in, struct conn *conn) if(!canonreq(req)) break; + headappheader(req, "X-Ash-Connection-ID", id); if((conn->initreq != NULL) && conn->initreq(conn, req)) break; @@ -307,7 +328,7 @@ void serve(FILE *in, struct conn *conn) if(sendreq(plex, req, pfds[0])) break; close(pfds[0]); - out = mtstdopen(pfds[1], 1, 600, "r+"); + out = mtstdopen(pfds[1], 1, 600, "r+", NULL); if(getheader(req, "content-type") != NULL) { if((hd = getheader(req, "content-length")) != NULL) { @@ -399,6 +420,7 @@ void serve(FILE *in, struct conn *conn) if(resp != NULL) freehthead(resp); fclose(in); + free(id); } static void plexwatch(struct muth *muth, va_list args)