int http_GetURL(struct http *hp, char **b);
void http_RecvHead(struct http *hp, int fd, struct event_base *eb, http_callback_f *func, void *arg);
void http_Dissect(struct http *sp, int fd, int rr);
-void http_BuildSbuf(int fd, int resp, struct sbuf *sb, struct http *hp);
+enum http_build {
+ Build_Pipe,
+ Build_Pass,
+ Build_Fetch,
+ Build_Reply,
+};
+void http_BuildSbuf(int fd, enum http_build mode, struct sbuf *sb, struct http *hp);
/* cache_main.c */
extern pthread_mutex_t sessmtx;
{
struct storage *st;
unsigned u = 0;
+ char *r;
if (l == 0)
l = strlen(b);
vca_write(sp, b, l);
- TAILQ_FOREACH(st, &sp->obj->store, list) {
- u += st->len;
- if (st->stevedore->send != NULL)
- st->stevedore->send(st, sp);
- else
- vca_write(sp, st->ptr, st->len);
+ assert(http_GetReq(sp->http, &r));
+ if (!strcmp(r, "GET")) {
+ TAILQ_FOREACH(st, &sp->obj->store, list) {
+ u += st->len;
+ if (st->stevedore->send != NULL)
+ st->stevedore->send(st, sp);
+ else
+ vca_write(sp, st->ptr, st->len);
+ }
+ assert(u == sp->obj->len);
}
- assert(u == sp->obj->len);
vca_flush(sp);
}
VSL(SLT_Backend, sp->fd, "%d %s", fd, sp->backend->vcl_name);
hp = http_New();
- http_BuildSbuf(fd, 1, w->sb, sp->http);
+ http_BuildSbuf(fd, Build_Fetch, w->sb, sp->http);
i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb));
assert(i == sbuf_len(w->sb));
time(&sp->t_req);
if (sp->obj->cacheable)
EXP_Insert(sp->obj);
- http_BuildSbuf(sp->fd, 3, w->sb, hp);
+ http_BuildSbuf(sp->fd, Build_Reply, w->sb, hp);
if (body) {
if (http_GetHdr(hp, "Content-Length", &b))
cls = fetch_straight(w, sp, fd, hp, b);
/*--------------------------------------------------------------------*/
void
-http_BuildSbuf(int fd, int resp, struct sbuf *sb, struct http *hp)
+http_BuildSbuf(int fd, enum http_build mode, struct sbuf *sb, struct http *hp)
{
- unsigned u;
+ unsigned u, sup;
sbuf_clear(sb);
assert(sb != NULL);
- if (resp == 2 || resp == 3) {
+ switch (mode) {
+ case Build_Reply:
sbuf_cat(sb, hp->proto);
sbuf_cat(sb, " ");
sbuf_cat(sb, hp->status);
sbuf_cat(sb, " ");
sbuf_cat(sb, hp->response);
- } else if (resp == 1) {
+ sup = 2;
+ break;
+ case Build_Pipe:
+ case Build_Pass:
sbuf_cat(sb, hp->req);
sbuf_cat(sb, " ");
sbuf_cat(sb, hp->url);
sbuf_cat(sb, " ");
sbuf_cat(sb, hp->proto);
- } else {
- printf("resp = %d\n", resp);
- assert(resp == 1 || resp == 2);
+ sup = 2;
+ break;
+ case Build_Fetch:
+ sbuf_cat(sb, "GET ");
+ sbuf_cat(sb, hp->url);
+ sbuf_cat(sb, " ");
+ sbuf_cat(sb, hp->proto);
+ sup = 1;
+ break;
+ default:
+ printf("mode = %d\n", mode);
+ assert(mode == 1 || mode == 2);
}
sbuf_cat(sb, "\r\n");
for (u = 0; u < hp->nhdr; u++) {
- if (http_supress(hp->hdr[u], resp))
+ if (http_supress(hp->hdr[u], sup))
continue;
if (1)
VSL(SLT_BldHdr, fd, "%s", hp->hdr[u]);
sbuf_cat(sb, hp->hdr[u]);
sbuf_cat(sb, "\r\n");
}
- if (resp != 3) {
+ if (mode != Build_Reply) {
sbuf_cat(sb, "\r\n");
sbuf_finish(sb);
}
fd = VBE_GetFd(sp->backend, &fd_token, sp->xid);
assert(fd != -1);
- http_BuildSbuf(fd, 1, w->sb, sp->http);
+ http_BuildSbuf(fd, Build_Pass, w->sb, sp->http);
i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb));
assert(i == sbuf_len(w->sb));
fd = VBE_GetFd(sp->backend, &fd_token, sp->xid);
assert(fd != -1);
- http_BuildSbuf(fd, 0, w->sb, sp->http); /* XXX: 0 ?? */
+ http_BuildSbuf(fd, Build_Pipe, w->sb, sp->http); /* XXX: 0 ?? */
i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb));
assert(i == sbuf_len(w->sb));
assert(__LINE__ == 0);
AZ(pthread_cond_init(&shdcnd, NULL));
+ VSL(SLT_Debug, 0, "Starting %u worker threads", heritage.wthread_min);
for (i = 0; i < heritage.wthread_min; i++) {
AZ(pthread_create(&tp, NULL, CacheWorker, NULL));
AZ(pthread_detach(tp));
struct shmloghead slh;
int i;
- unlink(fn);
heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0600);
if (heritage.vsl_fd < 0) {
fprintf(stderr, "Could not open %s: %s\n",