Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_http_response.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
41
42#ifndef __NILOREA_HTTP_RESPONSE_HEADER
43#define __NILOREA_HTTP_RESPONSE_HEADER
44
45#ifdef __cplusplus
46extern "C" {
47#endif
48
53
54#include "nilorea/n_str.h"
55
56#include <stddef.h>
57#include <sys/types.h>
58
60#define N_HTTP_RESPONSE_HEADERS_MAX 64
62#define N_HTTP_RESPONSE_VALUE_MAX 8192
63
66typedef ssize_t (*n_http_write_fn)(void* ctx, const void* buf, size_t len);
67
93
98const char* n_http_status_reason(int status);
99
104
108
113int n_http_response_set_status(N_HTTP_RESP* r, int status);
114
126int n_http_response_add_header(N_HTTP_RESP* r, const char* name, const char* value);
127
134int n_http_response_set_header(N_HTTP_RESP* r, const char* name, const char* value);
135
140size_t n_http_response_remove_header(N_HTTP_RESP* r, const char* name);
141
146const char* n_http_response_get_header(const N_HTTP_RESP* r, const char* name);
147
153int n_http_response_append(N_HTTP_RESP* r, const void* data, size_t len);
154
162int n_http_response_file(N_HTTP_RESP* r, int fd, long long offset, long long length);
163
170int n_http_response_set_connection(N_HTTP_RESP* r, int keep_alive, int version_minor, int head_only);
171
175long long n_http_response_body_length(const N_HTTP_RESP* r);
176
181int n_http_response_head(const N_HTTP_RESP* r, N_STR** out);
182
191int n_http_response_write(const N_HTTP_RESP* r, n_http_write_fn fn, void* ctx);
192
199
212N_HTTP_RANGE n_http_parse_range(const char* value, size_t len, long long total, long long* first, long long* last);
213
217
218#ifdef __cplusplus
219}
220#endif
221
222#endif /* __NILOREA_HTTP_RESPONSE_HEADER */
static N_GUI_MOUSE_EVENT last
the last event the widget was told of, and how many
int version_minor
HTTP/1.x minor version of the request (0 or 1).
long long fd_length
file body length
int status
status code, 100..599
int fd
file body descriptor (owned, closed on free), or -1
size_t nb_headers
number of headers
char * names[64]
header names, nb_headers of them
long long fd_offset
file body start offset
int head_only
non-zero: send headers only (HEAD request)
char * values[64]
header values
N_STR * body
memory body, or NULL
int keep_alive
non-zero: the connection stays open after this response
N_HTTP_RANGE n_http_parse_range(const char *value, size_t len, long long total, long long *first, long long *last)
interpret a Range header for a body of total bytes
#define N_HTTP_RESPONSE_HEADERS_MAX
most headers a response may carry
int n_http_response_append(N_HTTP_RESP *r, const void *data, size_t len)
append bytes to the memory body (drops a file body)
const char * n_http_status_reason(int status)
reason phrase of a status code ("Not Found"); a generic class phrase for an unlisted code,...
int n_http_response_head(const N_HTTP_RESP *r, N_STR **out)
append the status line and headers, through the blank line
int n_http_response_set_header(N_HTTP_RESP *r, const char *name, const char *value)
set a header: remove every header of that name (ASCII case-insensitive), then add it; same refusals a...
ssize_t(* n_http_write_fn)(void *ctx, const void *buf, size_t len)
a write function: write up to len bytes, return how many were written (at least 1) or -1 on a fatal e...
int n_http_response_add_header(N_HTTP_RESP *r, const char *name, const char *value)
add a header line (repeats allowed, e.g.
int n_http_response_file(N_HTTP_RESP *r, int fd, long long offset, long long length)
use a file range as the body; the response owns fd from now on (it is closed on free,...
int n_http_response_set_status(N_HTTP_RESP *r, int status)
change the status code
long long n_http_response_body_length(const N_HTTP_RESP *r)
body length the response declares (Content-Length), 0 for a bodiless status
size_t n_http_response_remove_header(N_HTTP_RESP *r, const char *name)
remove every header of that name (ASCII case-insensitive)
N_HTTP_RANGE
result of n_http_parse_range()
int n_http_response_write(const N_HTTP_RESP *r, n_http_write_fn fn, void *ctx)
write the whole response (head, then body unless HEAD or bodiless)
int n_http_response_set_connection(N_HTTP_RESP *r, int keep_alive, int version_minor, int head_only)
connection handling for this response
void n_http_response_free(N_HTTP_RESP **r)
free a response (closing its file body) and set *r to NULL
const char * n_http_response_get_header(const N_HTTP_RESP *r, const char *name)
value of the first header of that name (ASCII case-insensitive)
N_HTTP_RESP * n_http_response_new(int status)
new response with a status, keep-alive off, HTTP/1.1
@ N_HTTP_RANGE_NONE
no usable Range: send the whole body (200)
@ N_HTTP_RANGE_UNSATISFIABLE
send 416, with a Content-Range that gives only the total
@ N_HTTP_RANGE_OK
one satisfiable range: send 206
a response under construction (fields are private, use the functions)
A box including a string and his lenght.
Definition n_str.h:61
N_STR and string function declaration.