Home

Traffic Server Software Developers Kit

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 INKHttpTxnClientIPGet, INKHttpHdrUrlGet, and INKUrlHostGet.

INKUrlHostGet.
static void
handle_dns (INKHttpTxn txnp, INKCont contp)
{
     INKMBuffer bufp;
     INKMLoc hdr_loc;
     INKMLoc url_loc;
     const char *host;
     int i;

     if (!INKHttpTxnClientIPGet (txnp, &bufp, &hdr_loc)) {
          INKError ("couldn't retrieve client request header\n");
          goto done;
     }

     url_loc = INKHttpHdrUrlGet (bufp, hdr_loc);

     if (!url_loc) {
          INKError ("couldn't retrieve request url\n");
          INKHandleMLocRelease (bufp, INK_NULL_MLOC, hdr_loc);
          goto done;
     }

     host = INKUrlHostGet (bufp, url_loc, NULL);
     if (!host) {
          INKError ("couldn't retrieve request hostname\n");
          INKHandleMLocRelease (bufp, hdr_loc, url_loc);
          INKHandleMLocRelease (bufp, INK_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 Release Marshal Buffer Handles for guidelines on using INKHandleMLocRelease and INKHandleStringRelease.