[ 
https://issues.apache.org/jira/browse/TS-1045?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13165819#comment-13165819
 ] 

James Peach commented on TS-1045:
---------------------------------

Nope, my example is definitely a TSFetchURL() request. The plugin I'm 
experimenting with is a simple proxy, so when I get a browser request, I make a 
corresponding TSFetchURL request.

TSFetchRespGet() returns the response body. If I apply your example code above, 
TSHttpHdrParseResp() returns TS_PARSE_CONT. This is a bogus result, because at 
the time of the call I'm handling the TSFetchURL() success event so I actually 
have all the data. Additionally, I would really expect TSHttpHdrParseResp() to 
return TS_PARSE_ERROR because it's being asked to return the body.

Hacked up code looks like this:

    TSHttpParser parser = TSHttpParserCreate();
    TSMBuffer buf = TSMBufferCreate();
    TSMLoc hdrLoc = TSHttpHdrCreate(buf);

    body = TSFetchRespGet(txn, &len);
    char * start;
    char * end;

    start = body;
    end = body + len;


    TSHttpHdrTypeSet(buf, hdrLoc, TS_HTTP_TYPE_RESPONSE);
    TSParseResult ret;

    ret = TSHttpHdrParseResp(parser, buf, hdrLoc,
            (const char **)&start, (const char *)end);
    debug_protocol("TSHttpHdrParseResp => %d", ret);
    if (ret != TS_PARSE_DONE) {
        return;
    }

And in the debugger, we see:

Breakpoint 1, send_http_txn_result (stream=0x1014069f0, txn=0x1030a50d0) at 
stream.cc:297
297         TSHttpParser parser = TSHttpParserCreate();
(gdb) n
298         TSMBuffer buf = TSMBufferCreate();
(gdb) n
299         TSMLoc hdrLoc = TSHttpHdrCreate(buf);
(gdb) n
301         body = TSFetchRespGet(txn, &len);
(gdb) n
305         start = body;
(gdb) p body
$1 = 0x101171460 "<html><body><h1>It works!</h1></body></html>"

The code in FetchSM::process_fetch_read() is a bit confusing to me; I'm not 
very familiar with ATS internals. On TS_EVENT_VCONN_READ_READY, resp_reader 
consumes bytes twice in process_fetch_read() and then again in 
client_response_hdr.parse_resp(). By inspection I would have thought that this 
would over-consume, causing bytes to be skipped but that doesn't seem to 
happen. At any rate, it reliably returns only the response body.
                
> PATCH: add new TSFetchHdrGet API
> --------------------------------
>
>                 Key: TS-1045
>                 URL: https://issues.apache.org/jira/browse/TS-1045
>             Project: Traffic Server
>          Issue Type: Improvement
>          Components: HTTP
>            Reporter: James Peach
>            Priority: Minor
>         Attachments: 0007-Add-new-public-API-TSFetchHdrGet.patch
>
>
> TSFetchUrl does not provide any way to get the headers from the result. This 
> patch adds a new API TSFetchHdrGet(), which is analogous to TSFetchRespGet() 
> and returns the headers.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to