blob: b24b47ffdfcabf1521fcc3157edf7fa306588a4d [file] [log] [blame]
Christopher Faulet47596d32018-10-22 09:17:28 +02001/*
2 * include/types/http_htx.h
3 * This file defines everything related to HTTP manipulation using the internal
4 * representation.
5 *
6 * Copyright (C) 2018 HAProxy Technologies, Christopher Faulet <cfaulet@haproxy.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation, version 2.1
11 * exclusively.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef _TYPES_HTTP_HTX_H
24#define _TYPES_HTTP_HTX_H
25
Christopher Faulet58857752020-01-15 15:19:50 +010026#include <ebistree.h>
27
28#include <common/buf.h>
Christopher Faulet35cd81d2020-01-15 11:22:56 +010029#include <common/http.h>
Willy Tarreaub96b77e2018-12-11 10:22:41 +010030#include <common/htx.h>
Christopher Faulet47596d32018-10-22 09:17:28 +020031#include <common/ist.h>
Christopher Faulet47596d32018-10-22 09:17:28 +020032
33/* Context used to find/remove an HTTP header. */
34struct http_hdr_ctx {
35 struct htx_blk *blk;
36 struct ist value;
37 uint16_t lws_before;
38 uint16_t lws_after;
39};
40
Christopher Faulet7bd3de02020-05-12 18:31:35 +020041
42/* Structure used to build the header list of an HTTP reply */
43struct http_reply_hdr {
44 struct ist name; /* the header name */
45 struct list value; /* the log-format string value */
46 struct list list; /* header chained list */
47};
48
49#define HTTP_REPLY_EMPTY 0x00 /* the reply has no payload */
50#define HTTP_REPLY_ERRMSG 0x01 /* the reply is an error message */
51#define HTTP_REPLY_ERRFILES 0x02 /* the reply references an http-errors section */
52#define HTTP_REPLY_RAW 0x03 /* the reply use a raw payload */
53#define HTTP_REPLY_LOGFMT 0x04 /* the reply use a log-format payload */
54
55/* Uses by HAProxy to generate internal responses */
56struct http_reply {
57 unsigned char type; /* HTTP_REPLY_* */
58 int status; /* The response status code */
59 char *ctype; /* The response content-type, may be NULL */
60 struct list hdrs; /* A list of http_reply_hdr */
61 union {
62 struct list fmt; /* A log-format string (type = HTTP_REPLY_LOGFMT) */
63 struct buffer obj; /* A raw string (type = HTTP_REPLY_RAW) */
64 struct buffer *errmsg; /* The error message to use as response (type = HTTP_REPLY_ERRMSG).
65 * may be NULL, if so rely on the proxy error messages */
66 char *http_errors; /* The http-errors section to use (type = HTTP_REPLY_ERRFILES).
67 * Should be resolved during post-check */
68 } body;
69};
70
Christopher Faulet58857752020-01-15 15:19:50 +010071/* A custom HTTP error message load from a row file and converted in HTX. The
72 * node key is the file path.
73 */
Christopher Fauletb6ea17c2020-05-13 21:45:22 +020074struct http_error_msg {
Christopher Faulet58857752020-01-15 15:19:50 +010075 struct buffer msg;
76 struct ebpt_node node;
77};
78
Christopher Faulet35cd81d2020-01-15 11:22:56 +010079/* http-errors section and parameters. */
80struct http_errors {
81 char *id; /* unique identifier */
82 struct {
83 char *file; /* file where the section appears */
84 int line; /* line where the section appears */
85 } conf; /* config information */
86
87 struct buffer *errmsg[HTTP_ERR_SIZE]; /* customized error messages for known errors */
88 struct list list; /* http-errors list */
89};
90
Christopher Faulet47596d32018-10-22 09:17:28 +020091#endif /* _TYPES_HTTP_HTX_H */