/////////////////////////////////////////////////////////////////// Copy all non hop-by-hop header fields from src_hdr to new_hdr. If header Date: is not present or invalid in src_hdr, then the given date will be used.
| 212 | // If header Date: is not present or invalid in src_hdr, |
| 213 | // then the given date will be used. |
| 214 | void |
| 215 | HttpTransactHeaders::copy_header_fields(HTTPHdr *src_hdr, HTTPHdr *new_hdr, bool retain_proxy_auth_hdrs, ink_time_t date) |
| 216 | { |
| 217 | ink_assert(src_hdr->valid()); |
| 218 | ink_assert(!new_hdr->valid()); |
| 219 | |
| 220 | bool date_hdr = false; |
| 221 | |
| 222 | // Start with an exact duplicate |
| 223 | new_hdr->copy(src_hdr); |
| 224 | |
| 225 | // Nuke hop-by-hop headers |
| 226 | // |
| 227 | // The hop-by-hop header fields are laid out by the spec |
| 228 | // with two adjustments |
| 229 | // 1) we treat TE as hop-by-hop because spec implies |
| 230 | // that it is by declaring anyone who sends a TE must |
| 231 | // include TE in the connection header. This in |
| 232 | // my opinion error prone and if the client doesn't follow the spec |
| 233 | // we'll have problems with the TE being forwarded to the server |
| 234 | // and us caching the transfer encoded documents and then |
| 235 | // serving it to a client that can not handle it. The exception |
| 236 | // to this is that we will allow "TE: trailers" to be forwarded |
| 237 | // because that is required for gRPC traffic. |
| 238 | // 2) Transfer encoding is copied. If the transfer encoding |
| 239 | // is changed for example by dechunking, the transfer encoding |
| 240 | // should be modified when the decision is made to dechunk it |
| 241 | |
| 242 | for (auto &field : *new_hdr) { |
| 243 | if (field.m_wks_idx == -1) { |
| 244 | continue; |
| 245 | } |
| 246 | |
| 247 | int field_flags = hdrtoken_index_to_flags(field.m_wks_idx); |
| 248 | |
| 249 | if (field_flags & HTIF_HOPBYHOP) { |
| 250 | std::string_view name(field.name_get()); |
| 251 | std::string_view value(field.value_get()); |
| 252 | bool const is_te_trailers = name == MIME_FIELD_TE && value == "trailers"; |
| 253 | if (is_te_trailers) { |
| 254 | // te: trailers is used by gRPC, do not delete it. |
| 255 | continue; |
| 256 | } |
| 257 | |
| 258 | // Delete header if not in special proxy_auth retention mode |
| 259 | if (retain_proxy_auth_hdrs && (field_flags & HTIF_PROXYAUTH)) { |
| 260 | continue; |
| 261 | } |
| 262 | new_hdr->field_delete(&field); |
| 263 | } else if (field.m_wks_idx == MIME_WKSIDX_DATE) { |
| 264 | date_hdr = true; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // Set date hdr if not already set and valid value passed in |
| 269 | if ((date_hdr == false) && (date > 0)) { |
| 270 | new_hdr->set_date(date); |
| 271 | } |
nothing calls this directly
no test coverage detected