Coverage Report

Created: 2025-07-12 06:34

/src/h2o/lib/handler/server_timing.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2018 Fastly, Ichito Nagata
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 <assert.h>
23
#include <inttypes.h>
24
#include <stdio.h>
25
#include <stdlib.h>
26
#include "h2o.h"
27
28
struct st_server_timing_filter_t {
29
    h2o_filter_t super;
30
    unsigned enforce : 1;
31
};
32
33
static void on_setup_ostream(h2o_filter_t *_self, h2o_req_t *req, h2o_ostream_t **slot)
34
0
{
35
0
    struct st_server_timing_filter_t *self = (struct st_server_timing_filter_t *)_self;
36
37
    /* indicate the protocol handler to emit server timing header (basic and proxy properties) */
38
0
    req->send_server_timing = H2O_SEND_SERVER_TIMING_BASIC | H2O_SEND_SERVER_TIMING_PROXY;
39
40
    /* force chunked encoding for HTTP/1.1 if enforce flag is set */
41
0
    if (0x101 <= req->version && req->version < 0x200 && self->enforce)
42
0
        req->res.content_length = SIZE_MAX;
43
44
0
    h2o_setup_next_ostream(req, slot);
45
0
}
46
47
void h2o_server_timing_register(h2o_pathconf_t *pathconf, int enforce)
48
0
{
49
0
    struct st_server_timing_filter_t *self = (struct st_server_timing_filter_t *)h2o_create_filter(pathconf, sizeof(*self));
50
0
    self->super.on_setup_ostream = on_setup_ostream;
51
0
    self->enforce = enforce;
52
0
}