Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions example/append-transform/append-transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

Expand Down
11 changes: 4 additions & 7 deletions example/bnull-transform/bnull-transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 4 additions & 7 deletions example/null-transform/null-transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
44 changes: 22 additions & 22 deletions example/thread-pool/psi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 14 additions & 15 deletions plugins/gzip/gzip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down