void h2o_config_init(h2o_global_configuration_t *config) { memset(config, 0, sizeof(*config)); h2o_linklist_init_anchor(&config->virtual_hosts); init_host_config(&config->default_host); h2o_linklist_init_anchor(&config->global_configurators); h2o_linklist_init_anchor(&config->host_configurators); config->server_name = h2o_buf_init(H2O_STRLIT("h2o/0.1")); config->req_timeout = H2O_DEFAULT_REQ_TIMEOUT; config->max_request_entity_size = H2O_DEFAULT_MAX_REQUEST_ENTITY_SIZE; config->http1_upgrade_to_http2 = H2O_DEFAULT_HTTP1_UPGRADE_TO_HTTP2; config->http2_max_concurrent_requests_per_connection = H2O_DEFAULT_HTTP2_MAX_CONCURRENT_REQUESTS_PER_CONNECTION; }
static int write_bio(BIO *b, const char *in, int len) { h2o_socket_t *sock = b->ptr; void *bytes_alloced; if (len == 0) return 0; bytes_alloced = h2o_mempool_alloc(&sock->ssl->output.pool, len); memcpy(bytes_alloced, in, len); h2o_vector_reserve(&sock->ssl->output.pool, (h2o_vector_t*)&sock->ssl->output.bufs, sizeof(h2o_buf_t), sock->ssl->output.bufs.size + 1); sock->ssl->output.bufs.entries[sock->ssl->output.bufs.size++] = h2o_buf_init(bytes_alloced, len); return len; }
static h2o_buf_t append_slash_and_dup(const char *path) { char *buf; size_t path_len = strlen(path); int needs_slash = 0; if (path_len == 0 || path[path_len - 1] != '/') needs_slash = 1; buf = h2o_malloc(path_len + 1 + needs_slash); memcpy(buf, path, path_len); if (needs_slash) buf[path_len++] = '/'; buf[path_len] = '\0'; return h2o_buf_init(buf, path_len); }
h2o_buf_t h2o_socket_ssl_get_selected_protocol(h2o_socket_t *sock) { const unsigned char *data = NULL; unsigned len = 0; assert(sock->ssl != NULL); #if H2O_USE_ALPN if (len == 0) SSL_get0_alpn_selected(sock->ssl->ssl, &data, &len); #endif #if H2O_USE_NPN if (len == 0) SSL_get0_next_proto_negotiated(sock->ssl->ssl, &data, &len); #endif return h2o_buf_init(data, len); }
void test_lib__file_c() { h2o_globalconf_t globalconf; h2o_hostconf_t *hostconf; h2o_context_t ctx; h2o_config_init(&globalconf); hostconf = h2o_config_register_host(&globalconf, "default"); h2o_file_register(hostconf, "/", "t/00unit/file", NULL, NULL); h2o_context_init(&ctx, test_loop, &globalconf); { h2o_loopback_conn_t *conn = h2o_loopback_create(&ctx); conn->req.method = h2o_buf_init(H2O_STRLIT("GET")); conn->req.path = h2o_buf_init(H2O_STRLIT("/")); h2o_loopback_run_loop(conn); ok(conn->req.res.status == 200); ok(check_header(&conn->req.res, H2O_TOKEN_CONTENT_TYPE, "text/html")); ok(h2o_memis(conn->body->bytes, conn->body->size, H2O_STRLIT("hello html\n"))); h2o_loopback_destroy(conn); } { h2o_loopback_conn_t *conn = h2o_loopback_create(&ctx); conn->req.method = h2o_buf_init(H2O_STRLIT("GET")); conn->req.path = h2o_buf_init(H2O_STRLIT("/index.html")); h2o_loopback_run_loop(conn); ok(conn->req.res.status == 200); ok(check_header(&conn->req.res, H2O_TOKEN_CONTENT_TYPE, "text/html")); ok(h2o_memis(conn->body->bytes, conn->body->size, H2O_STRLIT("hello html\n"))); h2o_loopback_destroy(conn); } { h2o_loopback_conn_t *conn = h2o_loopback_create(&ctx); conn->req.method = h2o_buf_init(H2O_STRLIT("GET")); conn->req.path = h2o_buf_init(H2O_STRLIT("/1000.txt")); h2o_loopback_run_loop(conn); ok(conn->req.res.status == 200); ok(check_header(&conn->req.res, H2O_TOKEN_CONTENT_TYPE, "text/plain")); ok(conn->body->size == 1000); ok(strcmp(sha1sum(conn->body->bytes, conn->body->size), "dfd3ae1f5c475555fad62efe42e07309fa45f2ed") == 0); h2o_loopback_destroy(conn); } { h2o_loopback_conn_t *conn = h2o_loopback_create(&ctx); conn->req.method = h2o_buf_init(H2O_STRLIT("GET")); conn->req.path = h2o_buf_init(H2O_STRLIT("/1000000.txt")); h2o_loopback_run_loop(conn); ok(conn->req.res.status == 200); ok(check_header(&conn->req.res, H2O_TOKEN_CONTENT_TYPE, "text/plain")); ok(conn->body->size == 1000000); ok(strcmp(sha1sum(conn->body->bytes, conn->body->size), "00c8ab71d0914dce6a1ec2eaa0fda0df7044b2a2") == 0); h2o_loopback_destroy(conn); } { h2o_loopback_conn_t *conn = h2o_loopback_create(&ctx); conn->req.method = h2o_buf_init(H2O_STRLIT("GET")); conn->req.path = h2o_buf_init(H2O_STRLIT("/index_txt/")); h2o_loopback_run_loop(conn); ok(conn->req.res.status == 200); ok(check_header(&conn->req.res, H2O_TOKEN_CONTENT_TYPE, "text/plain")); ok(h2o_memis(conn->body->bytes, conn->body->size, H2O_STRLIT("hello text\n"))); h2o_loopback_destroy(conn); } { h2o_loopback_conn_t *conn = h2o_loopback_create(&ctx); conn->req.method = h2o_buf_init(H2O_STRLIT("GET")); conn->req.path = h2o_buf_init(H2O_STRLIT("/index_txt")); h2o_loopback_run_loop(conn); ok(conn->req.res.status == 301); ok(check_header(&conn->req.res, H2O_TOKEN_LOCATION, "http://default/index_txt/")); h2o_loopback_destroy(conn); } { h2o_loopback_conn_t *conn = h2o_loopback_create(&ctx); conn->req.method = h2o_buf_init(H2O_STRLIT("GET")); conn->req.path = h2o_buf_init(H2O_STRLIT("/index_txt_as_dir/")); h2o_loopback_run_loop(conn); ok(conn->req.res.status == 301); ok(check_header(&conn->req.res, H2O_TOKEN_LOCATION, "http://default/index_txt_as_dir/index.txt/")); h2o_loopback_destroy(conn); } h2o_context_dispose(&ctx); h2o_config_dispose(&globalconf); }