weixin_39757169 2020-11-29 18:01
浏览 1

Add interceptors for HttpClient (#975)

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.

This change is Reviewable

该提问来源于开源项目:ratpack/ratpack

  • 写回答

1条回答 默认 最新

  • weixin_39757169 2020-11-29 18:01
    关注

    So...that failure...I think they're both 404s so I think something was moved. In any case, as far as i can tell, not related to this PR.

    ~~[Update]: added this PR (https://github.com/ratpack/ratpack/pull/980) to address this failure~~ All good now!

    
    ratpack.site.LinkCrawlSpec > site has no bad links FAILED
        Condition not satisfied:
    
        errored.empty
        |       |
        |       false
        http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/io/Resources.html (referrers: [http://localhost:56762/manual/1.4.0/config.html], errors: [HTTP status: 404], attempts: 3),
        http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/io/ByteSource.html (referrers: [http://localhost:56762/manual/1.4.0/config.html], errors: [HTTP status: 404], attempts: 3)
            at ratpack.site.LinkCrawlSpec.site has no bad links(LinkCrawlSpec.groovy:77)
    
    评论

报告相同问题?