Commit 6c7a3ad6 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Use HttpdBuildSbuf()

Enable Id keyword


git-svn-id: http://www.varnish-cache.org/svn/trunk@121 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 584cb1ac
......@@ -42,65 +42,32 @@ PassSession(struct worker *w, struct sess *sp)
fd = VBE_GetFd(sp->backend, &fd_token);
assert(fd != -1);
sbuf_clear(w->sb);
assert(w->sb != NULL);
sbuf_cat(w->sb, sp->http.req);
sbuf_cat(w->sb, " ");
sbuf_cat(w->sb, sp->http.url);
sbuf_cat(w->sb, " ");
sbuf_cat(w->sb, sp->http.proto);
sbuf_cat(w->sb, "\r\n");
#define HTTPH(a, b, c, d, e, f, g) \
do { \
if (d && sp->http.b != NULL) { \
sbuf_cat(w->sb, a ": "); \
sbuf_cat(w->sb, sp->http.b); \
sbuf_cat(w->sb, "\r\n"); \
} \
} while (0);
#include "http_headers.h"
#undef HTTPH
sbuf_cat(w->sb, "\r\n");
sbuf_finish(w->sb);
HttpdBuildSbuf(0, 1, w->sb, sp);
i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb));
assert(i == sbuf_len(w->sb));
/* XXX: copy any contents */
memset(&sp2, 0, sizeof sp2);
sp2.rd_e = &w->e1;
sp2.fd = fd;
HttpdGetHead(&sp2, w->eb, PassReturn);
event_base_loop(w->eb, 0);
sbuf_clear(w->sb);
sbuf_cat(w->sb, sp2.http.proto);
sbuf_cat(w->sb, " ");
sbuf_cat(w->sb, sp2.http.status);
sbuf_cat(w->sb, " ");
sbuf_cat(w->sb, sp2.http.response);
sbuf_cat(w->sb, "\r\n");
#define HTTPH(a, b, c, d, e, f, g) \
do { \
if (d && sp2.http.b != NULL) { \
sbuf_cat(w->sb, a ": "); \
sbuf_cat(w->sb, sp2.http.b); \
sbuf_cat(w->sb, "\r\n"); \
} \
} while (0);
#include "http_headers.h"
#undef HTTPH
sbuf_cat(w->sb, "\r\n");
sbuf_finish(w->sb);
HttpdBuildSbuf(1, 1, w->sb, &sp2);
i = write(sp->fd, sbuf_data(w->sb), sbuf_len(w->sb));
assert(i == sbuf_len(w->sb));
if (sp2.http.H_Content_Length != NULL) {
cl = strtoumax(sp2.http.H_Content_Length, NULL, 0);
VSL(SLT_Debug, 0, "CL %ju %u %u", cl, sp->rcv_len, sp->hdr_end);
i = fcntl(sp2.fd, F_GETFL);
i &= ~O_NONBLOCK;
i = fcntl(sp2.fd, F_SETFL, i);
assert(i != -1);
i = sp2.rcv_len - sp2.hdr_end;
if (i > 0) {
VSL(SLT_Debug, 0, "Wr1 %d", i);
j = write(sp->fd, sp2.rcv + sp2.hdr_end, i);
assert(j == i);
cl -= i;
......@@ -112,14 +79,15 @@ PassSession(struct worker *w, struct sess *sp)
i = recv(sp2.fd, buf, j, 0);
assert(i >= 0);
if (i > 0) {
VSL(SLT_Debug, 0, "Rd %d", i);
cl -= i;
j = write(sp->fd, buf, i);
assert(j == i);
} else if (i == 0) {
VSL(SLT_Debug, 0, "EOF %d", i);
break;
}
}
}
/* XXX: move remaining input in sp->rcv */
/* XXX: return session to acceptor */
}
......@@ -44,37 +44,21 @@ rdf(int fd, short event, void *arg)
void
PipeSession(struct worker *w, struct sess *sp)
{
int fd, i;
int fd, i, j;
void *fd_token;
struct edir e1, e2;
fd = VBE_GetFd(sp->backend, &fd_token);
assert(fd != -1);
sbuf_clear(w->sb);
assert(w->sb != NULL);
sbuf_cat(w->sb, sp->http.req);
sbuf_cat(w->sb, " ");
sbuf_cat(w->sb, sp->http.url);
if (sp->http.proto != NULL) {
sbuf_cat(w->sb, " ");
sbuf_cat(w->sb, sp->http.proto);
}
sbuf_cat(w->sb, "\r\n");
#define HTTPH(a, b, c, d, e, f, g) \
do { \
if (sp->http.b != NULL) { \
sbuf_cat(w->sb, a ": "); \
sbuf_cat(w->sb, sp->http.b); \
sbuf_cat(w->sb, "\r\n"); \
} \
} while (0);
#include "http_headers.h"
#undef HTTPH
sbuf_cat(w->sb, "\r\n");
sbuf_finish(w->sb);
HttpdBuildSbuf(0, 0, w->sb, sp);
i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb));
assert(i == sbuf_len(w->sb));
i = sp->rcv_len - sp->hdr_end;
if (i > 0) {
j = write(sp->fd, sp->rcv + sp->hdr_end, i);
assert(j == i);
}
e1.fd = fd;
e2.fd = sp->fd;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment