[trivial] Use the callbacks to determine if a given connection is h1
@@ -1013,9 +1013,7 @@ static int foreach_request(h2o_context_t *ctx, int (*cb)(h2o_req_t *req, void *c
return 0;
}
-void h2o_http1_accept(h2o_accept_ctx_t *ctx, h2o_socket_t *sock, struct timeval connected_at)
-{
- static const h2o_conn_callbacks_t callbacks = {
+static const h2o_conn_callbacks_t h1_callbacks = {
get_sockname, /* stringify address */
get_peername, /* ditto */
NULL, /* push */
@@ -1026,7 +1024,15 @@ void h2o_http1_accept(h2o_accept_ctx_t *ctx, h2o_socket_t *sock, struct timeval
{log_request_index}, /* http1 */
{NULL} /* http2 */
}}};
- struct st_h2o_http1_conn_t *conn = (void *)h2o_create_connection(sizeof(*conn), ctx->ctx, ctx->hosts, connected_at, &callbacks);
+
+static int conn_is_h1(h2o_conn_t *conn)
+{
+ return conn->callbacks == &h1_callbacks;
+}
+
+void h2o_http1_accept(h2o_accept_ctx_t *ctx, h2o_socket_t *sock, struct timeval connected_at)
+{
+ struct st_h2o_http1_conn_t *conn = (void *)h2o_create_connection(sizeof(*conn), ctx->ctx, ctx->hosts, connected_at, &h1_callbacks);
/* zero-fill all properties expect req */
memset((char *)conn + sizeof(conn->super), 0, offsetof(struct st_h2o_http1_conn_t, req) - sizeof(conn->super));
@@ -1042,9 +1048,9 @@ void h2o_http1_accept(h2o_accept_ctx_t *ctx, h2o_socket_t *sock, struct timeval
void h2o_http1_upgrade(h2o_req_t *req, h2o_iovec_t *inbufs, size_t inbufcnt, h2o_http1_upgrade_cb on_complete, void *user_data)
{
- struct st_h2o_http1_conn_t *conn = (void *)req->conn;
- assert(req->version <= 0x200); /* TODO find a better way to assert instanceof(req->conn) == struct st_h2o_http1_conn_t */
+ assert(conn_is_h1(req->conn));
+ struct st_h2o_http1_conn_t *conn = (void *)req->conn;
h2o_iovec_t *bufs = alloca(sizeof(h2o_iovec_t) * (inbufcnt + 1));
