天道酬勤,学无止境

chunked

使用 okhttp 分块的传输编码仅提供完整结果(Transfer Encoding chunked with okhttp only delivers full result)

问题 我正在尝试对分块端点获得一些见解,因此计划逐块打印服务器发送给我的内容。 我没有这样做,所以我写了一个测试,看看 OkHttp/Retrofit 是否按我的预期工作。 以下测试应该向控制台提供一些块,但我得到的只是完整的响应。 我什至让 OkHttp3 的 MockWebServer 向我发送块,我有点失去了我所缺少的东西。 我发现了这个改造问题条目,但答案对我来说有点模棱两可:Chunked Transfer Encoding Response class ChunkTest { @Rule @JvmField val rule = RxImmediateSchedulerRule() // custom rule to run Rx synchronously @Test fun `test Chunked Response`() { val mockWebServer = MockWebServer() mockWebServer.enqueue(getMockChunkedResponse()) val retrofit = Retrofit.Builder() .baseUrl(mockWebServer.url("/")) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .client

2022-01-15 19:01:24    分类:技术分享    retrofit   rx-java2   okhttp3   chunked

Transfer Encoding chunked with okhttp only delivers full result

I am trying to get some insights on a chunked endpoint and therefore planned to print what the server sends me chunk by chunk. I failed to do so so I wrote a test to see if OkHttp/Retrofit are working as I expect it. The following test should deliver some chunks to the console but all I get is the full response. I am a bit lost what I am missing to even make the MockWebServer of OkHttp3 sending me chunks. I found this retrofit issue entry but the answer is a bit ambiguous for me: Chunked Transfer Encoding Response class ChunkTest { @Rule @JvmField val rule = RxImmediateSchedulerRule() //

2022-01-15 11:46:05    分类:问答    retrofit   rx-java2   okhttp3   chunked

如果未发送 HTTP 标头,如何从分块编码中确定内容数据长度(How to determine content-data length from chunked encoding if HTTP header not sent)

问题 如果未发送标头而是接收Transfer-Encoding: chunked标头,如何确定内容数据长度? 回答1 使用分块编码将没有 Content-Length 标头。 因此,在您阅读了标头和标记标头结尾的一对 CRLF 之后,您就可以阅读第一个块了。 每个块有效负载前面都有自己的迷你标头 - 十六进制长度,后跟 CRLF。 在有效载荷之后,在下一个块的迷你头之前,还有另一个 CRLF。 一个块也可以跟一些可选的预告片。 消息的结尾由零长度块指示。 您可以在 HTTP RFC、RFC2616 中找到明确的详细信息。

2021-12-23 02:27:58    分类:技术分享    http   content-length   chunked

为什么 Tomcat 向我的 RESTful API 返回不同的 HEAD 和 GET 请求标头?(Why Tomcat returns different headers for HEAD and GET requests to my RESTful API?)

问题 我最初的目的是验证HTTP 分块传输。 但是无意中发现了这个不一致。 API 旨在将文件返回给客户端。 我对它使用HEAD和GET方法。 返回不同的标头。 对于GET ,我得到这些标题:(这是我所期望的。) 对于HEAD ,我得到这些标题: 根据此线程, HEAD和GET应该返回相同的标头,但不一定返回 . 我的问题是: 如果使用Transfer-Encoding: chunked因为文件是动态提供给客户端的,而 Tomcat 服务器事先无法知道其大小,那么在使用HEAD方法时,Tomcat 如何知道Content-Length ? Tomcat 只是干运行处理程序并计算所有文件字节数吗? 为什么它不简单地返回相同的Transfer-Encoding: chunked标头? 下面是我用Spring Web MVC实现的 RESTful API: @RestController public class ChunkedTransferAPI { @Autowired ServletContext servletContext; @RequestMapping(value = "bootfile.efi", method = { RequestMethod.GET, RequestMethod.HEAD }) public void doHttpBoot

2021-12-21 12:42:30    分类:技术分享    http   tomcat8   http-method   chunked

Why Tomcat returns different headers for HEAD and GET requests to my RESTful API?

My initial purpose was to verify the HTTP chunked transfer. But accidentally found this inconsistency. The API is designed to return a file to client. I use HEAD and GET methods against it. Different headers are returned. For GET, I get these headers: (This is what I expected.) For HEAD, I get these headers: According to this thread, HEAD and GET SHOULD return identical headers but not necessarily. My question is: If Transfer-Encoding: chunked is used because the file is dynamically fed to the client and Tomcat server cannot know its size beforehand, how could Tomcat know the Content-Length

2021-12-10 19:49:52    分类:问答    http   tomcat8   http-method   chunked

如何强制 http.client 在 python 中发送分块编码的 HTTP 正文?(How to force http.client to send chunked-encoding HTTP body in python?)

问题 我想发送分块的 HTTP 正文来测试我自己的 HTTP 服务器。 所以我写了这个python代码: import http.client body = 'Hello World!' * 80 conn = http.client.HTTPConnection("some.domain.com") url = "/some_path?arg=true_arg" conn.request("POST", url, body, {"Transfer-Encoding":"chunked"}) resp = conn.getresponse() print(resp.status, resp.reason) 我希望 HTTP 请求的正文是分块传输的,但是我用 Wireshark 捕获了网络包,HTTP 请求的正文没有被分块传输。 如何通过python中的http.client lib传输分块主体? 回答1 好的我明白了。 首先,编写我自己的分块编码函数。 然后使用 putrequest()、putheader()、endheaders() 和 send() 代替 request() import http.client def chunk_data(data, chunk_size): dl = len(data) ret = "" for i in range(dl //

2021-12-08 12:05:16    分类:技术分享    python   http   chunked

How to determine content-data length from chunked encoding if HTTP header not sent

How to determine the content-data length if the header is not sent and instead you receive Transfer-Encoding: chunked header?

2021-11-25 06:36:02    分类:问答    http   content-length   chunked

How to force http.client to send chunked-encoding HTTP body in python?

I want to send chunked HTTP body to test my own HTTP server. So I wrote this python code: import http.client body = 'Hello World!' * 80 conn = http.client.HTTPConnection("some.domain.com") url = "/some_path?arg=true_arg" conn.request("POST", url, body, {"Transfer-Encoding":"chunked"}) resp = conn.getresponse() print(resp.status, resp.reason) I expect the HTTP request's body is transferrd chunked, but I capture the network package with Wireshark, the HTTP request's body is not transferred chunked. How to transfer chunked body by http.client lib in python?

2021-11-21 19:38:37    分类:问答    python   http   chunked

读取传输编码分块的 Flex/Flash URL(Read Flex/Flash URL which has Transfer-Encoding chunked)

问题 我在从 Flex 读取具有 Transfer-Encoding: chunked 的 url 时遇到问题,因为 FLex 等待服务器发送终止信号,而在分块传输中未发送该信号... 回答1 使用 URLStream 类而不是您现在使用的任何加载器。 它的 ProgressEvents 将让您在消息完成之前读取块。 回答2 但是,如果您更仔细地阅读文档,您会发现以下内容。 所以很明显,你只需要检查接收到的块的大小,直到它变为零。 数据传输由长度为零的最后一个块终止

2021-10-29 16:35:30    分类:技术分享    apache-flex   flash   actionscript-3   apache   chunked

Read Flex/Flash URL which has Transfer-Encoding chunked

I have a problem reading from Flex a url which has Transfer-Encoding: chunked because the FLex waits for the server to send terminate signal which in chunked transfer isn't sent...

2021-10-29 12:11:42    分类:问答    apache-flex   flash   actionscript-3   apache   chunked