sindresorhus / got

🌐 Human-friendly and powerful HTTP request library for Node.js
MIT License
14.27k stars 935 forks source link

Not able to post buffer in body #1151

Closed roastedmonk closed 4 years ago

roastedmonk commented 4 years ago

Describe the bug

Actual behavior

receiving server getting buffer in json format as req.body Restify is the server used in the receiving end.

Expected behavior

req.body should be a instance of Buffer. Restify is the server used in the receiving end.

tested with currently depricated request plugin it works fine, but GOT is having this issue.

Code to reproduce


try {
        got(`http://myurl/api/users/user1`, {
            method: 'PUT',
            body: fs.readFileSync('c:\\test.zip')
        });
    } catch(err) {
        throw `Remote update failed : ${err}`;
        }

Checklist

szmarczak commented 4 years ago

Can you set up a RunKit example?

szmarczak commented 4 years ago

Or a reproducible repo?

roastedmonk commented 4 years ago

GOT.zip

Attached the sample code for the same.

Both server & got client code.

szmarczak commented 4 years ago

Your example is incomplete therefore I'm not able to reproduce the issue.

szmarczak commented 4 years ago

I've written a simple test that proves it works as expected: 442be0c78b63b3a1795a74a205be9693fcbeddf6

szmarczak commented 4 years ago

I'll close this issue for housekeeping purposes. Feel free to send a reproducible code so I'll open this issue again. It'd be best if you used plain Node.js HTTP server instead of Restify as I'm not familiar with it.

roastedmonk commented 4 years ago

i raised issue for Buffer not stream. @szmarczak

szmarczak commented 4 years ago

i raised issue for Buffer not stream.

The body? It's a Readable stream in your example, so I followed it.

roastedmonk commented 4 years ago

i raised issue for Buffer not stream.

The body? It's a Readable stream in your example, so I followed it.

image image @szmarczak : this function returns String or Buffer.

szmarczak commented 4 years ago

oh sorry my bad looking into this rn

szmarczak commented 4 years ago

It works as expected and we have a test for that:

https://github.com/sindresorhus/got/blob/bf0b0cde07b6b65b18601aa3f43f976f4150c1f2/test/post.ts#L53-L58

roastedmonk commented 4 years ago

i dont want wow in response, it should be buffer of wow in server.

szmarczak commented 4 years ago

it should be buffer of wow in server

That's not a Got issue. You are responsible for parsing the data.

szmarczak commented 4 years ago

Feel free to experiment around our tests. In that test we just output the received body, so it works as expected.