Updated Branches: refs/heads/master 0373ca358 -> daa10ebce
[TS-2475] Adding new transaction methods to C++ API Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/daa10ebc Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/daa10ebc Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/daa10ebc Branch: refs/heads/master Commit: daa10ebce3fbde1ef640af0a9f9040418a4e45cf Parents: 0373ca3 Author: Brian Geffon <[email protected]> Authored: Fri Jan 3 10:43:15 2014 -0800 Committer: Brian Geffon <[email protected]> Committed: Fri Jan 3 10:43:15 2014 -0800 ---------------------------------------------------------------------- CHANGES | 2 ++ lib/atscppapi/src/Transaction.cc | 22 +++++++++++++ .../src/include/atscppapi/Transaction.h | 34 ++++++++++++++++++++ proxy/http/HttpSM.cc | 1 + 4 files changed, 59 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/daa10ebc/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index b00bbf4..2759e63 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 4.2.0 + *) [TS-2475] Adding new transaction methods in C++ API + *) [TS-2474] Change proxy.config.net.poll_timeout to 10ms consistently. *) [TS-2473] Fix C++ API includes for FreeBSD. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/daa10ebc/lib/atscppapi/src/Transaction.cc ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/Transaction.cc b/lib/atscppapi/src/Transaction.cc index e3be20f..df3f852 100644 --- a/lib/atscppapi/src/Transaction.cc +++ b/lib/atscppapi/src/Transaction.cc @@ -217,6 +217,28 @@ bool Transaction::setIncomingPort(uint16_t port) { return true; // In reality TSHttpTxnClientIncomingPortSet should return SUCCESS or ERROR. } +/* + * Note: The following methods cannot be attached to a Response + * object because that would require the Response object to + * know that it's a server or client response because of the + * TS C api which is TSHttpTxnServerRespBodyBytesGet. + */ +size_t Transaction::getServerResponseBodySize() { + return static_cast<size_t>(TSHttpTxnServerRespBodyBytesGet(state_->txn_)); +} + +size_t Transaction::getServerResponseHeaderSize() { + return static_cast<size_t>(TSHttpTxnServerRespHdrBytesGet(state_->txn_)); +} + +size_t Transaction::getClientResponseBodySize() { + return static_cast<size_t>(TSHttpTxnClientRespBodyBytesGet(state_->txn_)); +} + +size_t Transaction::getClientResponseHeaderSize() { + return static_cast<size_t>(TSHttpTxnClientRespHdrBytesGet(state_->txn_)); +} + void Transaction::setTimeout(Transaction::TimeoutType type, int time_ms) { switch (type) { case TIMEOUT_DNS: http://git-wip-us.apache.org/repos/asf/trafficserver/blob/daa10ebc/lib/atscppapi/src/include/atscppapi/Transaction.h ---------------------------------------------------------------------- diff --git a/lib/atscppapi/src/include/atscppapi/Transaction.h b/lib/atscppapi/src/include/atscppapi/Transaction.h index 13def37..1e6014f 100644 --- a/lib/atscppapi/src/include/atscppapi/Transaction.h +++ b/lib/atscppapi/src/include/atscppapi/Transaction.h @@ -264,6 +264,40 @@ public: */ void addPlugin(TransactionPlugin *); + + /* + * Note: The following methods cannot be attached to a Response + * object because that would require the Response object to + * know that it's a server or client response because of the + * TS C api which is TSHttpTxnServerRespBodyBytesGet. + */ + + /** + * Get the number of bytes for the response body as returned by the server + * + * @return server response body size */ + size_t getServerResponseBodySize(); + + /** + * Get the nubmber of bytes for the response headers as returned by the server + * + * @return server response header size */ + size_t getServerResponseHeaderSize(); + + /** + * Get the number of bytes for the client response. + * This can differ from the server response size because of transformations. + * + * @return client response body size */ + size_t getClientResponseBodySize(); + + /** + * Get the number of bytes for the response headers. + * This can differ from the server response because headers can be modified. + * + * @return client response header size */ + size_t getClientResponseHeaderSize(); + private: TransactionState *state_; //!< The internal TransactionState object tied to the current Transaction friend class TransactionPlugin; //!< TransactionPlugin is a friend so it can call addPlugin() http://git-wip-us.apache.org/repos/asf/trafficserver/blob/daa10ebc/proxy/http/HttpSM.cc ---------------------------------------------------------------------- diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc index df9dac5..654c2d8 100644 --- a/proxy/http/HttpSM.cc +++ b/proxy/http/HttpSM.cc @@ -3102,6 +3102,7 @@ HttpSM::tunnel_handler_ua(int event, HttpTunnelConsumer * c) } client_response_body_bytes = c->bytes_written - client_response_hdr_bytes; + if (client_response_body_bytes < 0) client_response_body_bytes = 0;
