Пример #1
0
static void register_authority(h2o_globalconf_t *globalconf, h2o_iovec_t host, uint16_t port)
{
    static h2o_iovec_t x_authority = {H2O_STRLIT("x-authority")};

    h2o_hostconf_t *hostconf = h2o_config_register_host(globalconf, host, port);
    h2o_pathconf_t *pathconf = h2o_config_register_path(hostconf, "/");
    h2o_file_register(pathconf, "t/00unit/assets", NULL, NULL, 0);

    char *authority = h2o_mem_alloc(host.len + sizeof(":65535"));
    sprintf(authority, "%.*s:%" PRIu16, (int)host.len, host.base, port);
    h2o_headers_command_t *cmds = h2o_mem_alloc(sizeof(*cmds) * 2);
    cmds[0] = (h2o_headers_command_t){H2O_HEADERS_CMD_ADD, &x_authority, {authority, strlen(authority)}};
    cmds[1] = (h2o_headers_command_t){H2O_HEADERS_CMD_NULL};
    h2o_headers_register(pathconf, cmds);
}
Пример #2
0
static int on_config_exit(h2o_configurator_t *_self, h2o_configurator_context_t *ctx, yoml_t *node)
{
    struct headers_configurator_t *self = (void *)_self;

    if (ctx->pathconf != NULL && self->cmds->size != 0) {
        h2o_vector_reserve(NULL, (h2o_vector_t *)self->cmds, sizeof(self->cmds->entries[0]), sizeof(self->cmds->size));
        self->cmds->entries[self->cmds->size] = (h2o_headers_command_t){H2O_HEADERS_CMD_NULL};
        h2o_headers_register(ctx->pathconf, self->cmds->entries);
    } else {
        free(self->cmds->entries);
        memset(self->cmds, 0, sizeof(*self->cmds));
    }

    --self->cmds;
    return 0;
}