------------------------------------------------------------------------- transformable Determine if the current transaction should be transformed or not Input: txnp current transaction Output : Return Value: 1 if transformable 0 if not -------------------------------------------------------------------------*/
| 851 | 0 if not |
| 852 | -------------------------------------------------------------------------*/ |
| 853 | static int |
| 854 | transformable(TSHttpTxn txnp) |
| 855 | { |
| 856 | /* We are only interested in transforming "200 OK" responses |
| 857 | with a Content-Type: text/ header and with X-Psi header */ |
| 858 | TSMBuffer bufp; |
| 859 | TSMLoc hdr_loc; |
| 860 | TSHttpStatus resp_status; |
| 861 | |
| 862 | if (TS_SUCCESS == TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc)) { |
| 863 | resp_status = TSHttpHdrStatusGet(bufp, hdr_loc); |
| 864 | if (resp_status != TS_HTTP_STATUS_OK) { |
| 865 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 866 | return 0; |
| 867 | } |
| 868 | |
| 869 | TSMLoc field_loc; |
| 870 | field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, TS_MIME_FIELD_CONTENT_TYPE, -1); |
| 871 | if (field_loc == TS_NULL_MLOC) { |
| 872 | TSError("[%s] Unable to search Content-Type field", PLUGIN_NAME); |
| 873 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | const char *value = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, -1, nullptr); |
| 878 | if ((value == nullptr) || (strncasecmp(value, "text/", sizeof("text/") - 1) != 0)) { |
| 879 | TSHandleMLocRelease(bufp, hdr_loc, field_loc); |
| 880 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 881 | return 0; |
| 882 | } |
| 883 | |
| 884 | TSHandleMLocRelease(bufp, hdr_loc, field_loc); |
| 885 | |
| 886 | field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, MIME_FIELD_XPSI, -1); |
| 887 | |
| 888 | TSHandleMLocRelease(bufp, hdr_loc, field_loc); |
| 889 | TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); |
| 890 | } |
| 891 | |
| 892 | return 1; |
| 893 | } |
| 894 | |
| 895 | /*------------------------------------------------------------------------- |
| 896 | transform_add |
no test coverage detected