加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

scala – 如何使用akka的http客户端设置最大内容长度?

发布时间:2020-12-16 18:28:59 所属栏目:安全 来源:网络整理
导读:如果我尝试下载一个非常大的文件(超过100 MB),我会收到此错误: You can configure this by setting `akka.http.[server|client].parsing.max-content-length` or calling `HttpEntity.withSizeLimit` before materializing the dataBytes stream.val respon
如果我尝试下载一个非常大的文件(超过100 MB),我会收到此错误:

You can configure this by setting `akka.http.[server|client].parsing.max-content-length` or calling `HttpEntity.withSizeLimit` before materializing the dataBytes stream.


val responseFuture: Future[HttpResponse] =
  Http().singleRequest(HttpRequest(uri = "http://akka.io"))

我正在阅读我可以以某种方式将HttpEntity设置为withoutSizeLimit,我该怎么做?

顺便说一句,如果我将这些配置设置添加到我的application.config,它不能解决问题:

akka.http.server.parsing.max-content-length=913753229
akka.http.client.parsing.max-content-length=913753229

解决方法

我注意到akka.http.scaladsl.model.HttpEntity中withSizeLimit(maxBytes:Long)方法的源代码注释:

Note that the size limit applied via this method will only have any effect if the Source instance contained in this entity has been appropriately modified via the HttpEntity.limitable method. For all entities created by the HTTP layer itself this is always the case,but if you create entities yourself and would like them to properly respect limits defined via this method you need to make sure to apply HttpEntity.limitable yourself.

也许您需要使用HttpEntity对象中的privableByteSource()方法转换Source,以使withoutSizeLimit生效.这里有一些例子:akka http doc.

我遇到了同样的问题,但是文档中有关为什么withSizeLimit()不起作用的有用信息较少.幸运的是,源代码提供了有用的信息:-)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读