Dolda2000 GitWeb
/
ashd.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
056f947
)
htparser: Improved HTTP/1.0 Keep-Alive behavior.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Mon, 5 Sep 2011 14:52:31 +0000
(16:52 +0200)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Mon, 5 Sep 2011 14:52:31 +0000
(16:52 +0200)
src/htparser.c
patch
|
blob
|
blame
|
history
diff --git
a/src/htparser.c
b/src/htparser.c
index
a195fab
..
4086f79
100644
(file)
--- a/
src/htparser.c
+++ b/
src/htparser.c
@@
-212,6
+212,20
@@
static int canonreq(struct hthead *req)
return(0);
}
return(0);
}
+static int http10keep(struct hthead *req, struct hthead *resp)
+{
+ int fc;
+
+ fc = hasheader(resp, "connection", "close");
+ headrmheader(resp, "connection");
+ if(!fc && hasheader(req, "connection", "keep-alive")) {
+ headappheader(resp, "Connection", "Keep-Alive");
+ return(1);
+ } else {
+ return(0);
+ }
+}
+
void serve(FILE *in, struct conn *conn)
{
int pfds[2];
void serve(FILE *in, struct conn *conn)
{
int pfds[2];
@@
-219,6
+233,7
@@
void serve(FILE *in, struct conn *conn)
struct hthead *req, *resp;
char *hd;
off_t dlen;
struct hthead *req, *resp;
char *hd;
off_t dlen;
+ int keep;
out = NULL;
req = resp = NULL;
out = NULL;
req = resp = NULL;
@@
-260,22
+275,25
@@
void serve(FILE *in, struct conn *conn)
headappheader(resp, "Server", sprintf3("ashd/%s", VERSION));
if(!strcmp(req->ver, "HTTP/1.0")) {
headappheader(resp, "Server", sprintf3("ashd/%s", VERSION));
if(!strcmp(req->ver, "HTTP/1.0")) {
- writeresp(in, resp);
- fprintf(in, "\r\n");
if(!strcasecmp(req->method, "head")) {
if(!strcasecmp(req->method, "head")) {
- if(!hasheader(req, "connection", "keep-alive"))
- break;
+ keep = http10keep(req, resp);
+ writeresp(in, resp);
+ fprintf(in, "\r\n");
} else if((hd = getheader(resp, "content-length")) != NULL) {
} else if((hd = getheader(resp, "content-length")) != NULL) {
+ keep = http10keep(req, resp);
dlen = atoo(hd);
dlen = atoo(hd);
+ writeresp(in, resp);
+ fprintf(in, "\r\n");
if(passdata(out, in, dlen) != dlen)
break;
if(passdata(out, in, dlen) != dlen)
break;
- if(!hasheader(req, "connection", "keep-alive"))
- break;
} else {
} else {
+ headrmheader(resp, "connection");
+ writeresp(in, resp);
+ fprintf(in, "\r\n");
passdata(out, in, -1);
break;
}
passdata(out, in, -1);
break;
}
- if(
hasheader(req, "connection", "close") || hasheader(resp, "connection", "close")
)
+ if(
!keep
)
break;
} else if(!strcmp(req->ver, "HTTP/1.1")) {
if(!strcasecmp(req->method, "head")) {
break;
} else if(!strcmp(req->ver, "HTTP/1.1")) {
if(!strcasecmp(req->method, "head")) {