Skip to content

Add --stream option to output HTTP response body as it arrives#123

Merged
WeihanLi merged 4 commits intodevfrom
copilot/fix-7604648-337128585-7d603691-b6e3-4b67-ab7c-0e710515503e
Nov 7, 2025
Merged

Add --stream option to output HTTP response body as it arrives#123
WeihanLi merged 4 commits intodevfrom
copilot/fix-7604648-337128585-7d603691-b6e3-4b67-ab7c-0e710515503e

Conversation

Copy link
Contributor

Copilot AI commented Nov 3, 2025

Implements streaming response output for better UX with long-running requests and streaming APIs. Currently, all responses are buffered until complete before any output is shown.

Changes

Command-line interface:

  • Added --stream / -S option to enable streaming mode
  • Automatically falls back to buffered mode for binary responses and --download flag

Core implementation:

  • RequestExecutor.InvokeStreamingRequest(): Uses HttpCompletionOption.ResponseHeadersRead to start receiving data immediately
  • Outputs response headers once received, then streams body line-by-line to console
  • Respects response encoding from Content-Type header instead of assuming UTF-8
  • HttpResponseModel.Bytes: Changed from init to set to support incremental updates

State tracking:

  • IsStreamingMode flag set when --stream option present
  • StreamingCompleted flag set after successful streaming to skip normal output formatting

Usage

# Stream JSON response
dotnet-http GET https://api.example.com/stream --stream

# Stream with body-only output
dotnet-http GET https://api.example.com/data -S -b

Binary responses and downloads automatically use buffered mode regardless of flag.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • httpbin.org
    • Triggering command: /home/REDACTED/work/dotnet-httpie/dotnet-httpie/tests/HTTPie.IntegrationTest/bin/Debug/net10.0/HTTPie.IntegrationTest --internal-msbuild-node /home/REDACTED/.local/share/eb0b5e397f8d46c597913dcb38a813f7/.p (dns block)
    • Triggering command: /home/REDACTED/work/dotnet-httpie/dotnet-httpie/src/HTTPie/bin/Debug/net10.0/dotnet-httpie GET REDACTED --stream (dns block)
    • Triggering command: /home/REDACTED/work/dotnet-httpie/dotnet-httpie/tests/HTTPie.IntegrationTest/bin/Debug/net10.0/HTTPie.IntegrationTest --internal-msbuild-node /home/REDACTED/.local/share/d5029fa786974acbb89a522699550d97/.p (dns block)
  • reservation.weihanli.xyz
    • Triggering command: /home/REDACTED/work/dotnet-httpie/dotnet-httpie/tests/HTTPie.IntegrationTest/bin/Debug/net10.0/HTTPie.IntegrationTest --internal-msbuild-node /home/REDACTED/.local/share/eb0b5e397f8d46c597913dcb38a813f7/.p (dns block)
    • Triggering command: /home/REDACTED/work/dotnet-httpie/dotnet-httpie/tests/HTTPie.IntegrationTest/bin/Debug/net10.0/HTTPie.IntegrationTest --internal-msbuild-node /home/REDACTED/.local/share/d5029fa786974acbb89a522699550d97/.p (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Stream http response output</issue_title>
<issue_description>Is your feature request related to a problem? Please describe.

Currently, the response will need to wait for response body complete, for streaming response it's not friendly, it would be better to support stream response body, while we may want to ignore the file download or binary responses

Describe the solution you'd like

Stream response body

</issue_description>

Comments on the Issue (you are @copilot in this section)

Note

Custom agent used: dotnet expert
Build amazing things in C#


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Nov 3, 2025
Copilot AI and others added 3 commits November 3, 2025 02:59
Add --stream option to enable streaming response body output as it arrives.
- Add StreamOption to RequestExecutor
- Implement InvokeStreamingRequest method for streaming responses
- Change HttpResponseModel.Bytes from init to set to support streaming
- Add IsStreamingMode flag to track streaming state
- Skip normal output formatting when in streaming mode
- Add unit tests for streaming option recognition

Co-authored-by: WeihanLi <7604648+WeihanLi@users.noreply.github.com>
Add StreamingCompleted flag to track when streaming actually occurred.
Only skip normal output formatting when streaming was actually performed,
not just when the streaming option was present.

Co-authored-by: WeihanLi <7604648+WeihanLi@users.noreply.github.com>
- Use response encoding from Content-Type header instead of hardcoded UTF-8
- Improve error handling in catch block with logging
- Add documentation comment for IsTextResponse behavior

Co-authored-by: WeihanLi <7604648+WeihanLi@users.noreply.github.com>
Copilot AI changed the title [WIP] Stream http response output Add --stream option to output HTTP response body as it arrives Nov 3, 2025
Copilot AI requested a review from WeihanLi November 3, 2025 03:08
@WeihanLi WeihanLi marked this pull request as ready for review November 7, 2025 13:57
@WeihanLi WeihanLi merged commit 7f471bb into dev Nov 7, 2025
10 of 12 checks passed
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.

Stream http response output

2 participants