/src/trafficserver/include/proxy/http/HttpTransactHeaders.h
Line | Count | Source |
1 | | /** @file |
2 | | |
3 | | A brief file description |
4 | | |
5 | | @section license License |
6 | | |
7 | | Licensed to the Apache Software Foundation (ASF) under one |
8 | | or more contributor license agreements. See the NOTICE file |
9 | | distributed with this work for additional information |
10 | | regarding copyright ownership. The ASF licenses this file |
11 | | to you under the Apache License, Version 2.0 (the |
12 | | "License"); you may not use this file except in compliance |
13 | | with the License. You may obtain a copy of the License at |
14 | | |
15 | | http://www.apache.org/licenses/LICENSE-2.0 |
16 | | |
17 | | Unless required by applicable law or agreed to in writing, software |
18 | | distributed under the License is distributed on an "AS IS" BASIS, |
19 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
20 | | See the License for the specific language governing permissions and |
21 | | limitations under the License. |
22 | | */ |
23 | | |
24 | | #pragma once |
25 | | |
26 | | #include "proxy/http/HttpTransact.h" |
27 | | |
28 | 0 | #define ink_time_t time_t |
29 | | |
30 | | extern int nstrhex(char *d, unsigned int i); |
31 | | |
32 | | class HttpTransactHeaders |
33 | | { |
34 | | public: |
35 | | static bool is_this_http_method_supported(int method); |
36 | | static bool is_method_cacheable(const OverridableHttpConfigParams *http_config_param, const int method); |
37 | | static bool is_method_cache_lookupable(int method); |
38 | | static bool is_this_a_hop_by_hop_header(const char *field_name_wks); |
39 | | static bool is_this_method_supported(int the_scheme, int the_method); |
40 | | |
41 | | static void insert_supported_methods_in_response(HTTPHdr *response, int the_scheme); |
42 | | |
43 | | static void build_base_response(HTTPHdr *outgoing_response, HTTPStatus status, const char *reason_phrase, int reason_phrase_len, |
44 | | ink_time_t date); |
45 | | |
46 | | static void copy_header_fields(HTTPHdr *src_hdr, HTTPHdr *new_hdr, bool retain_proxy_auth_hdrs, ink_time_t date = 0); |
47 | | |
48 | | static void convert_request(HTTPVersion outgoing_ver, HTTPHdr *outgoing_request); |
49 | | static void convert_response(HTTPVersion outgoing_ver, HTTPHdr *outgoing_response, char const *reason_phrase = nullptr); |
50 | | static void convert_to_1_0_request_header(HTTPHdr *outgoing_request); |
51 | | static void convert_to_1_1_request_header(HTTPHdr *outgoing_request); |
52 | | static void convert_to_1_0_response_header(HTTPHdr *outgoing_response, char const *reason_phrase = nullptr); |
53 | | static void convert_to_1_1_response_header(HTTPHdr *outgoing_response, char const *reason_phrase = nullptr); |
54 | | |
55 | | static bool does_server_allow_response_to_be_stored(HTTPHdr *resp, bool does_server_allow_response_to_be_stored); |
56 | | static bool downgrade_request(bool *origin_server_keep_alive, HTTPHdr *outgoing_request); |
57 | | static bool is_method_safe(int method); |
58 | | static bool is_method_idempotent(int method); |
59 | | static bool is_status_an_error_response(HTTPStatus response_code); |
60 | | |
61 | | static void generate_and_set_squid_codes(HTTPHdr *header, char *via_string, HttpTransact::SquidLogInfo *squid_codes); |
62 | | |
63 | | enum class ProtocolStackDetail { Compact, Standard, Full }; |
64 | | |
65 | | static int write_hdr_protocol_stack(char *hdr_string, size_t len, ProtocolStackDetail pSDetail, std::string_view *proto_buf, |
66 | | int n_proto, char separator = ' '); |
67 | | |
68 | | static void insert_warning_header(HttpConfigParams *http_config_param, HTTPHdr *header, HTTPWarningCode code, |
69 | | const char *warn_text = nullptr, int warn_text_len = 0); |
70 | | static void insert_time_and_age_headers_in_response(ink_time_t request_sent_time, ink_time_t response_received_time, |
71 | | ink_time_t now, HTTPHdr *base, HTTPHdr *outgoing); |
72 | | static void insert_via_header_in_request(HttpTransact::State *s, HTTPHdr *header); |
73 | | static void insert_via_header_in_response(HttpTransact::State *s, HTTPHdr *header); |
74 | | static void insert_hsts_header_in_response(HttpTransact::State *s, HTTPHdr *header); |
75 | | |
76 | | static void add_forwarded_field_to_request(HttpTransact::State *s, HTTPHdr *request); |
77 | | |
78 | | static bool is_request_proxy_authorized(HTTPHdr *incoming_hdr); |
79 | | |
80 | | static void normalize_accept_encoding(const OverridableHttpConfigParams *ohcp, HTTPHdr *header); |
81 | | |
82 | | static void remove_conditional_headers(HTTPHdr *outgoing); |
83 | | static void remove_100_continue_headers(HttpTransact::State *s, HTTPHdr *outgoing); |
84 | | static void remove_host_name_from_url(HTTPHdr *outgoing_request); |
85 | | static void add_global_user_agent_header_to_request(const OverridableHttpConfigParams *http_txn_conf, HTTPHdr *header); |
86 | | static void add_server_header_to_response(const OverridableHttpConfigParams *http_txn_conf, HTTPHdr *header); |
87 | | static void remove_privacy_headers_from_request(HttpConfigParams *http_config_param, |
88 | | const OverridableHttpConfigParams *http_txn_conf, HTTPHdr *header); |
89 | | static void add_connection_close(HTTPHdr *header); |
90 | | |
91 | | static int nstrcpy(char *d, const char *as); |
92 | | }; |
93 | | |
94 | | /***************************************************************************** |
95 | | ***************************************************************************** |
96 | | **** **** |
97 | | **** Inline Utility Routines **** |
98 | | **** **** |
99 | | ***************************************************************************** |
100 | | *****************************************************************************/ |
101 | | inline bool |
102 | | HttpTransactHeaders::is_this_http_method_supported(int method) |
103 | 0 | { |
104 | 0 | return ((method == HTTP_WKSIDX_GET) || (method == HTTP_WKSIDX_POST) || (method == HTTP_WKSIDX_CONNECT) || |
105 | 0 | (method == HTTP_WKSIDX_DELETE) || (method == HTTP_WKSIDX_PURGE) || (method == HTTP_WKSIDX_HEAD) || |
106 | 0 | (method == HTTP_WKSIDX_OPTIONS) || (method == HTTP_WKSIDX_PUT) || (method == HTTP_WKSIDX_PUSH) || |
107 | 0 | (method == HTTP_WKSIDX_TRACE)); |
108 | 0 | } |
109 | | |
110 | | inline int |
111 | | HttpTransactHeaders::nstrcpy(char *d, const char *as) |
112 | 0 | { |
113 | 0 | const char *s = as; |
114 | 0 | while (*s) |
115 | 0 | *d++ = *s++; |
116 | 0 | return s - as; |
117 | 0 | } |
118 | | |
119 | | /////////////////////////////////////////////////////////////////////////////// |
120 | | // Name : is_request_proxy_authorized |
121 | | // Description: does request authorization meet our authentication requirement |
122 | | // |
123 | | // Input : |
124 | | // Output : |
125 | | // |
126 | | // Details : |
127 | | // Currently a place holder. |
128 | | inline bool |
129 | | HttpTransactHeaders::is_request_proxy_authorized(HTTPHdr *incoming_hdr) |
130 | 0 | { |
131 | 0 | ink_assert(incoming_hdr); |
132 | | // TODO: What do we need to do here? |
133 | 0 | return true; |
134 | 0 | } |