| 800 | } |
| 801 | |
| 802 | static int |
| 803 | client_accepts_compression(TSHttpTxn txnp, bool server, HostConfiguration *host_configuration, int *compress_type, int *algorithms) |
| 804 | { |
| 805 | /* Server response header */ |
| 806 | TSMBuffer bufp; |
| 807 | TSMLoc hdr_loc; |
| 808 | |
| 809 | /* Client request header */ |
| 810 | TSMBuffer cbuf; |
| 811 | TSMLoc chdr; |
| 812 | TSMLoc cfield; |
| 813 | |
| 814 | const char *value; |
| 815 | int len; |
| 816 | |
| 817 | if (server) { |
| 818 | if (TS_SUCCESS != TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc)) { |
| 819 | return 0; |
| 820 | } |
| 821 | } else { |
| 822 | if (TS_SUCCESS != TSHttpTxnCachedRespGet(txnp, &bufp, &hdr_loc)) { |
| 823 | return 0; |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | if (TS_SUCCESS != TSHttpTxnClientReqGet(txnp, &cbuf, &chdr)) { |
| 828 | info("cound not get client request"); |
| 829 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | // check Partial Object is transformable |
| 834 | if (host_configuration->range_request_ctl() == RangeRequestCtrl::NO_COMPRESSION) { |
| 835 | // check Range header in client request |
| 836 | // CAVETE: some plugin (- e.g. cache_range_request) tweaks client headers |
| 837 | TSMLoc range_hdr_field = TSMimeHdrFieldFind(cbuf, chdr, TS_MIME_FIELD_RANGE, TS_MIME_LEN_RANGE); |
| 838 | if (range_hdr_field != TS_NULL_MLOC) { |
| 839 | debug("Range header found in the request and range_request is configured as no_compression"); |
| 840 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 841 | TSHandleMLocRelease(cbuf, chdr, range_hdr_field); |
| 842 | TSHandleMLocRelease(cbuf, TS_NULL_MLOC, chdr); |
| 843 | return 0; |
| 844 | } |
| 845 | |
| 846 | // check Content-Range header in (cached) server response |
| 847 | TSMLoc content_range_hdr_field = TSMimeHdrFieldFind(bufp, hdr_loc, TS_MIME_FIELD_CONTENT_RANGE, TS_MIME_LEN_CONTENT_RANGE); |
| 848 | if (content_range_hdr_field != TS_NULL_MLOC) { |
| 849 | debug("Content-Range header found in the response and range_request is configured as no_compression"); |
| 850 | TSHandleMLocRelease(bufp, hdr_loc, content_range_hdr_field); |
| 851 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 852 | TSHandleMLocRelease(cbuf, TS_NULL_MLOC, chdr); |
| 853 | return 0; |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | *algorithms = host_configuration->compression_algorithms(); |
| 858 | cfield = TSMimeHdrFieldFind(cbuf, chdr, TS_MIME_FIELD_ACCEPT_ENCODING, TS_MIME_LEN_ACCEPT_ENCODING); |
| 859 | if (cfield != TS_NULL_MLOC) { |
no test coverage detected