问题
I have a specific pipeline in my app that must follow all redirects (let's say up to 50 for sanity's sake), across any domain and protocol (e.g. it could follow http://somewhere.com to https://somewhere.else.com), but only for GET requests. No other pipeline in my app should do this.
Here's what it looks like now:
val pipeline = sendReceive ~> decode(Gzip) ~> decode(Deflate) ~> unmarshal[String]
How can I specify this inside the pipeline's configuration in a host-agnostic manner (i.e. not via configuration option or HostConnectorSetup
)?
回答1:
I don't think you will be able to create a particular pipeline with a bespoke behaviour.
The counter of redirects, called maxRetries
, is stored in the RequestContext, inside a private object called HttpHostConnector
.
And this information only comes from HostConnectorSettings
So I thought about adding an updated HostConnectorSettings
to add custom behaviours, but I am afraid it is defined in the Http object. So there is no option to update this settings. They are defined in the configuration options. And as you said you were looking for another option, this doesn't solve the problem.
And the last thing, I don't think it is possible to change the behaviour only for GET requests either. Here you can see how it works to follow the RFC2616.
So TLDR: All the pipelines will follow redirects or not depending on your configuration, but it is not possible to discriminate which ones will do or don't.
来源:https://stackoverflow.com/questions/36617844/how-can-i-tell-a-specific-spray-client-request-to-follow-all-redirects