Skip to content

PoC: streaming response in ProxyResource - #857

Open
netwarex wants to merge 1 commit into
devfrom
f-proxy-stream
Open

PoC: streaming response in ProxyResource#857
netwarex wants to merge 1 commit into
devfrom
f-proxy-stream

Conversation

@netwarex

@netwarex netwarex commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Add streaming output for response body in ProxyResource.

Change vs. stock: forward() returns a StreamingOutput that copies the upstream response with a flush() after every read instead of handing Jersey the raw InputStream (which is copied without any flush, so the bytes sit in Jetty's 32KB output buffer until the response completes). With jersey.config.server.contentLength.buffer=0 active, each flush goes straight to the socket, so proxied responses (GenAIx generations) stream live and nginx's proxy_read_timeout is reset per frame. Also releases the commons-httpclient connection when the copy ends (stock code leaked it) and adds an X-Proxy-Streaming marker header so the patch's presence is verifiable.

Add streaming output for response body in ProxyResource.
}
return responseBuilder.entity(method.getResponseBodyAsStream()).build();

responseBuilder.header("X-Proxy-Streaming", "1");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marker: lets callers verify the streaming patch is loaded

return responseBuilder.build();
}

StreamingOutput streamingBody = output -> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy the upstream body chunk by chunk, flushing after every read so each chunk reaches the socket immediately instead of accumulating in the servlet output buffer until the upstream response completes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant