Ref: https://github.com/ratpack/ratpack/issues/975
Probably still needs some work, but I wanted to get some feedback on this before taking it much further.
I've added a couple of "hooks" that allow intercepting the sent request and received response. These hooks (currently) don't permit modification of either the request or the response - they're intended as "wiretaps" (which would be fine for my original use case).
Re. this (https://github.com/ratpack/ratpack/issues/975#issuecomment-216666556) bit of feedback, I've also added a hook that allows you to customize the RequestSpec all requests (e.g. add a header on all requests).
These interceptors can bound in the registry, in which case they'll apply "globally" for all HttpClient instance. I've also added a builder class for HttpClient instances so that you can apply interceptors for a specific instance of HttpClient.
I had some trouble with the unit tests in that I wasn't able to use bindings { ... } to bind my interceptors.
该提问来源于开源项目:ratpack/ratpack