Closed Willyham closed 7 years ago
@Willyham I'm not entirely sure if this is an issue with ThriftRW Node either. The corrupted payload I showed you was what Node saw before it was decoded by ThriftRW.
@kriskowal any ideas?
@Willyham Thanks for the really detailed repro!
I've seen something similar before where the body is converted to a string, which modifies the buffer, and then thriftrw
isn't able to decode it.
I looked into the documentation for request, and found this little nugget:
encoding
- encoding to be used onsetEncoding
of response data. Ifnull
, thebody
is returned as aBuffer
. Anything else (including the default value ofundefined
) will be passed as the encoding parameter totoString()
(meaning this is effectivelyutf8
by default). (Note: if you expect binary data, you should setencoding: null
.)
I tried this out, and set encoding: null
in options
, and the issue is fixed!
const options = {
url: 'http://localhost:8001',
encoding: null,
body: body.value,
headers: {
"Rpc-Caller": 'web',
"Rpc-Encoding": "thrift",
"Rpc-Service": "foo",
"Context-TTL-MS": 5000,
"Rpc-Procedure": "Foo::bar"
}
}
> node test.js
Result of small:
null <Buffer 00 00 00 00 00 00 00 7b>
Result of big:
null <Buffer 14 da db 63 ff b5 b7 52>
Please see https://github.com/thriftrw/thriftrw-go/issues/321
This appears to be an issue with thriftrw-node, though given the test cases I've been able to find, I think the issue could be with me using the library incorrectly. Even if that is the case, some docs to clarify this would be good.
See this archive for a reproducible test case: https://github.com/thriftrw/thriftrw-go/files/1218543/issue.tar.gz