Triggered by a recent email exchange on this subject, and Watl's proposal
in this are, and  due to the fact that I was doing plugin work that also
needed that sort of API, I realized the current API is rather dismal in
this regard. I propose adding this function.

TSReturnCode TSHttpHdrEffectiveURLBuffGet(TSMBuffer hdr_buf, TSMLoc
hdr_loc, void * buff, int64_t size, int64_t* length)

This prints the effective URL for the header specified by :arg:`mbuf` and
:arg:`url_loc` to the buffer starting at :arg:`buff`. The amount of text
written is limited by the buffer :arg:`size`. The full length of the URL is
returned in :arg:`*length`. If this value is less than or equal to
:arg:`size` then all of the URL was printed. Otherwise it was clipped and
the buffer size increased to that value if all of the URL is needed.

The effective URL is the request header URL and, if the host is not
present, the "Host" field in the request. All case insensitive text is
rendered lowercase to make URL comparisons simple and fast.

The typical usage would be
TSMBuffer hdr_buff;
TSMLoc hdr_loc;
TSHttpTxnServerReqGet(txn, &hdr_buff, &hdr_loc);
int64_t length;
char store[2048];
char *buff = store;
TSHttpHdrEffectiveUrlBuffGet(hdr_buff, hdr_loc, buff, sizeof(store),
&length);
if (length > sizeof(store)) {
  buff = malloc(length);
  TSHttpHdrEffectiveUrlBuffGet(hdr_buff, hdr_loc, buff, length, &length);
}

Notes:

This differs from existing API in three ways,.

*  The memory is not allocated nor contained in the TS core, but provided
by the plugin. As noted in the example, a plugin can provide a reasonably
small buffer to handle the common case and allocate only for particularly
large URLs.

*  This works on any HTTP header, not just the client request header.

*  The resulting URL text is fully normalized in accordance with the HTTP
specification.

Reply via email to