Enables a plugin to intercept an HTTP client’s request and serve content in place of the origin server.
INKReturnCode INKHttpTxnIntercept (INKCont
contp
, INKHttpTxn
txnp
)
INKCont
is the
continuation called to accept the connection.contp
INKHttpTxn
is the
current HTTP transaction the plugin wants to intercept.txnp
Allows a plugin to intercept an HTTP client's request and
serve content in place of the origin server. The request
is intercepted immediately after it is read by Traffic Server; the
origin server is not contacted. This API should be used in the
INK_HTTP_READ_REQUEST_HDR_HOOK
hook.
Once INKHttpTxnIntercept
is
called, the handler of the continuation
receives an event
contp
INK_EVENT_NET_ACCEPT
. Note that the continuation
passed should not have a NULL
mutex; if it does, then an error is
returned. The void
passed to the handler of the continuation
*data
is a data of type
NetVConnection that represents the connection. Once a vconnection is established, the user can use regular
VConnection operations (contp
INKVConnRead
,
INKVConnWrite
, etc...).
A typical scenario for using INKHttpTxnIntercept
is as follows:
Call INKHttpTxnIntercept
from
hook INK_HTTP_READ_REQUEST_HDR_HOOK
.
Get called back on the continuation's handler that's passed
as an argument to
INKHttpTxnIntercept
.
Get the vconnection from the argument void
*
.data
Use INKVConnRead
to get the HTTP
request. Note that you will not receive the event
INK_VCONN_READ_COMPLETE
- you will only receive the
INK_VCONN_READ_READY
event because the number of
characters to be read is unknown. You should rely on
INKTHttpParser
to parse the request and
then return a status INK_PARSE_DONE
when request is
fully received (escape sequence \r\n\r\n
read).
Use INKHttpParser
to parse the
request.
Use INKVConnWrite
to write the
HTTP response.
Note | |
---|---|
Because the request and response do not go through the Traffic
Server HTTP state machine, neither is
cached by Traffic Server. The request is logged in
|
INK_SUCCESS
if the API is called
successfully.
INK_ERROR
if an error occurs while calling
the API or if an argument is invalid. This error is also
returned if the continuation passed has a NULL
mutex.