|  | varnish-cache/bin/varnishd/http1/cache_http1_fsm.c | 
| 0 | 
   | 
  /*-  | 
| 1 | 
   | 
   * Copyright (c) 2006 Verdens Gang AS  | 
| 2 | 
   | 
   * Copyright (c) 2006-2015 Varnish Software AS  | 
| 3 | 
   | 
   * All rights reserved.  | 
| 4 | 
   | 
   *  | 
| 5 | 
   | 
   * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>  | 
| 6 | 
   | 
   *  | 
| 7 | 
   | 
   * SPDX-License-Identifier: BSD-2-Clause  | 
| 8 | 
   | 
   *  | 
| 9 | 
   | 
   * Redistribution and use in source and binary forms, with or without  | 
| 10 | 
   | 
   * modification, are permitted provided that the following conditions  | 
| 11 | 
   | 
   * are met:  | 
| 12 | 
   | 
   * 1. Redistributions of source code must retain the above copyright  | 
| 13 | 
   | 
   *    notice, this list of conditions and the following disclaimer.  | 
| 14 | 
   | 
   * 2. Redistributions in binary form must reproduce the above copyright  | 
| 15 | 
   | 
   *    notice, this list of conditions and the following disclaimer in the  | 
| 16 | 
   | 
   *    documentation and/or other materials provided with the distribution.  | 
| 17 | 
   | 
   *  | 
| 18 | 
   | 
   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND  | 
| 19 | 
   | 
   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE  | 
| 20 | 
   | 
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE  | 
| 21 | 
   | 
   * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE  | 
| 22 | 
   | 
   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL  | 
| 23 | 
   | 
   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS  | 
| 24 | 
   | 
   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)  | 
| 25 | 
   | 
   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT  | 
| 26 | 
   | 
   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY  | 
| 27 | 
   | 
   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF  | 
| 28 | 
   | 
   * SUCH DAMAGE.  | 
| 29 | 
   | 
   *  | 
| 30 | 
   | 
   * This file contains the two central state machine for pushing HTTP1  | 
| 31 | 
   | 
   * sessions through their states.  | 
| 32 | 
   | 
   *  | 
| 33 | 
   | 
   */  | 
| 34 | 
   | 
   | 
| 35 | 
   | 
  #include "config.h"  | 
| 36 | 
   | 
   | 
| 37 | 
   | 
  #include <stdio.h>  | 
| 38 | 
   | 
  #include <stdlib.h>  | 
| 39 | 
   | 
   | 
| 40 | 
   | 
  #include "cache/cache_varnishd.h"  | 
| 41 | 
   | 
  #include "cache/cache_objhead.h"  | 
| 42 | 
   | 
  #include "cache/cache_transport.h"  | 
| 43 | 
   | 
  #include "cache_http1.h"  | 
| 44 | 
   | 
   | 
| 45 | 
   | 
  #include "vtcp.h"  | 
| 46 | 
   | 
   | 
| 47 | 
   | 
  static const char H1NEWREQ[] = "HTTP1::NewReq";  | 
| 48 | 
   | 
  static const char H1PROC[] = "HTTP1::Proc";  | 
| 49 | 
   | 
  static const char H1CLEANUP[] = "HTTP1::Cleanup";  | 
| 50 | 
   | 
   | 
| 51 | 
   | 
  static void HTTP1_Session(struct worker *, struct req *);  | 
| 52 | 
   | 
   | 
| 53 | 
   | 
  static void  | 
| 54 | 
  472634 | 
  http1_setstate(const struct sess *sp, const char *s)  | 
| 55 | 
   | 
  { | 
| 56 | 
   | 
          uintptr_t p;  | 
| 57 | 
   | 
   | 
| 58 | 
  472634 | 
          p = (uintptr_t)s;  | 
| 59 | 
  472634 | 
          AZ(SES_Set_proto_priv(sp, &p));  | 
| 60 | 
  472634 | 
  }  | 
| 61 | 
   | 
   | 
| 62 | 
   | 
  static const char *  | 
| 63 | 
  568852 | 
  http1_getstate(const struct sess *sp)  | 
| 64 | 
   | 
  { | 
| 65 | 
   | 
          uintptr_t *p;  | 
| 66 | 
   | 
   | 
| 67 | 
  568852 | 
          AZ(SES_Get_proto_priv(sp, &p));  | 
| 68 | 
  568852 | 
          return ((const char *)*p);  | 
| 69 | 
   | 
  }  | 
| 70 | 
   | 
   | 
| 71 | 
   | 
  /*--------------------------------------------------------------------  | 
| 72 | 
   | 
   * Call protocol for this request  | 
| 73 | 
   | 
   */  | 
| 74 | 
   | 
   | 
| 75 | 
   | 
  static void v_matchproto_(task_func_t)  | 
| 76 | 
  97442 | 
  http1_req(struct worker *wrk, void *arg)  | 
| 77 | 
   | 
  { | 
| 78 | 
   | 
          struct req *req;  | 
| 79 | 
   | 
   | 
| 80 | 
  97442 | 
          CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);  | 
| 81 | 
  97442 | 
          CAST_OBJ_NOTNULL(req, arg, REQ_MAGIC);  | 
| 82 | 
   | 
   | 
| 83 | 
  97442 | 
          THR_SetRequest(req);  | 
| 84 | 
  97442 | 
          assert(!WS_IsReserved(wrk->aws));  | 
| 85 | 
  97442 | 
          HTTP1_Session(wrk, req);  | 
| 86 | 
  97442 | 
          WS_Assert(wrk->aws);  | 
| 87 | 
  97442 | 
          THR_SetRequest(NULL);  | 
| 88 | 
  97442 | 
  }  | 
| 89 | 
   | 
   | 
| 90 | 
   | 
  /*--------------------------------------------------------------------  | 
| 91 | 
   | 
   * Call protocol for this session (new or from waiter)  | 
| 92 | 
   | 
   *  | 
| 93 | 
   | 
   * When sessions are rescheduled from the waiter, a struct pool_task  | 
| 94 | 
   | 
   * is put on the reserved session workspace (for reasons of memory  | 
| 95 | 
   | 
   * conservation).  This reservation is released as the first thing.  | 
| 96 | 
   | 
   * The acceptor and any other code which schedules this function  | 
| 97 | 
   | 
   * must obey this calling convention with a dummy reservation.  | 
| 98 | 
   | 
   */  | 
| 99 | 
   | 
   | 
| 100 | 
   | 
  static void v_matchproto_(task_func_t)  | 
| 101 | 
  87309 | 
  http1_new_session(struct worker *wrk, void *arg)  | 
| 102 | 
   | 
  { | 
| 103 | 
   | 
          struct sess *sp;  | 
| 104 | 
   | 
          struct req *req;  | 
| 105 | 
   | 
          uintptr_t *u;  | 
| 106 | 
   | 
          ssize_t sz;  | 
| 107 | 
   | 
   | 
| 108 | 
  87309 | 
          CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);  | 
| 109 | 
  87309 | 
          CAST_OBJ_NOTNULL(req, arg, REQ_MAGIC);  | 
| 110 | 
  87309 | 
          sp = req->sp;  | 
| 111 | 
  87309 | 
          CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);  | 
| 112 | 
   | 
   | 
| 113 | 
  87309 | 
          HTC_RxInit(req->htc, req->ws);  | 
| 114 | 
   | 
   | 
| 115 | 
  87309 | 
          sz = sizeof u;  | 
| 116 | 
  87309 | 
          if (SES_Get_proto_priv(sp, &u) &&  | 
| 117 | 
  87301 | 
              !SES_Reserve_proto_priv(sp, &u, &sz)) { | 
| 118 | 
   | 
                  /* Out of session workspace. Free the req, close the sess,  | 
| 119 | 
   | 
                   * and do not set a new task func, which will exit the  | 
| 120 | 
   | 
                   * worker thread. */  | 
| 121 | 
  40 | 
                  VSL(SLT_Error, req->sp->vxid,  | 
| 122 | 
   | 
                      "insufficient workspace (proto_priv)");  | 
| 123 | 
  40 | 
                  WS_Release(req->ws, 0);  | 
| 124 | 
  40 | 
                  Req_Release(req);  | 
| 125 | 
  40 | 
                  SES_Delete(sp, SC_RX_JUNK, NAN);  | 
| 126 | 
  40 | 
                  return;  | 
| 127 | 
   | 
          }  | 
| 128 | 
  87269 | 
          assert(sz == sizeof u);  | 
| 129 | 
  87261 | 
          http1_setstate(sp, H1NEWREQ);  | 
| 130 | 
  87261 | 
          wrk->task->func = http1_req;  | 
| 131 | 
  87261 | 
          wrk->task->priv = req;  | 
| 132 | 
  87301 | 
  }  | 
| 133 | 
   | 
   | 
| 134 | 
   | 
  static void v_matchproto_(task_func_t)  | 
| 135 | 
  5610 | 
  http1_unwait(struct worker *wrk, void *arg)  | 
| 136 | 
   | 
  { | 
| 137 | 
   | 
          struct sess *sp;  | 
| 138 | 
   | 
          struct req *req;  | 
| 139 | 
   | 
   | 
| 140 | 
  5610 | 
          CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);  | 
| 141 | 
  5610 | 
          CAST_OBJ_NOTNULL(sp, arg, SESS_MAGIC);  | 
| 142 | 
  5610 | 
          WS_Release(sp->ws, 0);  | 
| 143 | 
  5610 | 
          req = Req_New(sp, NULL);  | 
| 144 | 
  5610 | 
          CHECK_OBJ_NOTNULL(req, REQ_MAGIC);  | 
| 145 | 
  5610 | 
          req->htc->rfd = &sp->fd;  | 
| 146 | 
  5610 | 
          HTC_RxInit(req->htc, req->ws);  | 
| 147 | 
  5610 | 
          http1_setstate(sp, H1NEWREQ);  | 
| 148 | 
  5610 | 
          wrk->task->func = http1_req;  | 
| 149 | 
  5610 | 
          wrk->task->priv = req;  | 
| 150 | 
  5610 | 
  }  | 
| 151 | 
   | 
   | 
| 152 | 
   | 
  static void v_matchproto_(vtr_req_body_t)  | 
| 153 | 
  3760 | 
  http1_req_body(struct req *req)  | 
| 154 | 
   | 
  { | 
| 155 | 
   | 
   | 
| 156 | 
  3760 | 
          CHECK_OBJ_NOTNULL(req, REQ_MAGIC);  | 
| 157 | 
  3760 | 
          if (V1F_Setup_Fetch(req->vfc, req->htc) != 0)  | 
| 158 | 
  0 | 
                  req->req_body_status = BS_ERROR;  | 
| 159 | 
  3760 | 
  }  | 
| 160 | 
   | 
   | 
| 161 | 
   | 
  static void  | 
| 162 | 
  240 | 
  http1_sess_panic(struct vsb *vsb, const struct sess *sp)  | 
| 163 | 
   | 
  { | 
| 164 | 
   | 
   | 
| 165 | 
  240 | 
          VSB_printf(vsb, "state = %s\n", http1_getstate(sp));  | 
| 166 | 
  240 | 
  }  | 
| 167 | 
   | 
   | 
| 168 | 
   | 
  static void  | 
| 169 | 
  200 | 
  http1_req_panic(struct vsb *vsb, const struct req *req)  | 
| 170 | 
   | 
  { | 
| 171 | 
   | 
   | 
| 172 | 
  200 | 
          VSB_printf(vsb, "state = %s\n", http1_getstate(req->sp));  | 
| 173 | 
  200 | 
  }  | 
| 174 | 
   | 
   | 
| 175 | 
   | 
  static void v_matchproto_(vtr_req_fail_f)  | 
| 176 | 
  1199 | 
  http1_req_fail(struct req *req, stream_close_t reason)  | 
| 177 | 
   | 
  { | 
| 178 | 
  1199 | 
          assert(reason != SC_NULL);  | 
| 179 | 
  1199 | 
          assert(req->sp->fd != 0);  | 
| 180 | 
  1199 | 
          if (req->sp->fd > 0)  | 
| 181 | 
  1199 | 
                  SES_Close(req->sp, reason);  | 
| 182 | 
  1199 | 
  }  | 
| 183 | 
   | 
   | 
| 184 | 
   | 
  static int v_matchproto_(vtr_minimal_response_f)  | 
| 185 | 
  2160 | 
  http1_minimal_response(struct req *req, uint16_t status)  | 
| 186 | 
   | 
  { | 
| 187 | 
   | 
          ssize_t wl, l;  | 
| 188 | 
   | 
          char buf[80];  | 
| 189 | 
   | 
          const char *reason;  | 
| 190 | 
   | 
   | 
| 191 | 
  2160 | 
          assert(status >= 100);  | 
| 192 | 
  2160 | 
          assert(status < 1000);  | 
| 193 | 
   | 
   | 
| 194 | 
  2160 | 
          reason = http_Status2Reason(status, NULL);  | 
| 195 | 
   | 
   | 
| 196 | 
  2160 | 
          bprintf(buf, "HTTP/1.1 %03d %s\r\n\r\n", status, reason);  | 
| 197 | 
  2160 | 
          l = strlen(buf);  | 
| 198 | 
   | 
   | 
| 199 | 
  2160 | 
          VSLb(req->vsl, SLT_RespProtocol, "HTTP/1.1");  | 
| 200 | 
  2160 | 
          VSLb(req->vsl, SLT_RespStatus, "%03d", status);  | 
| 201 | 
  2160 | 
          VSLbs(req->vsl, SLT_RespReason, TOSTRAND(reason));  | 
| 202 | 
   | 
   | 
| 203 | 
  2160 | 
          if (status >= 400)  | 
| 204 | 
  1960 | 
                  req->err_code = status;  | 
| 205 | 
  2160 | 
          wl = write(req->sp->fd, buf, l);  | 
| 206 | 
   | 
   | 
| 207 | 
  2160 | 
          if (wl > 0)  | 
| 208 | 
  2160 | 
                  req->acct.resp_hdrbytes += wl;  | 
| 209 | 
  2160 | 
          if (wl != l) { | 
| 210 | 
  0 | 
                  if (wl < 0)  | 
| 211 | 
  0 | 
                          VTCP_Assert(1);  | 
| 212 | 
  0 | 
                  if (req->doclose == SC_NULL)  | 
| 213 | 
  0 | 
                          req->doclose = SC_REM_CLOSE;  | 
| 214 | 
  0 | 
                  return (-1);  | 
| 215 | 
   | 
          }  | 
| 216 | 
  2160 | 
          return (0);  | 
| 217 | 
  2160 | 
  }  | 
| 218 | 
   | 
   | 
| 219 | 
   | 
  struct transport HTTP1_transport = { | 
| 220 | 
   | 
          .name =                 "HTTP/1",  | 
| 221 | 
   | 
          .proto_ident =          "HTTP",  | 
| 222 | 
   | 
          .magic =                TRANSPORT_MAGIC,  | 
| 223 | 
   | 
          .deliver =              V1D_Deliver,  | 
| 224 | 
   | 
          .minimal_response =     http1_minimal_response,  | 
| 225 | 
   | 
          .new_session =          http1_new_session,  | 
| 226 | 
   | 
          .req_body =             http1_req_body,  | 
| 227 | 
   | 
          .req_fail =             http1_req_fail,  | 
| 228 | 
   | 
          .req_panic =            http1_req_panic,  | 
| 229 | 
   | 
          .sess_panic =           http1_sess_panic,  | 
| 230 | 
   | 
          .unwait =               http1_unwait,  | 
| 231 | 
   | 
  };  | 
| 232 | 
   | 
   | 
| 233 | 
   | 
  /*----------------------------------------------------------------------  | 
| 234 | 
   | 
   */  | 
| 235 | 
   | 
   | 
| 236 | 
   | 
  static inline void  | 
| 237 | 
  1320 | 
  http1_abort(struct req *req, uint16_t status)  | 
| 238 | 
   | 
  { | 
| 239 | 
  1320 | 
          assert(req->doclose != SC_NULL);  | 
| 240 | 
  1320 | 
          assert(status >= 400);  | 
| 241 | 
  1320 | 
          (void)http1_minimal_response(req, status);  | 
| 242 | 
  1320 | 
  }  | 
| 243 | 
   | 
   | 
| 244 | 
   | 
  static int  | 
| 245 | 
  132083 | 
  http1_dissect(struct worker *wrk, struct req *req)  | 
| 246 | 
   | 
  { | 
| 247 | 
   | 
   | 
| 248 | 
  132083 | 
          CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);  | 
| 249 | 
  132083 | 
          CHECK_OBJ_NOTNULL(req, REQ_MAGIC);  | 
| 250 | 
  132083 | 
          CHECK_OBJ_NOTNULL(req->transport, TRANSPORT_MAGIC);  | 
| 251 | 
   | 
   | 
| 252 | 
   | 
          /* Allocate a new vxid now that we know we'll need it. */  | 
| 253 | 
  132083 | 
          assert(IS_NO_VXID(req->vsl->wid));  | 
| 254 | 
  132083 | 
          req->vsl->wid = VXID_Get(wrk, VSL_CLIENTMARKER);  | 
| 255 | 
   | 
   | 
| 256 | 
  132083 | 
          VSLb(req->vsl, SLT_Begin, "req %ju rxreq", VXID(req->sp->vxid));  | 
| 257 | 
  132083 | 
          VSL(SLT_Link, req->sp->vxid, "req %ju rxreq", VXID(req->vsl->wid));  | 
| 258 | 
  132083 | 
          AZ(isnan(req->t_first)); /* First byte timestamp set by http1_wait */  | 
| 259 | 
  132083 | 
          AZ(isnan(req->t_req));   /* Complete req rcvd set by http1_wait */  | 
| 260 | 
  132083 | 
          req->t_prev = req->t_first;  | 
| 261 | 
  132083 | 
          VSLb_ts_req(req, "Start", req->t_first);  | 
| 262 | 
  132083 | 
          VSLb_ts_req(req, "Req", req->t_req);  | 
| 263 | 
   | 
   | 
| 264 | 
  132083 | 
          HTTP_Setup(req->http, req->ws, req->vsl, SLT_ReqMethod);  | 
| 265 | 
  132083 | 
          req->err_code = HTTP1_DissectRequest(req->htc, req->http);  | 
| 266 | 
   | 
   | 
| 267 | 
   | 
          /* If we could not even parse the request, just close */  | 
| 268 | 
  132083 | 
          if (req->err_code != 0) { | 
| 269 | 
  2640 | 
                  VSLb(req->vsl, SLT_HttpGarbage, "%.*s",  | 
| 270 | 
  1320 | 
                      (int)(req->htc->rxbuf_e - req->htc->rxbuf_b),  | 
| 271 | 
  1320 | 
                      req->htc->rxbuf_b);  | 
| 272 | 
  1320 | 
                  wrk->stats->client_req_400++;  | 
| 273 | 
   | 
   | 
| 274 | 
  1320 | 
                  (void)Req_LogStart(wrk, req);  | 
| 275 | 
   | 
   | 
| 276 | 
  1320 | 
                  req->doclose = SC_RX_JUNK;  | 
| 277 | 
  1320 | 
                  http1_abort(req, 400);  | 
| 278 | 
  1320 | 
                  return (-1);  | 
| 279 | 
   | 
          }  | 
| 280 | 
   | 
   | 
| 281 | 
  130763 | 
          AZ(req->req_body_status);  | 
| 282 | 
  130763 | 
          req->req_body_status = req->htc->body_status;  | 
| 283 | 
  130763 | 
          return (0);  | 
| 284 | 
  132083 | 
  }  | 
| 285 | 
   | 
   | 
| 286 | 
   | 
  /*----------------------------------------------------------------------  | 
| 287 | 
   | 
   */  | 
| 288 | 
   | 
   | 
| 289 | 
   | 
  static void  | 
| 290 | 
  97188 | 
  HTTP1_Session(struct worker *wrk, struct req *req)  | 
| 291 | 
   | 
  { | 
| 292 | 
   | 
          enum htc_status_e hs;  | 
| 293 | 
   | 
          struct sess *sp;  | 
| 294 | 
   | 
          const char *st;  | 
| 295 | 
   | 
          int i;  | 
| 296 | 
   | 
   | 
| 297 | 
  97188 | 
          CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);  | 
| 298 | 
  97188 | 
          CHECK_OBJ_NOTNULL(req, REQ_MAGIC);  | 
| 299 | 
  97188 | 
          sp = req->sp;  | 
| 300 | 
  97188 | 
          CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);  | 
| 301 | 
   | 
   | 
| 302 | 
   | 
          /*  | 
| 303 | 
   | 
           * Whenever we come in from the acceptor or waiter, we need to set  | 
| 304 | 
   | 
           * blocking mode.  It would be simpler to do this in the acceptor  | 
| 305 | 
   | 
           * or waiter, but we'd rather do the syscall in the worker thread.  | 
| 306 | 
   | 
           */  | 
| 307 | 
  97188 | 
          if (http1_getstate(sp) == H1NEWREQ)  | 
| 308 | 
  92867 | 
                  VTCP_blocking(sp->fd);  | 
| 309 | 
  97188 | 
          req->transport = XPORT_ByNumber(sp->sattr[SA_TRANSPORT]);  | 
| 310 | 
   | 
   | 
| 311 | 
  469392 | 
          while (1) { | 
| 312 | 
  470792 | 
                  st = http1_getstate(sp);  | 
| 313 | 
  470792 | 
                  if (st == H1NEWREQ) { | 
| 314 | 
  204301 | 
                          CHECK_OBJ_NOTNULL(req->transport, TRANSPORT_MAGIC);  | 
| 315 | 
  204301 | 
                          assert(isnan(req->t_prev));  | 
| 316 | 
  204301 | 
                          assert(isnan(req->t_req));  | 
| 317 | 
  204301 | 
                          AZ(req->vcl);  | 
| 318 | 
  204301 | 
                          AZ(req->esi_level);  | 
| 319 | 
  204301 | 
                          AN(WS_Reservation(req->htc->ws));  | 
| 320 | 
   | 
   | 
| 321 | 
  408602 | 
                          hs = HTC_RxStuff(req->htc, HTTP1_Complete,  | 
| 322 | 
  204301 | 
                              &req->t_first, &req->t_req,  | 
| 323 | 
  204301 | 
                              sp->t_idle + SESS_TMO(sp, timeout_linger),  | 
| 324 | 
  204301 | 
                              sp->t_idle + SESS_TMO(sp, timeout_idle),  | 
| 325 | 
   | 
                              NAN,  | 
| 326 | 
  204301 | 
                              cache_param->http_req_size);  | 
| 327 | 
  204301 | 
                          assert(!WS_IsReserved(req->htc->ws));  | 
| 328 | 
  204301 | 
                          if (hs < HTC_S_EMPTY) { | 
| 329 | 
  58956 | 
                                  if (hs == HTC_S_OVERFLOW && cache_param->http_req_overflow_status != 0) { | 
| 330 | 
  80 | 
                                          (void)req->transport->minimal_response(req,  | 
| 331 | 
  40 | 
                                              cache_param->http_req_overflow_status);  | 
| 332 | 
  40 | 
                                  }  | 
| 333 | 
  58956 | 
                                  req->acct.req_hdrbytes +=  | 
| 334 | 
  58956 | 
                                      req->htc->rxbuf_e - req->htc->rxbuf_b;  | 
| 335 | 
  58956 | 
                                  Req_AcctLogCharge(wrk->stats, req);  | 
| 336 | 
  58956 | 
                                  Req_Release(req);  | 
| 337 | 
  58956 | 
                                  SES_DeleteHS(sp, hs, NAN);  | 
| 338 | 
  58956 | 
                                  return;  | 
| 339 | 
   | 
                          }  | 
| 340 | 
  145345 | 
                          if (hs == HTC_S_IDLE) { | 
| 341 | 
  7314 | 
                                  wrk->stats->sess_herd++;  | 
| 342 | 
  7314 | 
                                  Req_Release(req);  | 
| 343 | 
  7314 | 
                                  SES_Wait(sp, &HTTP1_transport);  | 
| 344 | 
  7314 | 
                                  return;  | 
| 345 | 
   | 
                          }  | 
| 346 | 
  138031 | 
                          if (hs != HTC_S_COMPLETE)  | 
| 347 | 
  0 | 
                                  WRONG("htc_status (nonbad)"); | 
| 348 | 
   | 
   | 
| 349 | 
  138031 | 
                          if (H2_prism_complete(req->htc) == HTC_S_COMPLETE) { | 
| 350 | 
  5960 | 
                                  if (!FEATURE(FEATURE_HTTP2)) { | 
| 351 | 
  80 | 
                                          SES_Close(req->sp, SC_REQ_HTTP20);  | 
| 352 | 
  80 | 
                                          assert(!WS_IsReserved(req->ws));  | 
| 353 | 
  80 | 
                                          assert(!WS_IsReserved(wrk->aws));  | 
| 354 | 
  80 | 
                                          http1_setstate(sp, H1CLEANUP);  | 
| 355 | 
  80 | 
                                          continue;  | 
| 356 | 
   | 
                                  }  | 
| 357 | 
  5880 | 
                                  http1_setstate(sp, NULL);  | 
| 358 | 
  5880 | 
                                  H2_PU_Sess(wrk, sp, req);  | 
| 359 | 
  5880 | 
                                  return;  | 
| 360 | 
   | 
                          }  | 
| 361 | 
   | 
   | 
| 362 | 
  132071 | 
                          i = http1_dissect(wrk, req);  | 
| 363 | 
  132071 | 
                          req->acct.req_hdrbytes +=  | 
| 364 | 
  132071 | 
                              req->htc->rxbuf_e - req->htc->rxbuf_b;  | 
| 365 | 
  132071 | 
                          if (i) { | 
| 366 | 
  1320 | 
                                  assert(req->doclose != SC_NULL);  | 
| 367 | 
  1320 | 
                                  SES_Close(req->sp, req->doclose);  | 
| 368 | 
  1320 | 
                                  assert(!WS_IsReserved(req->ws));  | 
| 369 | 
  1320 | 
                                  assert(!WS_IsReserved(wrk->aws));  | 
| 370 | 
  1320 | 
                                  http1_setstate(sp, H1CLEANUP);  | 
| 371 | 
  1320 | 
                                  continue;  | 
| 372 | 
   | 
                          }  | 
| 373 | 
  130751 | 
                          if (http_HdrIs(req->http, H_Upgrade, "h2c")) { | 
| 374 | 
  360 | 
                                  if (!FEATURE(FEATURE_HTTP2)) { | 
| 375 | 
  40 | 
                                          VSLb(req->vsl, SLT_Debug,  | 
| 376 | 
   | 
                                              "H2 upgrade attempt");  | 
| 377 | 
  360 | 
                                  } else if (req->htc->body_status != BS_NONE) { | 
| 378 | 
  40 | 
                                          VSLb(req->vsl, SLT_Debug,  | 
| 379 | 
   | 
                                              "H2 upgrade attempt has body");  | 
| 380 | 
  40 | 
                                  } else { | 
| 381 | 
  280 | 
                                          http1_setstate(sp, NULL);  | 
| 382 | 
  280 | 
                                          req->err_code = 2;  | 
| 383 | 
  280 | 
                                          H2_OU_Sess(wrk, sp, req);  | 
| 384 | 
  280 | 
                                          return;  | 
| 385 | 
   | 
                                  }  | 
| 386 | 
  80 | 
                          }  | 
| 387 | 
  130471 | 
                          assert(req->req_step == R_STP_TRANSPORT);  | 
| 388 | 
  130471 | 
                          VCL_TaskEnter(req->privs);  | 
| 389 | 
  130471 | 
                          VCL_TaskEnter(req->top->privs);  | 
| 390 | 
  130471 | 
                          http1_setstate(sp, H1PROC);  | 
| 391 | 
  396962 | 
                  } else if (st == H1PROC) { | 
| 392 | 
  134831 | 
                          req->task->func = http1_req;  | 
| 393 | 
  134831 | 
                          req->task->priv = req;  | 
| 394 | 
  134831 | 
                          CNT_Embark(wrk, req);  | 
| 395 | 
  134831 | 
                          if (CNT_Request(req) == REQ_FSM_DISEMBARK)  | 
| 396 | 
  4573 | 
                                  return;  | 
| 397 | 
  130258 | 
                          wrk->stats->client_req++;  | 
| 398 | 
  130258 | 
                          AZ(req->top->vcl0);  | 
| 399 | 
  130258 | 
                          req->task->func = NULL;  | 
| 400 | 
  130258 | 
                          req->task->priv = NULL;  | 
| 401 | 
  130258 | 
                          assert(!WS_IsReserved(req->ws));  | 
| 402 | 
  130258 | 
                          assert(!WS_IsReserved(wrk->aws));  | 
| 403 | 
  130258 | 
                          http1_setstate(sp, H1CLEANUP);  | 
| 404 | 
  261918 | 
                  } else if (st == H1CLEANUP) { | 
| 405 | 
   | 
   | 
| 406 | 
  131660 | 
                          assert(!WS_IsReserved(wrk->aws));  | 
| 407 | 
  131660 | 
                          assert(!WS_IsReserved(req->ws));  | 
| 408 | 
   | 
   | 
| 409 | 
  131660 | 
                          if (sp->fd >= 0 && req->doclose != SC_NULL)  | 
| 410 | 
  16626 | 
                                  SES_Close(sp, req->doclose);  | 
| 411 | 
   | 
   | 
| 412 | 
  131660 | 
                          if (sp->fd < 0) { | 
| 413 | 
  20185 | 
                                  wrk->stats->sess_closed++;  | 
| 414 | 
  20185 | 
                                  Req_Cleanup(sp, wrk, req);  | 
| 415 | 
  20185 | 
                                  Req_Release(req);  | 
| 416 | 
  20185 | 
                                  SES_Delete(sp, SC_NULL, NAN);  | 
| 417 | 
  20185 | 
                                  return;  | 
| 418 | 
   | 
                          }  | 
| 419 | 
   | 
   | 
| 420 | 
  111475 | 
                          Req_Cleanup(sp, wrk, req);  | 
| 421 | 
  111475 | 
                          HTC_RxInit(req->htc, req->ws);  | 
| 422 | 
  111475 | 
                          if (req->htc->rxbuf_e != req->htc->rxbuf_b)  | 
| 423 | 
  538 | 
                                  wrk->stats->sess_readahead++;  | 
| 424 | 
  111475 | 
                          if (FEATURE(FEATURE_BUSY_STATS_RATE))  | 
| 425 | 
  0 | 
                                  WRK_AddStat(wrk);  | 
| 426 | 
  111475 | 
                          http1_setstate(sp, H1NEWREQ);  | 
| 427 | 
  111475 | 
                  } else { | 
| 428 | 
  0 | 
                          WRONG("Wrong H1 session state"); | 
| 429 | 
   | 
                  }  | 
| 430 | 
   | 
          }  | 
| 431 | 
  97188 | 
  }  |