Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--stream does not print entire buffer #273

Open
devunt opened this issue Sep 4, 2022 · 1 comment
Open

--stream does not print entire buffer #273

devunt opened this issue Sep 4, 2022 · 1 comment

Comments

@devunt
Copy link

devunt commented Sep 4, 2022

I'm testing streaming SSR react server with xh, and I found that xh does not display entire response unlike what curl does.

Testing against same endpoint with xh and curl:

~ ❱ xh http://127.0.0.1:3000 --stream
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Type: text/html
Date: Sun, 04 Sep 2022 14:28:37 GMT
Keep-Alive: timeout=72
Transfer-Encoding: chunked

<!DOCTYPE html>
    <html>
      <head>
        <title>hello</title>
        <meta charset="utf-8" />
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, width=device-width" />
      </head>
      <body>
~ ❱ curl http://127.0.0.1:3000 --include
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: text/html
Date: Sun, 04 Sep 2022 14:30:13 GMT
Connection: keep-alive
Keep-Alive: timeout=72
Transfer-Encoding: chunked

<!DOCTYPE html>
    <html>
      <head>
        <title>hello</title>
        <meta charset="utf-8" />
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, width=device-width" />
      </head>
      <body>
~ ❱ curl http://127.0.0.1:3000 --include --no-buffer
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: text/html
Date: Sun, 04 Sep 2022 14:31:16 GMT
Connection: keep-alive
Keep-Alive: timeout=72
Transfer-Encoding: chunked

<!DOCTYPE html>
    <html>
      <head>
        <title>hello</title>
        <meta charset="utf-8" />
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, width=device-width" />
      </head>
      <body>
        <div id="root"><!--$?--><template id="B:0"></template>suspending...<!--/$-->

As you can see, content of the body is printed only when curl is used with --no-buffer parameter.
I can't find xh option equivalent with curl --no-buffer from documentation or source code.

Any help would be appriciated!

@blyxxyz
Copy link
Collaborator

blyxxyz commented Sep 4, 2022

This happens because --stream only shows complete lines, like HTTPie. See httpie/cli#1060

We don't have an option like --no-buffer. Maybe we should.

I see two workarounds:

  1. Send a newline immediately after <div id="root"><!--$?--><template id="B:0"></template>suspending...<!--/$-->. Then curl won't need --no-buffer either.

  2. Pipe the output through cat: xh :3000 --stream --print=hb | cat
    This disables the "smart" line-buffering and just sends everything through as soon as it's received.
    (--print=hb ensures you still see the headers, those are hidden by default when piping.)

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

No branches or pull requests

2 participants