Uploaded image for project: 'Traffic Server'
  1. Traffic Server
  2. TS-2953

GET Host header in reverse proxy setup

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 4.2.1
    • None
    • Core, CPP API, Logging

    Description

      Hello, been trying this for 3 days, I think this is a bug. See bellow code, this has been tested on TS_HTTP_PRE_REMAP_HOOK and TS_HTTP_READ_REQUEST_HDR_HOOK. Also the example for blacklist, which uses the same thing, also fails.

      Same goes with getting the URL string, it will remove the hostname and leave the requested part, eg.

      http:///somefile.php

      (there are 3 slashes there).

      I've been using ATS for about 3 days (yes short time) and trying to make a plugin for it and I can't seem to get what I want ... I may be missing something, and if so, I apologize for taking your time to read this and if possible, kindly show me the right way to do this if possible.

      static void
      handle_request(TSHttpTxn txnp, TSCont contp) {
          TSMBuffer bufp; // TSMBuffer
          TSMLoc hdr_loc; // TSMLoc offset
          TSMLoc url_loc; // TSMLoc locp
          const char *host;
          int host_length;
      
          // getting client request
          errorCode = TSHttpTxnClientReqGet (txnp, &bufp, &hdr_loc);
          if (errorCode != TS_SUCCESS) {
              TSError ("couldn't retrieve client request header\n");
              goto done;
          } else {
              TSTextLogObjectWrite(logFile, "Reading client request...");
          }
      
          // getting client requested url
          errorCode = TSHttpHdrUrlGet (bufp, hdr_loc, &url_loc);
          if (errorCode != TS_SUCCESS) {
              TSError ("couldn't retrieve request url\n");
              TSHandleMLocRelease (bufp, TS_NULL_MLOC, hdr_loc);
              goto done;
          } else {
              TSTextLogObjectWrite(logFile, "Reading url_loc request...");
          }
      
          // getting  host
          host = TSUrlHostGet (bufp, url_loc, &host_length);
          TSTextLogObjectWrite(logFile, "Getting host header... %s", host);
          if (!host) {
              TSError ("couldn't retrieve request host header \n");
              TSHandleMLocRelease (bufp, hdr_loc, url_loc);
              TSHandleMLocRelease (bufp, TS_NULL_MLOC, hdr_loc);
              goto done;
          } else {
              TSTextLogObjectWrite(logFile, "Getting host header... %s", host);
          }
      
          done:
              TSTextLogObjectWrite(logFile, "Allowing http event to continue ...");
              TSHttpTxnReenable(txnp, TS_EVENT_HTTP_CONTINUE);
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            kaze Yemdjih Kaze Nasser
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: