-
Notifications
You must be signed in to change notification settings - Fork 7
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
Set request Content-Type to application/json #8
Conversation
In order to be compliant with the version 2 of the API. It is still compatible with the version 1.
Hey @richie3366 thanks for the PR! The change itself LGTM but we'll need to fix up the rpc tests. Having had a quick look at the output, I think nock is probably pre-parsing the body as json given the changed content-type, resulting in |
The only workaround I found (even after searching for a way to get the raw body with nock) was to use var contentLength = Buffer.byteLength(JSON.stringify(requestBody), 'utf8');
expect(request.headers['content-length']).to.equal(contentLength); It works well, but I don't know if it is a legit & safe way to test it. EDIT .reply(200, function(uri, reqBody) {
// Store the request object & body to assert about later.
request = this.req;
requestBody = JSON.stringify(reqBody)
return jsonRpcResponse;
}); |
@richie3366 Sorry for the delay in getting back to you - I just took a look through the nock codebase and, yeah, it seems that we can't easily get access to the raw body. I think in this instance let's go with your first suggestion to Thanks for your help with this! |
No worries about the delay, I'm using my fork until PR is merged. I hope that it's all good to go. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change but ready to merge after that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Legend, thanks very much for the change & iterations!
Pushed this out as v1.1.0 |
In order to be compliant with the version 2 of the API (see https://api.random.org/json-rpc/2/fundamentals).
It is still compatible with the version 1 (see https://api.random.org/json-rpc/1/introduction).