相关疑难解决方法(0)

分块传输编码 - 浏览器行为

我正在尝试以分块模式发送数据.正确设置所有标头并相应地编码数据.浏览器将我的响应识别为分块,接受标头并开始接收数据.

我期待浏览器会在每个收到的块上更新页面,而是等待直到收到所有块然后全部显示它们.这是预期的行为吗?

我希望看到每个块在收到后立即显示.使用时curl,每个块在收到后立即显示.为什么GUI浏览器不会发生同样的情况?他们使用某种缓冲/缓存吗?

我将Cache-Control标头设置为no-cache,所以不确定它是否与缓存有关.

browser firefox google-chrome http

23
推荐指数
2
解决办法
7552
查看次数

response.flushBuffer()不起作用

我正在尝试实现一个用于流式传输大型对象的servlet:

    oracle.sql.BLOB blob = rs.getBLOB('obj');
    InputStream in = blob.getBinaryStream();

    int bufferSize = 1024;
    byte[] buffer = new byte[bufferSize];

    ServletOutputStream out = response.getOutputStream();

    int counter=0
    while((length=in.read(buffer)) != -1){
        out.write(buffer,0,length);
        counter++;
        if(counter % 10 == 0){
        counter=0;
        response.flushBuffer();
    }
Run Code Online (Sandbox Code Playgroud)

此代码假设通过chunck将数据发送到客户端块.现在发生的事情是,当我传输大对象(100 MB)时,内存会上升,如果有多个并行下载/流,服务器有时会死掉.

为什么这flushBuffer()不是向客户端发送数据?只有在响应关闭后,客户端才会弹出打开/保存文件.

java streaming servlets blob oracle11g

6
推荐指数
1
解决办法
4836
查看次数

Java Spring - dynamically generated csv file download response is hanging

On my company's site we have some tables that we need to export to a csv file.
There are some varying parameters, so the csv file needs to be dynamically created on request.

My problem is that after clicking to download, the response hangs, and waits for the whole file to be created (which can take some time) and only then downloads the entire file in one instant.

I'm using AngularJS, so I'm using window.location = <url_for_file_download> In order to …

java csv spring opencsv

5
推荐指数
1
解决办法
2万
查看次数

端到端响应式流 RESTful 服务

我已经阅读了这篇文章,我不知道这是否是一个愚蠢的问题。我是反应式编程的新手。

问题很简单:假设我有一个完全反应式的后端,我怎样才能流式传输到浏览器(例如一个大文本),并在每个块来自服务器时立即将它们打印给用户?

可能我遗漏了一些重要的概念点,但我需要知道的是:我可以通过一个 HTTP GET(?或不)请求发送一小部分数据(从服务器到浏览器)吗?关键是:我可以写那些小部分,直到全部数据发送出去吗?

谢谢你的帮助。我之前确实尝试过 google,但我总是得到有关其他概念(如 websockets、长轮询、react.js)的信息,我认为情况并非如此。

编辑:我不是要求特定的 API ou 库。我只是想理解这个概念,例如:“你不能用 HTTP 协议做到这一点,句号!” 或“这与响应式编程无关,您对流的真正含义感到困惑。请参阅'something_else.js'”。

EDIT2:我使用 spring-mvc (spring-boot) 和这个方法做了一个小的休息控制器:

@RequestMapping(value = "/flush", method = RequestMethod.GET)
public void flushTest(HttpServletResponse response) {

    response.setContentType("text/html");
    response.setStatus(SC_OK);

    try (ServletOutputStream outputStream = response.getOutputStream()) {
        for (int i = 0; i < 3; i++) {
            String chunk = "chunk_" + i;
            outputStream.print(chunk);
            outputStream.flush();
            response.flushBuffer();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

}
Run Code Online (Sandbox Code Playgroud)

在浏览器中,即使使用了flushBuffer,也只有整个响应到达。经过一番研究,这可能是一个 TOMCAT 问题,我改变了我的 pom.xml,包括 undertow:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

使用默认配置:

server.undertow.accesslog.enabled=true
server.undertow.accesslog.dir=target/logs …
Run Code Online (Sandbox Code Playgroud)

java reactive-programming rxjs

4
推荐指数
1
解决办法
2838
查看次数