-
Notifications
You must be signed in to change notification settings - Fork 176
/
extra.c
150 lines (108 loc) · 3.47 KB
/
extra.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <stdlib.h>
#include "fixture.h"
int llhttp__on_url(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
return llparse__print_span("url", p, endp);
}
int llhttp__on_url_schema(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
return llparse__print_span("url.schema", p, endp);
}
int llhttp__on_url_host(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
return llparse__print_span("url.host", p, endp);
}
int llhttp__on_url_path(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
return llparse__print_span("url.path", p, endp);
}
int llhttp__on_url_query(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
return llparse__print_span("url.query", p, endp);
}
int llhttp__on_url_fragment(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
return llparse__print_span("url.fragment", p, endp);
}
#ifdef LLHTTP__TEST_HTTP
void llhttp__test_init_request(llparse_t* s) {
s->type = HTTP_REQUEST;
}
void llhttp__test_init_response(llparse_t* s) {
s->type = HTTP_RESPONSE;
}
void llhttp__test_init_request_lenient(llparse_t* s) {
llhttp__test_init_request(s);
s->flags |= F_LENIENT;
}
void llhttp__test_finish(llparse_t* s) {
llparse__print(NULL, NULL, "finish=%d", s->finish);
}
int llhttp__on_status(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
return llparse__print_span("status", p, endp);
}
int llhttp__on_header_field(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
return llparse__print_span("header_field", p, endp);
}
int llhttp__on_header_value(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
return llparse__print_span("header_value", p, endp);
}
int llhttp__on_headers_complete(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
if (s->type == HTTP_REQUEST) {
llparse__print(p, endp,
"headers complete method=%d v=%d/%d flags=%x content_length=%llu",
s->method, s->http_major, s->http_minor, s->flags, s->content_length);
} else if (s->type == HTTP_RESPONSE) {
llparse__print(p, endp,
"headers complete status=%d v=%d/%d flags=%x content_length=%llu",
s->status_code, s->http_major, s->http_minor, s->flags,
s->content_length);
} else {
llparse__print(p, endp, "invalid headers complete");
}
return 0;
}
int llhttp__on_message_begin(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
llparse__print(p, endp, "message begin");
return 0;
}
int llhttp__on_message_complete(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
llparse__print(p, endp, "message complete");
return 0;
}
int llhttp__on_body(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
return llparse__print_span("body", p, endp);
}
int llhttp__on_chunk_header(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
llparse__print(p, endp, "chunk header len=%d", (int) s->content_length);
return 0;
}
int llhttp__on_chunk_complete(llparse_t* s, const char* p, const char* endp) {
if (llparse__in_bench)
return 0;
llparse__print(p, endp, "chunk complete");
return 0;
}
#endif /* LLHTTP__TEST_HTTP */