Discussion:
issue in getting http response size
Gaurav Bansal
2017-07-14 07:37:29 UTC
Permalink
hi all,
I want to get the total http response size (i.e. size of headers + body).
For this i tried using below two api's :
TSHttpTxnServerRespBodyBytesGet(txnp) //always returns 0
TSHttpTxnServerRespHdrBytesGet(txnp) //seems to work fine

Are there any known issues in using the first api ? Is there any alternate
way to get the total size (headers + body) ?
thanks,
gaurav
Leif Hedstrom
2017-07-14 15:57:35 UTC
Permalink
Post by Gaurav Bansal
hi all,
TSHttpTxnServerRespBodyBytesGet(txnp) //always returns 0
TSHttpTxnServerRespHdrBytesGet(txnp) //seems to work fine
Hmmm, sounds broken / bad. First I thought it might be cache hit / miss related, but then reading your email again, it seems the header bytes is always right, so that can’t be it
 Do you have a reproducible test case? A small plugin that you can maybe attach to a Github Issue?

That much said, maybe you could try these instead?

TSHttpTxnClientRespHdrBytesGet()
TSHttpTxnClientRespBodyBytesGet()


Cheers,

— leif
Brian Geffon
2017-07-14 16:15:06 UTC
Permalink
I'd like to add something to this, you may not be able to calculate the
body size until a TXN Close, if you're trying to get the response body
since in READ_RESPONSE_HEADERS you're probably going to have a bad time
unless a content-length header is set, which even then may not result in
response body bytes being available. (But I also didn't check the code, I'm
just assuming). I'd try again in a TXN Close hook to see if it's available
there.

Brian
Post by Gaurav Bansal
hi all,
I want to get the total http response size (i.e. size of headers + body).
TSHttpTxnServerRespBodyBytesGet(txnp) //always returns 0
TSHttpTxnServerRespHdrBytesGet(txnp) //seems to work fine
Hmmm, sounds broken / bad. First I thought it might be cache hit / miss
related, but then reading your email again, it seems the header bytes is
always right, so that can’t be it
 Do you have a reproducible test case? A
small plugin that you can maybe attach to a Github Issue?
That much said, maybe you could try these instead?
TSHttpTxnClientRespHdrBytesGet()
TSHttpTxnClientRespBodyBytesGet()
Cheers,
— leif
Gaurav Bansal
2017-07-15 11:02:32 UTC
Permalink
@Leif :
1) TSHttpTxnClientRespBodyBytesGet() is giving the correct content length
as opposed to TSHttpTxnServerRespBodyBytesGet() (i don't have any plugin to
share right now but this api always gives 0). What difference it will make
to use one api over another ?
2) TSHttpTxnServerRespHdrBytesGet() & TSHttpTxnClientRespHdrBytesGet() are
giving different values. Can you please let me know what is the difference
between the two.

@Brian :
yes i want to calculate the response body size at the txn close only.
Post by Brian Geffon
I'd like to add something to this, you may not be able to calculate the
body size until a TXN Close, if you're trying to get the response body
since in READ_RESPONSE_HEADERS you're probably going to have a bad time
unless a content-length header is set, which even then may not result in
response body bytes being available. (But I also didn't check the code, I'm
just assuming). I'd try again in a TXN Close hook to see if it's available
there.
Brian
Post by Gaurav Bansal
hi all,
I want to get the total http response size (i.e. size of headers + body).
TSHttpTxnServerRespBodyBytesGet(txnp) //always returns 0
TSHttpTxnServerRespHdrBytesGet(txnp) //seems to work fine
Hmmm, sounds broken / bad. First I thought it might be cache hit / miss
related, but then reading your email again, it seems the header bytes is
always right, so that can’t be it
 Do you have a reproducible test case? A
small plugin that you can maybe attach to a Github Issue?
That much said, maybe you could try these instead?
TSHttpTxnClientRespHdrBytesGet()
TSHttpTxnClientRespBodyBytesGet()
Cheers,
— leif
Velusamy, Gandhimathi
2017-07-15 15:47:44 UTC
Permalink
Hi,
In my experiments I am reading the response size with Content-length field as below: ( Traffic server-7.0.0)

case TS_EVENT_HTTP_READ_RESPONSE_HDR:
{
if (TS_SUCCESS == TSHttpTxnServerRespGet(txn, &hdr_bufp, &hdr_loc)) {
TSMLoc loc = TSMimeHdrFieldFind(hdr_bufp, hdr_loc, "Content-Length", -1);
sd.status_code = TSHttpHdrStatusGet(hdr_bufp, hdr_loc);
if (TS_NULL_MLOC != loc) {
sd.c_len = TSMimeHdrFieldValueUintGet(hdr_bufp, hdr_loc, loc, 0 );
TSDebug("balancer", " [%" PRIu64 "] %d %d", smid, sd.status_code, sd.c_len);
}
TSHandleMLocRelease(hdr_bufp, hdr_loc, loc);
}

}
And in Transaction close event:

case TS_EVENT_HTTP_TXN_CLOSE:
{
resp_size = TSHttpTxnServerRespBodyBytesGet(txt);
TSDebug("balancer", "[%" PRIu64 "]Server response size %d", smid, resp_size);
}

The output from Traffic server:

[Jul 15 10:15:44.450] Server {0x7f7b7309b700} DIAG: (balancer) [176] 200 334496
[Jul 15 10:15:44.455] Server {0x7f7b7309b700} DIAG: (balancer) [176]Server response size 334496

I am using load balancer plugin for my experiments.

Thanks
Gandhimathi

On Jul 14, 2017, at 2:37 AM, Gaurav Bansal <***@gmail.com<mailto:***@gmail.com>> wrote:

hi all,
I want to get the total http response size (i.e. size of headers + body). For this i tried using below two api's :
TSHttpTxnServerRespBodyBytesGet(txnp) //always returns 0
TSHttpTxnServerRespHdrBytesGet(txnp) //seems to work fine

Are there any known issues in using the first api ? Is there any alternate way to get the total size (headers + body) ?
thanks,
gaurav

Continue reading on narkive:
Loading...