| 221 | } |
| 222 | |
| 223 | static TSReturnCode |
| 224 | content_encoding_header(TSMBuffer bufp, TSMLoc hdr_loc, const int compression_type, int algorithm) |
| 225 | { |
| 226 | TSReturnCode ret; |
| 227 | TSMLoc ce_loc; |
| 228 | const char *value = nullptr; |
| 229 | int value_len = 0; |
| 230 | // Delete Content-Encoding if present??? |
| 231 | if (compression_type & COMPRESSION_TYPE_BROTLI && (algorithm & ALGORITHM_BROTLI)) { |
| 232 | value = TS_HTTP_VALUE_BROTLI; |
| 233 | value_len = TS_HTTP_LEN_BROTLI; |
| 234 | } else if (compression_type & COMPRESSION_TYPE_GZIP && (algorithm & ALGORITHM_GZIP)) { |
| 235 | value = TS_HTTP_VALUE_GZIP; |
| 236 | value_len = TS_HTTP_LEN_GZIP; |
| 237 | } else if (compression_type & COMPRESSION_TYPE_DEFLATE && (algorithm & ALGORITHM_DEFLATE)) { |
| 238 | value = TS_HTTP_VALUE_DEFLATE; |
| 239 | value_len = TS_HTTP_LEN_DEFLATE; |
| 240 | } |
| 241 | |
| 242 | if (value_len == 0) { |
| 243 | error("no need to add Content-Encoding header"); |
| 244 | return TS_SUCCESS; |
| 245 | } |
| 246 | |
| 247 | if ((ret = TSMimeHdrFieldCreateNamed(bufp, hdr_loc, TS_MIME_FIELD_CONTENT_ENCODING, TS_MIME_LEN_CONTENT_ENCODING, &ce_loc)) == |
| 248 | TS_SUCCESS) { |
| 249 | ret = TSMimeHdrFieldValueStringInsert(bufp, hdr_loc, ce_loc, -1, value, value_len); |
| 250 | if (ret == TS_SUCCESS) { |
| 251 | ret = TSMimeHdrFieldAppend(bufp, hdr_loc, ce_loc); |
| 252 | } |
| 253 | TSHandleMLocRelease(bufp, hdr_loc, ce_loc); |
| 254 | } |
| 255 | |
| 256 | if (ret != TS_SUCCESS) { |
| 257 | error("cannot add the Content-Encoding header"); |
| 258 | } |
| 259 | |
| 260 | return ret; |
| 261 | } |
| 262 | |
| 263 | static TSReturnCode |
| 264 | vary_header(TSMBuffer bufp, TSMLoc hdr_loc) |
no test coverage detected