Working with HTTP Header Functions¶
The Blacklist plugin examines the host header in every client
transaction. This is done in the handle_dns
routine, using
TSHttpTxnClientReqGet
, TSHttpHdrUrlGet
, and TSUrlHostGet
.
static void
handle_dns (TSHttpTxn txnp, TSCont contp)
{
TSMBuffer bufp;
TSMLoc hdr_loc;
TSMLoc url_loc;
const char *host;
int i;
int host_length;
if (TSHttpTxnClientReqGet(txnp, &bufp, &hdr_loc) != TS_SUCCESS) {
TSError("[blacklist] Couldn't retrieve client request header");
goto done;
}
if (TSHttpHdrUrlGet(bufp, hdr_loc, &url_loc) != TS_SUCCESS) {
TSError("[blacklist] Couldn't retrieve request url");
TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
goto done;
}
host = TSUrlHostGet(bufp, url_loc, &host_length);
if (!host) {
TSError("[blacklist] couldn't retrieve request hostname");
TSHandleMLocRelease(bufp, hdr_loc, url_loc);
TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
goto done;
}
To access the host header, the plugin must first get the client request,
retrieve the URL portion, and then obtain the host header. See
HTTP Headers for more information about these calls.
See Marshal Buffers
for guidelines on using TSHandleMLocRelease
.