ducaale / xh

Friendly and fast tool for sending HTTP requests
MIT License
4.96k stars 90 forks source link

Equivalent command to curl -d #341

Closed nkh closed 6 months ago

nkh commented 6 months ago

Hi, I'm trying to replace he following curl command with an xh command.

curl localhost:4266 -d "put(x)" 

I've tried

xh :4266 --raw 'put(x)'

but I get

xh: error: error sending request for url (http://localhost:4266/): connection closed before message completed

Caused by:
    connection closed before message completed

while curl succeeds.

ducaale commented 6 months ago

The only difference between the two commands I could think of is the content-type header. Could you try using the --form option to set the content-type to application/x-www-form-urlencoded?

xh :4266 --raw 'put(x)' --form
nkh commented 6 months ago

@ducaale that gives the same result

FYI: the sequence is send to fzf --listen 4266

blyxxyz commented 6 months ago

fzf implements its own HTTP server that seems to have some odd behavior even if I just talk to it with netcat.

The request notably does work (on my machine). fzf does what it's told. But xh doesn't like it when fzf unceremoniously closes the connection thinks the response ends too early.

This is almost certainly a fzf bug, though a nitpicky one that they may or may not be interested in fixing.

nkh commented 6 months ago

@blyxxyz It indeed does do what it's told to do.

I'll report it to the fzf project.

blyxxyz commented 6 months ago

OK, I found the problem. fzf's response is missing a CRLF after the header section. It should send HTTP/1.1 200 OK\r\n\r\n but it only sends HTTP/1.1 200 OK\r\n. Most HTTP implementations don't seem to mind but hyper is very pedantic.

I've submitted a PR: https://github.com/junegunn/fzf/pull/3542

Nice find!