Skip to content

Let devs choose the handler for http requests - #60167

Merged
DaphneMuller merged 1 commit into
masterfrom
enh/noid/allow-http-progressive-stream-response
Jun 3, 2026
Merged

Let devs choose the handler for http requests#60167
DaphneMuller merged 1 commit into
masterfrom
enh/noid/allow-http-progressive-stream-response

Conversation

@julien-nc

@julien-ncjulien-nc commented May 5, 2026

Copy link
Copy Markdown
Member

So they can choose a stream handler for example.

Summary

When using the 'stream' => true request option with IClient, the response body is a resource but its content is written all at once when the request is done.
This happens because the use of the CurlHandler is hardcoded in https://github.com/nextcloud/server/blob/fb67d5d/lib/private/Http/Client/ClientService.php#L44
The Curlhandler makes a blocking call to curl_exec which executes the request synchronously.

To allow progressive streamed responses, we need:

  • to use HTTP 1/*
  • to allow guzzle to use the StreamHandler

This is just a PoC. I have no idea if it's the right thing to do.
Wdyt?

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@julien-ncjulien-nc added this to the Nextcloud 34 milestone May 5, 2026
@julien-nc
julien-ncforce-pushed the enh/noid/allow-http-progressive-stream-response branch from 6eeca81 to 9c49a16CompareMay 7, 2026 12:23
Comment threadlib/private/Http/Client/ClientService.php Outdated
@julien-nc
julien-ncforce-pushed the enh/noid/allow-http-progressive-stream-response branch from 9c49a16 to 5ff2e04CompareMay 11, 2026 10:34
@julien-nc
julien-nc marked this pull request as ready for review May 11, 2026 10:46
@julien-nc
julien-nc requested a review from a team as a code ownerMay 11, 2026 10:46
@julien-nc
julien-nc requested review from CarlSchwan, leftybournes, provokateurin and salmart-dev and removed request for a teamMay 11, 2026 10:46
@julien-nc
julien-ncforce-pushed the enh/noid/allow-http-progressive-stream-response branch from 5ff2e04 to 6419d53CompareMay 11, 2026 10:47
@provokateurin

Copy link
Copy Markdown
Member

Have you tried if it works?

@julien-nc

julien-nc commented May 11, 2026

Copy link
Copy Markdown
MemberAuthor

@provokateurin Yes, it is used in a WIP branch https://github.com/nextcloud/integration_openai/blob/enh/noid/streaming/lib/TaskProcessing/TextToTextProvider.php#L131-L137 . The output of the task processing task is progressively echoed to stdout.

There also are standalone scripts to test that. With the enh/noid/streaming branch of integration_openai, you can run:

  • php -S 127.0.0.1:8088 apps-extra/integration_openai/tests/stream_i_client_sse_server.php that spawns a simple HTTP server returning a SSE stream.
  • php apps-extra/integration_openai/tests/stream_i_client_repro.php http://127.0.0.1:8088/chat/completions that specifically tests the HTTP client's behaviour with 'stream' => true

You can try running those on server's main and on this PR's branch to see the difference. Spoiler, with this branch, the client progressively writes in the resource.

@julien-nc
julien-ncforce-pushed the enh/noid/allow-http-progressive-stream-response branch from 6419d53 to 6282e96CompareMay 18, 2026 10:03
@julien-ncjulien-nc changed the title [WIP] Let guzzle choose the handler for http requestsLet guzzle choose the handler for http requestsMay 18, 2026
@julien-nc
julien-ncforce-pushed the enh/noid/allow-http-progressive-stream-response branch 2 times, most recently from c7fdc8e to 4db6dc2CompareMay 27, 2026 11:10
@nextcloud-botnextcloud-bot mentioned this pull request May 27, 2026
@julien-nc
julien-ncforce-pushed the enh/noid/allow-http-progressive-stream-response branch from 4db6dc2 to b715faaCompareMay 28, 2026 14:39
@julien-nc
julien-ncforce-pushed the enh/noid/allow-http-progressive-stream-response branch 2 times, most recently from 94d24ee to a4638e2CompareJune 3, 2026 11:14
@julien-ncjulien-nc changed the title Let guzzle choose the handler for http requestsLet devs choose the handler for http requestsJun 3, 2026
Comment threadlib/public/Http/Client/IClientService.php Outdated
… a new client
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
@julien-nc
julien-ncforce-pushed the enh/noid/allow-http-progressive-stream-response branch from a4638e2 to 04dc699CompareJune 3, 2026 12:14
@DaphneMuller
DaphneMuller merged commit faa78c8 into masterJun 3, 2026
175 of 178 checks passed
@DaphneMuller
DaphneMuller deleted the enh/noid/allow-http-progressive-stream-response branch June 3, 2026 14:24
@nextcloud-botnextcloud-bot mentioned this pull request Aug 11, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2. developingWork in progressenhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@julien-nc@provokateurin@marcelklehr@CarlSchwan@DaphneMuller