What is the right way to observe not only the headers, but the bodies
of GET and POST requests/responses?

Essentially, I'm writing an extension to simply log all requests/
responses to the console.  The following approach works fantastic for
HTTP headers, but doesn't output the body:

1) Add observers for "http-on-modify-request" and "http-on-examine-
response"
2) Output the headers straight from nsIHttpChannel:

    if (aTopic == "http-on-modify-request")
    {
        // Output the results
        e.QueryInterface(Components.interfaces.nsIHttpChannel);
        var requestCookie  = "(none)";
        try { requestCookie  = e.getRequestHeader( "Cookie" );  }
catch( ignore ) { }
        TRACE( e.URI.asciiSpec  + "\n" +
               e.requestMethod  + " Cookie: " + requestCookie );
    }
    else if( aTopic == "http-on-examine-response" )
    {
        // Output the results
        e.QueryInterface(Components.interfaces.nsIHttpChannel);
        var requestCookie  = "(none)";
        var responseCookie = "(none)";
        try { requestCookie  = e.getRequestHeader( "Cookie" );  }
catch( ignore ) { }
        try { responseCookie = e.getResponseHeader( "Set-Cookie" ); }
catch( ignore ) { }
        TRACE( e.URI.asciiSpec  + "\n" +
               e.requestMethod  + " Cookie: " + requestCookie + "\n" +
               e.responseStatus + " Set-Cookie: " + responseCookie );
    }

What is the right way to also output POST request bodies, as well as
GET and POST responses? (Obviously this is inefficient, but I'm going
to use filtering to only get the specific requests I want once it's
working.)

So far as I can tell, it sounds like the right approach is to set the
nsIChannel::notificationCallbacks to something that has
OnDataAvailable overridden, and then perhaps trap the body somehow,
and maybe do a man-in-the-middle technique where I spawn off a new
request after dismantling the first.  But, as you can see, I'm not
really sure what I'm talking about.

Is there some easier way to do this?

Or, is there an extension that already does this?  (Just logs all
requests/responses somewhere.)

I'd normally just use Ethereal for this, except the requests in
connection are over HTTPS.  I'm *so close* by having all the headers,
but I need to capture the POST request bodies as well before I can do
what I need.

Thanks!

-david

_______________________________________________
dev-tech-network mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-network

Reply via email to