Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_http_req.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
47
48#ifndef N_HTTP_REQ_H
49#define N_HTTP_REQ_H
50
51#include <stddef.h>
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
61
63#define N_HTTP_REQ_HEAD_MAX 16384u
65#define N_HTTP_REQ_PATH_MAX 2048u
67#define N_HTTP_REQ_HEADERS_MAX 64u
70#define N_HTTP_REQ_BODY_MAX (1024u * 1024u)
72#define N_HTTP_REQ_BODY_LIMIT_MAX (1024LL * 1024LL * 1024LL)
74#define N_HTTP_REQ_AUTH_MAX 256u
75
82
84#define N_HTTP_REQ_METHOD_BIT(m) (1u << (unsigned)(m))
85
89typedef struct {
90 size_t name_off;
91 size_t name_len;
92 size_t value_off;
93 size_t value_len;
95
97typedef struct {
100 unsigned methods;
102 long long body_max;
107
127
135
157n_http_req_status n_http_request_parse(const char* buf, size_t len, n_http_request* out);
158
174n_http_req_status n_http_request_parse_ex(const char* buf, size_t len, const n_http_req_limits* limits, n_http_request* out);
175
190const char* n_http_request_header(const n_http_request* req, const char* buf, const char* name, size_t* value_len);
191
203size_t n_http_request_header_count(const n_http_request* req, const char* buf, const char* name);
204
208
209#ifdef __cplusplus
210}
211#endif
212
213#endif /* N_HTTP_REQ_H */
int require_host
non-zero: an HTTP/1.1 request must carry exactly one Host header and an HTTP/1.0 one at most one (RFC...
Definition n_http_req.h:105
long long body_max
largest accepted Content-Length, 0 to N_HTTP_REQ_BODY_LIMIT_MAX
Definition n_http_req.h:102
char authorization[256u+1]
Definition n_http_req.h:122
unsigned methods
accepted methods, an OR of N_HTTP_REQ_METHOD_BIT(); any other method is an error
Definition n_http_req.h:100
char path[2048u+1]
Definition n_http_req.h:119
size_t nb_headers
Definition n_http_req.h:124
long long content_length
Definition n_http_req.h:120
n_http_req_method method
Definition n_http_req.h:118
n_http_req_header headers[64u]
Definition n_http_req.h:125
n_http_req_status n_http_request_parse_ex(const char *buf, size_t len, const n_http_req_limits *limits, n_http_request *out)
parse an HTTP/1.1 request head with caller-chosen limits
Definition n_http_req.c:110
n_http_req_status
Result of n_http_request_parse.
Definition n_http_req.h:130
const char * n_http_request_header(const n_http_request *req, const char *buf, const char *name, size_t *value_len)
find a header of a parsed request
Definition n_http_req.c:253
n_http_req_status n_http_request_parse(const char *buf, size_t len, n_http_request *out)
parse an HTTP/1.1 request head from [buf, buf+len)
Definition n_http_req.c:245
size_t n_http_request_header_count(const n_http_request *req, const char *buf, const char *name)
count the headers of a parsed request that carry a name
Definition n_http_req.c:271
#define N_HTTP_REQ_AUTH_MAX
Longest captured Authorization header value.
Definition n_http_req.h:74
n_http_req_method
The methods accepted.
Definition n_http_req.h:77
#define N_HTTP_REQ_HEADERS_MAX
Maximum number of header lines.
Definition n_http_req.h:67
#define N_HTTP_REQ_PATH_MAX
Longest origin-form request target ('/'-prefixed, query included).
Definition n_http_req.h:65
@ N_HTTP_REQ_INCOMPLETE
no CRLFCRLF yet, still under the cap
Definition n_http_req.h:132
@ N_HTTP_REQ_ERROR
malformed / oversized / unsupported
Definition n_http_req.h:133
@ N_HTTP_REQ_OK
a complete, valid head was parsed
Definition n_http_req.h:131
@ N_HTTP_REQ_POST
Definition n_http_req.h:79
@ N_HTTP_REQ_GET
Definition n_http_req.h:78
@ N_HTTP_REQ_HEAD
Definition n_http_req.h:80
One header line, as offsets into the parsed buffer: the name is [name_off, name_off + name_len),...
Definition n_http_req.h:89
Limits for n_http_request_parse_ex().
Definition n_http_req.h:97
A parsed request head.
Definition n_http_req.h:117