如何告诉特定的喷涂客户请求遵循所有重定向? [英] How can I tell a specific spray-client request to follow all redirects?

查看:103
本文介绍了如何告诉特定的喷涂客户请求遵循所有重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个特定的管道,该管道必须遵循所有域和协议中的所有重定向(例如,为了理智起见,最多可以进行50次重定向)(例如,它可以遵循 http://somewhere.com https://somewhere.else.com ),但仅适用于GET请求.我的应用程序中没有其他管道可以执行此操作.

这是现在的样子:

val pipeline = sendReceive ~> decode(Gzip) ~> decode(Deflate) ~> unmarshal[String]

我如何以与主机无关的方式(即不通过配置选项或HostConnectorSetup)在管道的配置中指定此内容?

解决方案

我认为您将无法创建具有定制行为的特定管道.

重定向计数器称为maxRetries,存储在此处,您将了解遵循 RFC2616 的工作原理.. >

所以TLDR:所有管道都将遵循重定向或不遵循重定向,具体取决于您的配置,但是无法区分哪些管道将执行重定向或不进行重定向.

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)?

解决方案

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.

这篇关于如何告诉特定的喷涂客户请求遵循所有重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆