如何配置 HTTPServer 使用内容长度而不传输编码:分块?
我正在使用 java 的 HTTP Server 对象以及由 WebServiceProvider 实现的 Web 服务。 我发现无论客户请求如何,答案都是分块的,我需要它具有内容长度。 所以我假设问题出在服务器而不是网络服务器提供商,对吧? 我如何配置http标头以使用内容长度而不是分块?
HttpServer m_server = HttpServer.create();
Endpoint ep= Endpoint.create(new ep());
HttpContext epContext = m_server.createContext("/DownloadFile");
ep.publish(downloadFileContext);
I'm using java's HTTP Server object with web service implemeted by WebServiceProvider.
I see that no matter of the client request, the answer is chunked and i need it to be with content length.
so i'm assuming the problem is in the server and not the web server provider, right?
and how can i configure the http header to use content length and not chunked?
HttpServer m_server = HttpServer.create();
Endpoint ep= Endpoint.create(new ep());
HttpContext epContext = m_server.createContext("/DownloadFile");
ep.publish(downloadFileContext);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您正在谈论
com.sun.net.httpserver
HTTP 服务器。我进一步假设您通过调用Endpoint.publish
,使用一些支持HTTPServer的服务提供者。关键在于
HttpExchange.sendResponseHeaders
方法:因此,只要处理程序为
responseLength
传递正值,就会使用 Content-Length。当然,要做到这一点,它必须提前知道要发送多少数据,但它很可能不会。恐怕它是否完全取决于绑定的实现。我不相信这是标准化的 - 事实上,我不相信 WebServiceProvider/HTTPServer 是标准化的。但是,即使您的提供商不合作,您也有一个追索权:编写 Filter 添加缓冲,并将其添加到您用于发布服务的 HttpContext 中。我认为要做到这一点,您必须编写 HttpExchange 缓冲写入其中的数据,将其传递到过滤器链以供处理程序写入其响应,然后当它返回时,写入缓冲内容,设置
responseLength
当它这样做时。I assume you're talking about the
com.sun.net.httpserver
HTTPServer. I further assume that you're connecting the server to the service with a call toEndpoint.publish
, using some service provider which supports HTTPServer.The key is in the
HttpExchange.sendResponseHeaders
method:So, as long as the handler is passing a positive value for
responseLength
, Content-Length is used. Of course, to do that, it will have to know how much data it is going to send ahead of time, which it might well not. Whether it does or not depends entirely on the implementation of the binding, i'm afraid. I don't believe this is standardised - indeed, i don't believe that the WebServiceProvider/HTTPServer is standardised at all.However, even if your provider is uncooperative, you have a recourse: write a Filter which adds buffering, and add it to the HttpContext which you are using to publish the service. I think that to do this, you would have to write an implementation of HttpExchange which buffers the data written to it, pass that down the filter chain for the handler to write its response to, then when it comes back, write the buffered content, setting the
responseLength
when it does so.