If client request has both of Range and Accept-Encoding header, follow range-request config. */
| 85 | If client request has both of Range and Accept-Encoding header, follow range-request config. |
| 86 | */ |
| 87 | void |
| 88 | handle_range_request(TSMBuffer req_buf, TSMLoc req_loc, HostConfiguration *hc) |
| 89 | { |
| 90 | TSMLoc accept_encoding_hdr_field = |
| 91 | TSMimeHdrFieldFind(req_buf, req_loc, TS_MIME_FIELD_ACCEPT_ENCODING, TS_MIME_LEN_ACCEPT_ENCODING); |
| 92 | ts::PostScript accept_encoding_defer([&]() -> void { TSHandleMLocRelease(req_buf, req_loc, accept_encoding_hdr_field); }); |
| 93 | if (accept_encoding_hdr_field == TS_NULL_MLOC) { |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | TSMLoc range_hdr_field = TSMimeHdrFieldFind(req_buf, req_loc, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE); |
| 98 | ts::PostScript range_defer([&]() -> void { TSHandleMLocRelease(req_buf, req_loc, range_hdr_field); }); |
| 99 | if (range_hdr_field == TS_NULL_MLOC) { |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | debug("Both of Accept-Encoding and Range header are found in the request"); |
| 104 | |
| 105 | switch (hc->range_request_ctl()) { |
| 106 | case RangeRequestCtrl::REMOVE_RANGE: { |
| 107 | debug("Remove the Range header by remove-range config"); |
| 108 | while (range_hdr_field) { |
| 109 | TSMLoc next_dup = TSMimeHdrFieldNextDup(req_buf, req_loc, range_hdr_field); |
| 110 | TSMimeHdrFieldDestroy(req_buf, req_loc, range_hdr_field); |
| 111 | TSHandleMLocRelease(req_buf, req_loc, range_hdr_field); |
| 112 | range_hdr_field = next_dup; |
| 113 | } |
| 114 | break; |
| 115 | } |
| 116 | case RangeRequestCtrl::REMOVE_ACCEPT_ENCODING: { |
| 117 | debug("Remove the Accept-Encoding header by remove-accept-encoding config"); |
| 118 | while (accept_encoding_hdr_field) { |
| 119 | TSMLoc next_dup = TSMimeHdrFieldNextDup(req_buf, req_loc, accept_encoding_hdr_field); |
| 120 | TSMimeHdrFieldDestroy(req_buf, req_loc, accept_encoding_hdr_field); |
| 121 | TSHandleMLocRelease(req_buf, req_loc, accept_encoding_hdr_field); |
| 122 | accept_encoding_hdr_field = next_dup; |
| 123 | } |
| 124 | break; |
| 125 | } |
| 126 | case RangeRequestCtrl::NO_COMPRESSION: |
| 127 | // Do NOT touch header - this config is referred by `transformable()` function |
| 128 | debug("no header modification by no-compression config"); |
| 129 | break; |
| 130 | case RangeRequestCtrl::NONE: |
| 131 | [[fallthrough]]; |
| 132 | default: |
| 133 | debug("Do nothing by none config"); |
| 134 | break; |
| 135 | } |
| 136 | } |
| 137 | } // namespace |
| 138 | |
| 139 | static Data * |
no test coverage detected