我正在通过在Apache Tomcat/6.0.18上运行的Spring MVC控制器传输大型文档
因为它很大,并且(最终)会动态生成,所以我决定使用分块传输编码.
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.ChunkedOutputStream;
import org.apache.commons.net.io.CopyStreamException;
import org.apache.commons.net.io.Util;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class QueryController {
@Inject
QueryService queryService;
@RequestMapping(value = "/stream")
public void hellostreamer(HttpServletResponse response) throws CopyStreamException, IOException {
response.setHeader("Transfer-Encoding", "chunked");
response.setHeader("Content-type", "text/xml");
InputStream filestream = new FileInputStream("/lotsrecs.xml");
ChunkedOutputStream chunkStream = new ChunkedOutputStream(response.getOutputStream());
Util.copyStream(filestream,chunkStream);
chunkStream.close();
chunkStream.finish();
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我在firefox中打开它时,我得到了这个:
XML Parsing Error: syntax error
Location: http://localhost:8082/streaming-mockup-1.0-SNAPSHOT/stream
Line Number 1, Column 1:
800
^
Run Code Online (Sandbox Code Playgroud)
而不是将块大小作为关于流的元数据读取,而是将它们作为流的一部分读取!
使用Live HTTP标头,我可以看到正在接收Transfer-Encoding标头: …
我创建了一个HTTP端点(Java中的REST,Spring Framework,Apache Tomcat),其中HTTP响应的标题为"Transfer-Encoding:chunked".我不知道它是由servlet还是服务器创建的.
我不希望端点响应该标头.是否可以强制它以便不发送标题?
我有一个通常的静态站点,服务器在其中捕获.html文件并将其发送。
我了解Transfer-Encoding: chunked动态服务器页面的重要性,因为这是针对动态服务器页面而设计的。加速可能非常令人难以置信。但是,静态文件的速度增加是否相同?当Content-Length文件通过网络到达时,浏览器是否已经逐步使用&的请求进行渲染和获取?
我有一些非常巨大的HTML(百页范围内的文档),因此渐进式HTML处理至关重要。(有点像WHATWG如何提供整体式单页HTML5规范。)
我正在尝试上传一个0字节的文件,其中包含对owncloud的请求.我想为此使用类似文件的对象.通常我会这样做:
file_obj = io.BytesIO(b'')
response = requests.put('http://localhost/remote.php/webdav',
auth=('xxx', 'xxx'),
data=file_obj)
Run Code Online (Sandbox Code Playgroud)
但它冻结了.如果我中断进程,我会看到它与堆栈跟踪挂起的位置:
Traceback (most recent call last):
File "/home/julian/cc/client/.venv/lib/python3.5/site-packages/requests/packages/urllib3/connectionpool.py", line 376, in _make_request
httplib_response = conn.getresponse(buffering=True)
TypeError: getresponse() got an unexpected keyword argument 'buffering'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/julian/cc/client/cc/storage/webdav.py", line 360, in <module>
main()
File "/home/julian/cc/client/cc/storage/webdav.py", line 351, in main
data=file_obj)
File "/home/julian/cc/client/.venv/lib/python3.5/site-packages/requests/api.py", line 120, in put
return request('put', url, data=data, **kwargs)
File "/home/julian/cc/client/.venv/lib/python3.5/site-packages/requests/api.py", line 53, in request
return session.request(method=method, …Run Code Online (Sandbox Code Playgroud) 我正在编写一个应用程序,用于计算在网页上使用 gzip 后我们获得的节省。当用户输入使用 gzip 的网页的 URL 时,应用程序应该吐出由于 gzip 而节省的大小。
我应该如何解决这个问题?
这是我在页面上作为 GET 请求的标头所得到的:
{
'X-Powered-By': 'PHP/5.5.9-1ubuntu4.19',
'Transfer-Encoding': 'chunked',
'Content-Encoding': 'gzip',
'Vary': 'Accept-Encoding',
'Server': 'nginx/1.4.6 (Ubuntu)',
'Connection': 'keep-alive',
'Date': 'Thu, 10 Nov 2016 09:49:58 GMT',
'Content-Type': 'text/html'
}
Run Code Online (Sandbox Code Playgroud)
我正在检索页面requests:
r = requests.get(url, headers)
data = r.text
print "Webpage size : " , len(data)/1024
Run Code Online (Sandbox Code Playgroud) 我正在尝试重新解决一个问题。http 响应标头:Transfer-Encoding: chunked
我们在 spring-boot + 嵌入式 tomcat 中有一个 CXF-SOAP Web 服务。
SOAP 响应有一个Content-Length标头,但没有Transfer-Encoding……我猜这很正常?
不幸的是,我们有一些遗留的客户端黑客,它们似乎只适用Transfer-Encoding: chunked于Content-Length.
有没有办法强制服务器应用程序响应Transfer-Encoding: chunked?
到底是什么决定了生成哪种响应格式?
它可以以某种方式配置吗?
我需要测试服务器并从Fiddler发送一个chunked请求.我需要发送一些非常简单的东西,例如'a'字符作为内容.
有一个Request Builder选项卡,我可以在其中设置Transfer-Encoding:chunked header,但是如何指定Request Body?
golang 的 net/http 包是否支持使用分块传输编码的请求?到目前为止,我已经能够使用 Hijacker 接口(https://golang.org/src/net/http/server.go?s=6173:6875#L156)至少不关闭连接并接收完整的分块请求,但尚未解析块,并怀疑我可能走错了路。
从https://golang.org/src/net/http/httputil/httputil.go?s=688:732#L10,我看到有一个分块阅读器,但似乎供内部使用。
本质上,我试图接受带有“分块”传输编码的 HTTP PUT 并将其发送到后端服务器“即时”(即不缓冲 golang 中的完整请求)。我无法控制上游请求。有没有推荐的方法来处理这样的请求,或者劫机者是这样做的?
我有一个客户端在没有HTTP分块的情况下向我发送请求(它们使用内容长度).当我的服务器响应时,启用了分块,客户端无法处理 - 即使他们应该能够使用HTTP 1.1 .....
我试图通过从axis2配置文件(axis2.xml)中删除下面的条目来禁用分块,但响应仍然会返回分块.
分块
所以问题是,是否还有其他地方正在启用超出axis2设置的分块?在tomcat设置或许?
Web服务器详细信息 - tomcat 6.0.16,axis2 2.1.3
谢谢迈克