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

bug: RPC endpoint returns text/html as content type #1783

Closed
jakubgs opened this issue Jun 7, 2023 · 7 comments · Fixed by #1802
Closed

bug: RPC endpoint returns text/html as content type #1783

jakubgs opened this issue Jun 7, 2023 · 7 comments · Fixed by #1802
Assignees
Labels
bug Something isn't working

Comments

@jakubgs
Copy link
Contributor

jakubgs commented Jun 7, 2023

Problem

RPC endpoint sets Content-Type: text/html; charset=utf-8 when returning a JSON response.

Impact

Ansible 2.13 - or more exactly uri module - is more strict about HTTP response content types, and I no longer get the actual JSON response when I query the RPC API using uri task;
https://github.com/status-im/infra-role-nim-waku/blob/eed1a10ccea90c3b33af845ba54334530467a625/tasks/query.yml#L7-L19

To reproduce

Just query the RPC:

< HTTP/1.1 200 OK
< Server: nim-json-rpc
< Content-Length: 653
< Content-Type: text/html; charset=utf-8
< Date: Wed, 07 Jun 2023 13:15:58 GMT
< Connection: keep-alive
< 
{ [653 bytes data]
* Connection #0 to host localhost left intact
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
...

Expected behavior

The go-waku node does this correctly:

< HTTP/1.1 200 OK
< Content-Type: application/json; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Wed, 07 Jun 2023 13:17:38 GMT
< Content-Length: 1228
< 
{ [1228 bytes data]
* Connection #0 to host localhost left intact
{
  "result": {
...

nwaku version/commit hash

[email protected]:~ % /docker/nim-waku-v2/rpc.sh get_waku_v2_debug_v1_version
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "nightly-2-gba8ec7"
}
@jakubgs jakubgs added bug Something isn't working track:maintenance labels Jun 7, 2023
@Ivansete-status
Copy link
Collaborator

Ivansete-status commented Jun 7, 2023

Edited: the next comment is incorrect.

Afternoon @jakubgs,

Checking the nwaku code I don't see any place where the Content-Type is enforced.

However, I've noticed that the Content-Type present in the response is exactly the same as the one given in the request:

e.g.:
image


What if we add the next snippet in https://github.com/status-im/infra-role-nim-waku/blob/eed1a10ccea90c3b33af845ba54334530467a625/tasks/query.yml#L10 ?

headers:
      Content-Type: "application/json; charset=utf-8"

@jakubgs
Copy link
Contributor Author

jakubgs commented Jun 7, 2023

I already do that:

[email protected]:~ % tail -n10 /docker/nim-waku-v2/rpc.sh 
# The jq script checks if error exists and adjusts exit code.
curl --request POST \
    --verbose \
    --silent \
    --show-error \
    --fail-with-body \
    --header 'Content-type:application/json' \
    --data "${PAYLOAD}" \
    "${URL}" | \
    jq -e '., if .error != null then null|halt_error(2) else halt end'

[email protected]:~ % /docker/nim-waku-v2/rpc.sh get_waku_v2_debug_v1_version
*   Trying 127.0.0.1:8545...
* Connected to localhost (127.0.0.1) port 8545 (#0)
> POST / HTTP/1.1
> Host: localhost:8545
> User-Agent: curl/7.81.0
> Accept: */*
> Content-type:application/json
> Content-Length: 93
> 
} [93 bytes data]
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: nim-json-rpc
< Content-Length: 55
< Content-Type: text/html; charset=utf-8
< Date: Wed, 07 Jun 2023 13:56:13 GMT
< Connection: keep-alive
< 
{ [55 bytes data]
* Connection #0 to host localhost left intact
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "nightly-2-gba8ec7"
}

Doesn't work.

@jakubgs
Copy link
Contributor Author

jakubgs commented Jun 7, 2023

Also, doesn't work for Ansible either. Already tried that, since it was an obvious thing to test.

@Ivansete-status
Copy link
Collaborator

Ok, please ignore my last comment. It actually returns the type "text/html" too.

@vpavlin
Copy link
Member

vpavlin commented Jun 7, 2023

Looking at the json_rpc implementation (https://github.com/status-im/nim-json-rpc) I don't see a way to explicitly enforce headers (neither in server setup nor in method execution) which is kinda weird cause returning JSON as text/html is definitelly a problem

@Ivansete-status
Copy link
Collaborator

I think I saw what needs to be changed. I'll submit the PR to that repo shortly.

@Ivansete-status
Copy link
Collaborator

We'll need to get this merged and then, update the submodule accordingly in nwaku.
status-im/nim-json-rpc#165

Sorry for the previous confusion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
3 participants