Allows a plugin to intercept an HTTP request sent to an origin server and to serve the content in place of the origin server.
INKReturnCode INKHttpTxnServerIntercept (INKCont
contp
, INKHttpTxn
txnp
)
INKCont
is the
continuation that is called to accept the connection.contp
INKHttpTxn
is the
current HTTP transaction the plugin wants to intercept.txnp
Enables a plugin to intercept an HTTP request sent to an origin server, and then serve the content in place of the origin server. The origin server is not contacted.
This API should be used in the
INK_HTTP_READ_REQUEST_HDR_HOOK
hook.
Once INKHttpTxnServerIntercept
has
been 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 *
data
passed to the handler of the continuation
is a data of type
contp
NetVConnection
representing the connection.
Once the vconnection is established, you can use regular
vconnection operations (INKVConnRead
,
INKVConnWrite
, etc...).
A typical scenario when using
INKHttpTxnServerIntercept
is:
Call INKHttpTxnServerIntercept
from hook INK_HTTP_READ_REQUEST_HDR_HOOK
.
Get called back on the continuation's handler passed
as argument to
INKHttpTxnServerIntercept
.
Get the VC from argument void
*
.data
Use INKVConnRead
to get the HTTP
header. Note that you will not receive an event
INK_VCONN_READ_COMPLETE
- you will only receive the event
INK_VCONN_READ_READY
because the number of
characters to read is unknown. You should rely on
INKTHttpParser
to parse the request and
return a status INK_PARSE_DONE
when the 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 | |
---|---|
The request and response go through the Traffic Server
HTTP SM. The request and response can be cached; 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.