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

Octet-stream response bodies should be decoded to a hex Buffer #1021

Closed
kevinburke opened this issue Nov 16, 2017 · 3 comments
Closed

Octet-stream response bodies should be decoded to a hex Buffer #1021

kevinburke opened this issue Nov 16, 2017 · 3 comments

Comments

@kevinburke
Copy link

I have a server that responds with binary data and an octet-stream header:

$ http POST localhost:4249/v1/sign 'data=aGVsbG8gd29ybGQ='
HTTP/1.1 200 OK
Content-Length: 64
Content-Type: application/octet-stream
Date: Thu, 16 Nov 2017 05:04:11 GMT
Server: signing-server/0.1
X-Request-Duration: 141 µs

�̰3郞�W�5-��)�Z��`�׋�l����Ʃ2 ���n�|qu��<�4>

The response is a Buffer, so nock converts it to hex before storing in a file. I've truncated the response here and above, but it should be enough to get the idea.

    {
        "scope": "http://localhost:4249",
        "method": "POST",
        "path": "/v1/sign",
        "body": {
            "data": "aGVsbG8gd29ybGQ=",
            "name": "WebApp"
        },
        "status": 200,
        "response": "f0ccb033e9839eb657ae352d9bd329cf5a0193e660ded78bcf6cacbf4950acd3c6a9322098f9dc6e9a107c7175c3e83c19c7343e39d91d",
        "rawHeaders": [
            "Content-Type",
            "application/octet-stream",
            "Server",
            "signing-server/0.1",
            "X-Request-Duration",
            "178 µs",
            "Date",
            "Thu, 16 Nov 2017 05:00:17 GMT",
            "Content-Length",
            "64",
            "Connection",
            "close"
        ]
    }

When reading back from the file, I expect it to be converted back into a Buffer via Buffer.from(response.body, 'hex'). Instead it gets converted into a normal Buffer, e.g. the first byte is 'f', the second byte is '0', instead of one byte 0xf0.

I can work around this for the time being by setting Content-Encoding: identity, which triggers the right nock logic. But it would seem preferable to e.g. read the application/octet-stream response header and try to convert from hex based on that.

@gr2m
Copy link
Member

gr2m commented Feb 20, 2018

Hey @kevinburke can you check if #1067 fixes your problem?

@kevinburke
Copy link
Author

Apologies but I've since moved on from that engagement and probably won't have time to test :( best of luck!

A way to test would probably be to start with the JSON I put up above, read it back into memory, and verify the length of the buffer in memory matches the Content-Length header.

@lock
Copy link

lock bot commented Sep 13, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!

@lock lock bot locked as resolved and limited conversation to collaborators Sep 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants