Christopher Faulet | 47596d3 | 2018-10-22 09:17:28 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
Willy Tarreau | 8d2b777 | 2020-05-27 10:58:19 +0200 | [diff] [blame] | 26 | #include <import/ebistree.h> |
Christopher Faulet | 5885775 | 2020-01-15 15:19:50 +0100 | [diff] [blame] | 27 | |
Willy Tarreau | 8dabda7 | 2020-05-27 17:22:10 +0200 | [diff] [blame] | 28 | #include <haproxy/buf-t.h> |
Christopher Faulet | 35cd81d | 2020-01-15 11:22:56 +0100 | [diff] [blame] | 29 | #include <common/http.h> |
Willy Tarreau | b96b77e | 2018-12-11 10:22:41 +0100 | [diff] [blame] | 30 | #include <common/htx.h> |
Willy Tarreau | eb6f701 | 2020-05-27 16:21:26 +0200 | [diff] [blame] | 31 | #include <import/ist.h> |
Christopher Faulet | 47596d3 | 2018-10-22 09:17:28 +0200 | [diff] [blame] | 32 | |
| 33 | /* Context used to find/remove an HTTP header. */ |
| 34 | struct 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 Faulet | 7bd3de0 | 2020-05-12 18:31:35 +0200 | [diff] [blame] | 41 | |
| 42 | /* Structure used to build the header list of an HTTP reply */ |
| 43 | struct 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 */ |
Christopher Faulet | e29a97e | 2020-05-14 14:49:25 +0200 | [diff] [blame] | 50 | #define HTTP_REPLY_ERRMSG 0x01 /* the reply is an error message (may be NULL) */ |
Christopher Faulet | 7bd3de0 | 2020-05-12 18:31:35 +0200 | [diff] [blame] | 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 */ |
Christopher Faulet | e29a97e | 2020-05-14 14:49:25 +0200 | [diff] [blame] | 54 | #define HTTP_REPLY_INDIRECT 0x05 /* the reply references another http-reply (may be NULL) */ |
Christopher Faulet | 7bd3de0 | 2020-05-12 18:31:35 +0200 | [diff] [blame] | 55 | |
| 56 | /* Uses by HAProxy to generate internal responses */ |
| 57 | struct http_reply { |
| 58 | unsigned char type; /* HTTP_REPLY_* */ |
| 59 | int status; /* The response status code */ |
| 60 | char *ctype; /* The response content-type, may be NULL */ |
| 61 | struct list hdrs; /* A list of http_reply_hdr */ |
| 62 | union { |
| 63 | struct list fmt; /* A log-format string (type = HTTP_REPLY_LOGFMT) */ |
| 64 | struct buffer obj; /* A raw string (type = HTTP_REPLY_RAW) */ |
| 65 | struct buffer *errmsg; /* The error message to use as response (type = HTTP_REPLY_ERRMSG). |
| 66 | * may be NULL, if so rely on the proxy error messages */ |
Christopher Faulet | e29a97e | 2020-05-14 14:49:25 +0200 | [diff] [blame] | 67 | struct http_reply *reply; /* The HTTP reply to use as response (type = HTTP_REPLY_INDIRECT) */ |
| 68 | char *http_errors; /* The http-errors section to use (type = HTTP_REPLY_ERRFILES). |
Christopher Faulet | 7bd3de0 | 2020-05-12 18:31:35 +0200 | [diff] [blame] | 69 | * Should be resolved during post-check */ |
| 70 | } body; |
Christopher Faulet | 5809e10 | 2020-05-14 17:31:52 +0200 | [diff] [blame] | 71 | struct list list; /* next http_reply in the global list. |
| 72 | * Only used for replies defined in a proxy section */ |
Christopher Faulet | 7bd3de0 | 2020-05-12 18:31:35 +0200 | [diff] [blame] | 73 | }; |
| 74 | |
Christopher Faulet | 5885775 | 2020-01-15 15:19:50 +0100 | [diff] [blame] | 75 | /* A custom HTTP error message load from a row file and converted in HTX. The |
| 76 | * node key is the file path. |
| 77 | */ |
Christopher Faulet | b6ea17c | 2020-05-13 21:45:22 +0200 | [diff] [blame] | 78 | struct http_error_msg { |
Christopher Faulet | 5885775 | 2020-01-15 15:19:50 +0100 | [diff] [blame] | 79 | struct buffer msg; |
| 80 | struct ebpt_node node; |
| 81 | }; |
| 82 | |
Christopher Faulet | 35cd81d | 2020-01-15 11:22:56 +0100 | [diff] [blame] | 83 | /* http-errors section and parameters. */ |
| 84 | struct http_errors { |
| 85 | char *id; /* unique identifier */ |
| 86 | struct { |
| 87 | char *file; /* file where the section appears */ |
| 88 | int line; /* line where the section appears */ |
| 89 | } conf; /* config information */ |
| 90 | |
Christopher Faulet | de30bb7 | 2020-05-14 10:03:55 +0200 | [diff] [blame] | 91 | struct http_reply *replies[HTTP_ERR_SIZE]; /* HTTP replies for known errors */ |
Christopher Faulet | 35cd81d | 2020-01-15 11:22:56 +0100 | [diff] [blame] | 92 | struct list list; /* http-errors list */ |
| 93 | }; |
| 94 | |
Christopher Faulet | 47596d3 | 2018-10-22 09:17:28 +0200 | [diff] [blame] | 95 | #endif /* _TYPES_HTTP_HTX_H */ |