TS-2855: add TSHttpIsInternalSession API Add TSHttpIsInternalSession API to be symmetric with TSHttpIsInternalRequest.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/52682da9 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/52682da9 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/52682da9 Branch: refs/heads/5.0.x Commit: 52682da919945fce6097d5fa50e024a6f7fb5da6 Parents: e7586df Author: James Peach <[email protected]> Authored: Wed May 28 16:51:46 2014 -0700 Committer: James Peach <[email protected]> Committed: Thu May 29 12:33:26 2014 -0700 ---------------------------------------------------------------------- CHANGES | 2 + .../api/TSHttpIsInternalRequest.en.rst | 59 ++++++++++++++++++++ plugins/tcpinfo/tcpinfo.cc | 5 ++ proxy/InkAPI.cc | 18 ++++-- proxy/api/ts/ts.h | 1 + 5 files changed, 79 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/52682da9/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 7e70311..ab72cd1 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 5.0.0 + *) [TS-2855] Add the TSHttpIsInternalSession API. + *) [TS-2859] Remove DBG macros to not generate warnings from GCC 4.9. *) [TS-2858] Build failures on OmniOS. Also add some LuaJIT flags as per http://git-wip-us.apache.org/repos/asf/trafficserver/blob/52682da9/doc/reference/api/TSHttpIsInternalRequest.en.rst ---------------------------------------------------------------------- diff --git a/doc/reference/api/TSHttpIsInternalRequest.en.rst b/doc/reference/api/TSHttpIsInternalRequest.en.rst new file mode 100644 index 0000000..2ac5b2d --- /dev/null +++ b/doc/reference/api/TSHttpIsInternalRequest.en.rst @@ -0,0 +1,59 @@ +.. Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +.. default-domain:: c + +======================= +TSHttpIsInternalRequest +======================= + +Test whether a request is internally-generated. + +Synopsis +======== +`#include <ts/ts.h>` + +.. function:: TSReturnCode TSHttpIsInternalRequest(TSHttpTxn txnp) +.. function:: TSReturnCode TSHttpIsInternalSession(TSHttpSsn ssnp) + +Description +=========== + +:func:`TSHttpIsInternalRequest` tests whether a HTTP transaction +was originated within Traffic Server. + +:func:`TSHttpIsInternalSession` tests whether a HTTP session +was originated within Traffic Server. + +Return Values +============= + +Both these APIs returns a :type:`TSReturnCode`, indicating whether the +object was internal (:data:`TS_SUCCESS`) or not (:data:`TS_ERROR`). + +Examples +======== + +The ESI plugin uses :func:`TSHttpIsInternalRequest` to ignore requests that is +had generated while fetching portions of an ESI document: + +.. literalinclude:: ../../../plugins/experimental/esi/esi.cc + :language: c + :lines: 1395-1398 + +See also +======== +:manpage:`TSAPI(3ts)` http://git-wip-us.apache.org/repos/asf/trafficserver/blob/52682da9/plugins/tcpinfo/tcpinfo.cc ---------------------------------------------------------------------- diff --git a/plugins/tcpinfo/tcpinfo.cc b/plugins/tcpinfo/tcpinfo.cc index 65ad25b..481f553 100644 --- a/plugins/tcpinfo/tcpinfo.cc +++ b/plugins/tcpinfo/tcpinfo.cc @@ -234,6 +234,11 @@ tcp_info_hook(TSCont contp, TSEvent event, void *edata) goto done; } + // Don't try to sample internal requests. TCP metrics for loopback are not interesting. + if (TSHttpIsInternalSession(ssnp) == TS_SUCCESS) { + goto done; + } + // no need to run rand if we are always going log (100%) if (config->sample < 1000) { random = rand() % 1000; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/52682da9/proxy/InkAPI.cc ---------------------------------------------------------------------- diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc index 3811292..00501b2 100644 --- a/proxy/InkAPI.cc +++ b/proxy/InkAPI.cc @@ -7387,22 +7387,28 @@ TSFetchRespHdrMLocGet(TSFetchSM fetch_sm) } TSReturnCode -TSHttpIsInternalRequest(TSHttpTxn txnp) +TSHttpIsInternalSession(TSHttpSsn ssnp) { - sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - - TSHttpSsn ssnp = TSHttpTxnSsnGet(txnp); HttpClientSession *cs = (HttpClientSession *) ssnp; - if (!cs) + if (!cs) { return TS_ERROR; + } NetVConnection *vc = cs->get_netvc(); - if (!vc) + if (!vc) { return TS_ERROR; + } return vc->get_is_internal_request() ? TS_SUCCESS : TS_ERROR; } +TSReturnCode +TSHttpIsInternalRequest(TSHttpTxn txnp) +{ + sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); + return TSHttpIsInternalSession(TSHttpTxnSsnGet(txnp)); +} + TSReturnCode TSAIORead(int fd, off_t offset, char* buf, size_t buffSize, TSCont contp) http://git-wip-us.apache.org/repos/asf/trafficserver/blob/52682da9/proxy/api/ts/ts.h ---------------------------------------------------------------------- diff --git a/proxy/api/ts/ts.h b/proxy/api/ts/ts.h index 4978903..e00aa68 100644 --- a/proxy/api/ts/ts.h +++ b/proxy/api/ts/ts.h @@ -1623,6 +1623,7 @@ extern "C" /* Check if HTTP State machine is internal or not */ tsapi TSReturnCode TSHttpIsInternalRequest(TSHttpTxn txnp); + tsapi TSReturnCode TSHttpIsInternalSession(TSHttpSsn ssnp); /* -------------------------------------------------------------------------- HTTP alternate selection */
