Coverage Report

Created: 2025-07-12 06:32

/src/h2o/lib/handler/configurator/headers.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2015 DeNA Co., Ltd., Kazuho Oku
3
 *
4
 * Permission is hereby granted, free of charge, to any person obtaining a copy
5
 * of this software and associated documentation files (the "Software"), to
6
 * deal in the Software without restriction, including without limitation the
7
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8
 * sell copies of the Software, and to permit persons to whom the Software is
9
 * furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in
12
 * all copies or substantial portions of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20
 * IN THE SOFTWARE.
21
 */
22
#include <string.h>
23
#include "h2o.h"
24
#include "h2o/configurator.h"
25
26
struct headers_configurator_t {
27
    h2o_configurator_t super;
28
    h2o_headers_command_t **cmds, *_cmd_stack[H2O_CONFIGURATOR_NUM_LEVELS + 1];
29
};
30
31
static int on_config_enter(h2o_configurator_t *_self, h2o_configurator_context_t *ctx, yoml_t *node)
32
0
{
33
0
    struct headers_configurator_t *self = (void *)_self;
34
35
0
    self->cmds[1] = self->cmds[0];
36
0
    if (self->cmds[1] != NULL)
37
0
        h2o_mem_addref_shared(self->cmds[1]);
38
39
0
    ++self->cmds;
40
0
    return 0;
41
0
}
42
43
static int on_config_exit(h2o_configurator_t *_self, h2o_configurator_context_t *ctx, yoml_t *node)
44
0
{
45
0
    struct headers_configurator_t *self = (void *)_self;
46
47
0
    if (ctx->pathconf != NULL && !h2o_configurator_at_extension_level(ctx) && *self->cmds != NULL) {
48
0
        if (*self->cmds != NULL)
49
0
            h2o_mem_addref_shared(*self->cmds);
50
0
        h2o_headers_register(ctx->pathconf, *self->cmds);
51
0
    }
52
53
0
    if (*self->cmds != NULL)
54
0
        h2o_mem_release_shared(*self->cmds);
55
0
    --self->cmds;
56
0
    return 0;
57
0
}
58
59
static h2o_headers_command_t **get_headers_commands(h2o_configurator_t *_self)
60
0
{
61
0
    struct headers_configurator_t *self = (void *)_self;
62
0
    return self->cmds;
63
0
}
64
65
void h2o_headers_register_configurator(h2o_globalconf_t *conf)
66
0
{
67
0
    struct headers_configurator_t *c = (void *)h2o_configurator_create(conf, sizeof(*c));
68
69
0
    c->super.enter = on_config_enter;
70
0
    c->super.exit = on_config_exit;
71
72
0
    h2o_configurator_define_headers_commands(conf, &c->super, "header", get_headers_commands);
73
0
    c->cmds = c->_cmd_stack;
74
0
}