diff --git a/example/append-transform/append-transform.c b/example/append-transform/append-transform.c index 87c9c600ff3..5ede8119a1e 100644 --- a/example/append-transform/append-transform.c +++ b/example/append-transform/append-transform.c @@ -249,31 +249,31 @@ transformable(TSHttpTxn txnp) const char *value; int val_length; - TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc); - - /* - * We are only interested in "200 OK" responses. - */ - - if (TS_HTTP_STATUS_OK == (resp_status = TSHttpHdrStatusGet(bufp, hdr_loc))) { - /* We only want to do the transformation on documents that have a - content type of "text/html". */ - field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, "Content-Type", 12); - if (!field_loc) { - ASSERT_SUCCESS(TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc)); - return 0; - } - - value = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, -1, &val_length); - if (value && (strncasecmp(value, "text/html", sizeof("text/html") - 1) == 0)) { - ASSERT_SUCCESS(TSHandleMLocRelease(bufp, hdr_loc, field_loc)); - ASSERT_SUCCESS(TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc)); - - return 1; - } else { - ASSERT_SUCCESS(TSHandleMLocRelease(bufp, hdr_loc, field_loc)); - ASSERT_SUCCESS(TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc)); - return 0; + if (TS_SUCCESS == TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc)) { + /* + * We are only interested in "200 OK" responses. + */ + + if (TS_HTTP_STATUS_OK == (resp_status = TSHttpHdrStatusGet(bufp, hdr_loc))) { + /* We only want to do the transformation on documents that have a + content type of "text/html". */ + field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, "Content-Type", 12); + if (!field_loc) { + ASSERT_SUCCESS(TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc)); + return 0; + } + + value = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, -1, &val_length); + if (value && (strncasecmp(value, "text/html", sizeof("text/html") - 1) == 0)) { + ASSERT_SUCCESS(TSHandleMLocRelease(bufp, hdr_loc, field_loc)); + ASSERT_SUCCESS(TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc)); + + return 1; + } else { + ASSERT_SUCCESS(TSHandleMLocRelease(bufp, hdr_loc, field_loc)); + ASSERT_SUCCESS(TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc)); + return 0; + } } } diff --git a/example/bnull-transform/bnull-transform.c b/example/bnull-transform/bnull-transform.c index e87d337d484..786eb8446c3 100644 --- a/example/bnull-transform/bnull-transform.c +++ b/example/bnull-transform/bnull-transform.c @@ -264,13 +264,10 @@ transformable(TSHttpTxn txnp) /* We are only interested in transforming "200 OK" responses. */ - TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc); - resp_status = TSHttpHdrStatusGet(bufp, hdr_loc); - retv = (resp_status == TS_HTTP_STATUS_OK); - - if (TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc) == TS_ERROR) { - TSError("[bnull-transform] Error releasing MLOC while checking " - "header status"); + if (TS_SUCCESS == TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc)) { + resp_status = TSHttpHdrStatusGet(bufp, hdr_loc); + retv = (resp_status == TS_HTTP_STATUS_OK); + TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); } return retv; diff --git a/example/null-transform/null-transform.c b/example/null-transform/null-transform.c index c8f101a2633..56cdfe92221 100644 --- a/example/null-transform/null-transform.c +++ b/example/null-transform/null-transform.c @@ -259,13 +259,10 @@ transformable(TSHttpTxn txnp) TSDebug("null-transform", "Entering transformable()"); - TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc); - resp_status = TSHttpHdrStatusGet(bufp, hdr_loc); - retv = (resp_status == TS_HTTP_STATUS_OK); - - if (TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc) == TS_ERROR) { - TSError("[null-transform] Error releasing MLOC while checking " - "header status"); + if (TS_SUCCESS == TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc)) { + resp_status = TSHttpHdrStatusGet(bufp, hdr_loc); + retv = (resp_status == TS_HTTP_STATUS_OK); + TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); } TSDebug("null-transform", "Exiting transformable with return %d", retv); diff --git a/example/thread-pool/psi.c b/example/thread-pool/psi.c index 142c1fce1cb..8fd93c910e0 100644 --- a/example/thread-pool/psi.c +++ b/example/thread-pool/psi.c @@ -887,34 +887,34 @@ transformable(TSHttpTxn txnp) TSHttpStatus resp_status; const char *value; - TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc); + if (TS_SUCCESS == TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc)) { + resp_status = TSHttpHdrStatusGet(bufp, hdr_loc); + if (resp_status != TS_HTTP_STATUS_OK) { + TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); + return 0; + } - resp_status = TSHttpHdrStatusGet(bufp, hdr_loc); - if (resp_status != TS_HTTP_STATUS_OK) { - TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); - return 0; - } + field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, TS_MIME_FIELD_CONTENT_TYPE, -1); + if (field_loc == TS_NULL_MLOC) { + TSError("[psi] Unable to search Content-Type field"); + TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); + return 0; + } - field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, TS_MIME_FIELD_CONTENT_TYPE, -1); - if (field_loc == TS_NULL_MLOC) { - TSError("[psi] Unable to search Content-Type field"); - TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); - return 0; - } + value = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, -1, NULL); + if ((value == NULL) || (strncasecmp(value, "text/", sizeof("text/") - 1) != 0)) { + TSHandleMLocRelease(bufp, hdr_loc, field_loc); + TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); + return 0; + } - value = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, -1, NULL); - if ((value == NULL) || (strncasecmp(value, "text/", sizeof("text/") - 1) != 0)) { TSHandleMLocRelease(bufp, hdr_loc, field_loc); - TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); - return 0; - } - TSHandleMLocRelease(bufp, hdr_loc, field_loc); + field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, MIME_FIELD_XPSI, -1); - field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, MIME_FIELD_XPSI, -1); - - TSHandleMLocRelease(bufp, hdr_loc, field_loc); - TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); + TSHandleMLocRelease(bufp, hdr_loc, field_loc); + TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); + } return 1; } diff --git a/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c b/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c index 84226022b05..341a7105387 100644 --- a/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c +++ b/plugins/experimental/stale_while_revalidate/stale_while_revalidate.c @@ -573,18 +573,18 @@ main_plugin(TSCont cont, TSEvent event, void *edata) } break; case TS_EVENT_HTTP_READ_RESPONSE_HDR: - TSHttpTxnServerRespGet(txn, &buf, &loc); - http_status = TSHttpHdrStatusGet(buf, loc); - if ((http_status == 500) || ((http_status >= 502) && (http_status <= 504))) // 500, 502, 503, or 504 - { - TSDebug(PLUGIN_NAME, "Set non-cachable"); + if (TS_SUCCESS == TSHttpTxnServerRespGet(txn, &buf, &loc)) { + http_status = TSHttpHdrStatusGet(buf, loc); + if ((http_status == 500) || ((http_status >= 502) && (http_status <= 504))) { // 500, 502, 503, or 504 + TSDebug(PLUGIN_NAME, "Set non-cachable"); #if (TS_VERSION_NUMBER >= 3003000) - TSHttpTxnServerRespNoStoreSet(txn, 1); + TSHttpTxnServerRespNoStoreSet(txn, 1); #else - TSHttpTxnServerRespNoStore(txn); + TSHttpTxnServerRespNoStore(txn); #endif + } + TSHandleMLocRelease(buf, TS_NULL_MLOC, loc); } - TSHandleMLocRelease(buf, TS_NULL_MLOC, loc); TSHttpTxnReenable(txn, TS_EVENT_HTTP_CONTINUE); break; case TS_EVENT_HTTP_SEND_RESPONSE_HDR: diff --git a/plugins/gzip/gzip.cc b/plugins/gzip/gzip.cc index 74aa1f8676b..2d345a63e91 100644 --- a/plugins/gzip/gzip.cc +++ b/plugins/gzip/gzip.cc @@ -472,21 +472,27 @@ gzip_transformable(TSHttpTxn txnp, bool server, HostConfiguration *host_configur TSHttpStatus resp_status; if (server) { - TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc); + if (TS_SUCCESS != TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc)) { + return 0; + } } else { - TSHttpTxnCachedRespGet(txnp, &bufp, &hdr_loc); + if (TS_SUCCESS != TSHttpTxnCachedRespGet(txnp, &bufp, &hdr_loc)) { + return 0; + } } + resp_status = TSHttpHdrStatusGet(bufp, hdr_loc); - TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); // conservatively pick some statusses to compress if (!(resp_status == 200 || resp_status == 404 || resp_status == 500)) { info("http response status [%d] is not compressible", resp_status); + TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); return 0; } if (TS_SUCCESS != TSHttpTxnClientReqGet(txnp, &cbuf, &chdr)) { info("cound not get client request"); + TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); return 0; } @@ -526,27 +532,17 @@ gzip_transformable(TSHttpTxn txnp, bool server, HostConfiguration *host_configur if (!compression_acceptable) { info("no acceptable encoding found in request header, not compressible"); + TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); return 0; } } else { info("no acceptable encoding found in request header, not compressible"); TSHandleMLocRelease(cbuf, chdr, cfield); TSHandleMLocRelease(cbuf, TS_NULL_MLOC, chdr); + TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); return 0; } - if (server) { - if (TS_SUCCESS != TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc)) { - info("could not get server response"); - return 0; - } - } else { - if (TS_SUCCESS != TSHttpTxnCachedRespGet(txnp, &bufp, &hdr_loc)) { - info("could not get cached response"); - return 0; - } - } - /* If there already exists a content encoding then we don't want to do anything. */ field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, TS_MIME_FIELD_CONTENT_ENCODING, -1); @@ -569,11 +565,14 @@ gzip_transformable(TSHttpTxn txnp, bool server, HostConfiguration *host_configur value = TSMimeHdrFieldValueStringGet(bufp, hdr_loc, field_loc, -1, &len); int rv = host_configuration->is_content_type_compressible(value, len); + if (!rv) { info("content-type [%.*s] not compressible", len, value); } + TSHandleMLocRelease(bufp, hdr_loc, field_loc); TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc); + return rv; }