Capture body of POST requests in the onResponse callback

61 views
Skip to first unread message

Adi Tanase

unread,
Feb 16, 2015, 5:52:13 AM2/16/15
to gopro...@googlegroups.com
Hi all,

I'm having a bit of trouble finding an example of how to capture the body of a POST call (the request) - on the response callback.

In a straightforward implementation - trying to read req.Body in the onResponse callback - I get an error.
Before I resort to various state-keeping techniques (queues, request-headers with the request "ID", etc), I'm wondering if it's a better way to accomplish this.

Specifically, are any of the following use-cases supported by the library?
  • referencing the original request body in the onResponse callback - maybe I'm missing a setting or specific API?
  • saving something in the request context in onRequest that I can query back in onResponse
Lastly - what is the use-case for the RoundTripper interface and its implementations? I couldn't find a good example so far.

Thanks in advance!
-adrian

Elazar Leibovich

unread,
Feb 16, 2015, 5:56:59 AM2/16/15
to Adi Tanase, gopro...@googlegroups.com
Hi,

To keep something in the request context, you can use the context object.

onRequest:
ctx.UserData = myData
onResponse:
use(ctx.UserData.(UserDataType))

Roundtripper is used in case you want a special function to happen when sending requests from the proxy server to the internet. For example, a user wanted to direct the connection for special requests from a special network card.

Thanks for using goproxy.

--
You received this message because you are subscribed to the Google Groups "goproxy-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to goproxy-dev...@googlegroups.com.
To post to this group, send email to gopro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/goproxy-dev/a93bf9ee-d9b8-4be8-b022-92a24e7b4e1b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adi Tanase

unread,
Feb 16, 2015, 7:30:13 AM2/16/15
to gopro...@googlegroups.com, adi.t...@gmail.com
This is great - I knew I must be missing something.

Thanks for the quick reply.

-adrian
Reply all
Reply to author
Forward
0 new messages