You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by Dani Tweig <da...@gmail.com> on 2013/09/11 20:49:56 UTC

can traffic server transform delay the headers response ?

hi,

I am developing a trafficserver plugin which does analysis to the content
of downloaded files using the transform mechanism.
i am having a problem with the header response.
i would like to edit the http headers returned to the browser based on the
analysis i do in the transform, but i found that the headers are already
returned to the browser BEFORE i get a chance to analyse the files content
with the transform mechanism.
am i doing something wrong ?
is there a way to solve this problem ?

p.s. I based my code on the bnull-transform example with a couple of
adjustments.

thanks,

Dani

RE: can traffic server transform delay the headers response ?

Posted by "Bardwell, William" <wb...@akamai.com>.
I think you might be doing things in either the wrong place or the wrong time...
If you want to delete from the ServerResp you need to do it during READ_RESPONSE_HDR, if you only really want to change the response to the client, then you want to delete from ClientResp.  (Note that the body may still be in transit during any of the stages until TXN_CLOSE, so you still may not be able to do what you want.)  If you want to change headers after seeing some of the content, you probably just have to read it in, and pass it along, probably using a second request TSHttpConnect() or some such (and a ServerIntecept()).  But maybe you can Halt the transaction and still see the beginning of the body, and then Unhalt after editing the headers, you would have to try it and see.

-William

Re: can traffic server transform delay the headers response ?

Posted by James Peach <jp...@apache.org>.
On Sep 15, 2013, at 5:54 AM, Dani Tweig <da...@gmail.com> wrote:

> thanks for your response.
> I did as you advices and i am having problem destring one of the server
> headers.
> I still see with wireshark that it is not destroyed.
> 
> here is the relevant piece of code:
> 
>  switch (event) {
> 
>  case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
> {
>      TSMBuffer bufp;
>      TSMLoc hdr_loc;
>      TSMLoc field_loc;
> 
>      TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc);
>      field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, "Content-Disposition",
> -1);
>      if (field_loc == TS_NULL_MLOC) {
>        fprintf(stderr,"[add_header] Error while getting field !!!\n");
>        return 0;
>      }else{
>        fprintf(stderr,"[add_header] removing Content-Disposition !!!\n");
>      }
>      TSMimeHdrFieldDestroy(bufp, hdr_loc, field_loc);
>      TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
>   }

Looking at other plugins that use TSMimeHdrFieldDestroy, they typically loop over duplicate headers using TSMimeHdrFieldNextDup. Maybe you need that for your case too.


> 
> On Fri, Sep 13, 2013 at 12:40 AM, Uri Shachar <us...@hotmail.com> wrote:
> 
>> On Wed, 11 Sep 2013 21:49:56 Dani wrote:
>>> Subject: can traffic server transform delay the headers response ?
>> ...
>>> i would like to edit the http headers returned to the browser based on
>> the
>>> analysis i do in the transform, but i found that the headers are already
>>> returned to the browser BEFORE i get a chance to analyse the files
>> content
>>> with the transform mechanism.
>> 
>> All you need to do is add a hookpoint on TS_HTTP_SEND_RESPONSE_HDR_HOOK,
>> and only reenable when you have finished your analysis + modified the
>> headers.
>> 
>>           --Uri
> 
> 
> 
> 
> -- 
> Dani Tweig


Re: can traffic server transform delay the headers response ?

Posted by quehan <qu...@taobao.com>.
I think it's impossible unless the response body is too short.
May be you can do this with FetchSM, and combo_handler.cc is a reference.


在 2013-9-15,下午8:54,Dani Tweig <da...@gmail.com> 写道:

> thanks for your response.
> I did as you advices and i am having problem destring one of the server
> headers.
> I still see with wireshark that it is not destroyed.
> 
> here is the relevant piece of code:
> 
>  switch (event) {
> 
>  case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
> {
>      TSMBuffer bufp;
>      TSMLoc hdr_loc;
>      TSMLoc field_loc;
> 
>      TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc);
>      field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, "Content-Disposition",
> -1);
>      if (field_loc == TS_NULL_MLOC) {
>        fprintf(stderr,"[add_header] Error while getting field !!!\n");
>        return 0;
>      }else{
>        fprintf(stderr,"[add_header] removing Content-Disposition !!!\n");
>      }
>      TSMimeHdrFieldDestroy(bufp, hdr_loc, field_loc);
>      TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
>   }
> 
> 
> On Fri, Sep 13, 2013 at 12:40 AM, Uri Shachar <us...@hotmail.com> wrote:
> 
>> On Wed, 11 Sep 2013 21:49:56 Dani wrote:
>>> Subject: can traffic server transform delay the headers response ?
>> ...
>>> i would like to edit the http headers returned to the browser based on
>> the
>>> analysis i do in the transform, but i found that the headers are already
>>> returned to the browser BEFORE i get a chance to analyse the files
>> content
>>> with the transform mechanism.
>> 
>> All you need to do is add a hookpoint on TS_HTTP_SEND_RESPONSE_HDR_HOOK,
>> and only reenable when you have finished your analysis + modified the
>> headers.
>> 
>>           --Uri
> 
> 
> 
> 
> -- 
> Dani Tweig


Re: can traffic server transform delay the headers response ?

Posted by Dani Tweig <da...@gmail.com>.
thanks for your response.
I did as you advices and i am having problem destring one of the server
headers.
I still see with wireshark that it is not destroyed.

here is the relevant piece of code:

  switch (event) {

  case TS_EVENT_HTTP_SEND_RESPONSE_HDR:
{
      TSMBuffer bufp;
      TSMLoc hdr_loc;
      TSMLoc field_loc;

      TSHttpTxnServerRespGet(txnp, &bufp, &hdr_loc);
      field_loc = TSMimeHdrFieldFind(bufp, hdr_loc, "Content-Disposition",
-1);
      if (field_loc == TS_NULL_MLOC) {
        fprintf(stderr,"[add_header] Error while getting field !!!\n");
        return 0;
      }else{
        fprintf(stderr,"[add_header] removing Content-Disposition !!!\n");
      }
      TSMimeHdrFieldDestroy(bufp, hdr_loc, field_loc);
      TSHandleMLocRelease(bufp, TS_NULL_MLOC, hdr_loc);
   }


On Fri, Sep 13, 2013 at 12:40 AM, Uri Shachar <us...@hotmail.com> wrote:

> On Wed, 11 Sep 2013 21:49:56 Dani wrote:
> > Subject: can traffic server transform delay the headers response ?
> ...
> > i would like to edit the http headers returned to the browser based on
> the
> > analysis i do in the transform, but i found that the headers are already
> > returned to the browser BEFORE i get a chance to analyse the files
> content
> > with the transform mechanism.
>
> All you need to do is add a hookpoint on TS_HTTP_SEND_RESPONSE_HDR_HOOK,
> and only reenable when you have finished your analysis + modified the
> headers.
>
>            --Uri




-- 
Dani Tweig

RE: can traffic server transform delay the headers response ?

Posted by Uri Shachar <us...@hotmail.com>.
On Wed, 11 Sep 2013 21:49:56 Dani wrote:
> Subject: can traffic server transform delay the headers response ?
...
> i would like to edit the http headers returned to the browser based on the
> analysis i do in the transform, but i found that the headers are already
> returned to the browser BEFORE i get a chance to analyse the files content
> with the transform mechanism.

All you need to do is add a hookpoint on TS_HTTP_SEND_RESPONSE_HDR_HOOK, and only reenable when you have finished your analysis + modified the headers.

           --Uri