rpc: Set HTTP Content-Type in bitcoin-cli #20055

pull laanwj wants to merge 1 commits into bitcoin:master from laanwj:2020_10_cli_contenttype changing 1 files +1 −0
  1. laanwj commented at 3:35 PM on October 1, 2020: member

    We don't set any Content-Type in the client. It is more consistent with our other JSON-RPC use to set it to application/json.

    Note that our server doesn't enforce content types, so it doesn't make a difference in practice. But it is fairly strange HTTP behavior to not set it at all for a POST request.

    This came up in #18950.

  2. rpc: Set HTTP Content-Type in bitcoin-cli
    We don't set any `Content-Type` in the client. It is more
    consistent with our other JSON-RPC use to set it to `application/json`.
    
    Note that our server doesn't enforce content types, so it doesn't make a
    difference in practice. But it is fairly strange HTTP behavior to not set it.
    
    This came up in #18950.
    7eab781a14
  3. laanwj added the label RPC/REST/ZMQ on Oct 1, 2020
  4. promag commented at 3:39 PM on October 1, 2020: member

    Note that our server doesn't enforce content types

    Should?

  5. practicalswift commented at 4:04 PM on October 1, 2020: contributor

    Concept ACK

  6. laanwj commented at 4:08 PM on October 1, 2020: member

    Should?

    As it would be an interface change that affects any applications that mimicked previous -cli behavior, or followed the (strange) advice to set text/plain content type, I don't really think that's a good idea. It seems unnecessary.

  7. practicalswift commented at 5:50 PM on October 1, 2020: contributor

    ACK 7eab781a145a35d0373c4ab4d237a82b4919e88d: patch looks correct

  8. jonatack commented at 6:20 PM on October 1, 2020: member

    This makes sense.

    Tested ACK 7eab781a145a35d0373c4ab4d237a82b4919e88d

  9. jonatack commented at 6:27 PM on October 1, 2020: member

    (Should the RPC helps content type be updated? In practice it doesn't seem to make much difference except what is seen in the server header: text/plain, application/json, or when no content type is specified, application/x-www-form-urlencoded)

  10. laanwj commented at 6:52 PM on October 1, 2020: member

    Should the RPC helps content type be updated? I

    Are we mentioning that anywhere?

  11. jonatack commented at 6:54 PM on October 1, 2020: member

    ISTM all the help examples ATM say -H 'content-type: text/plain;' for the curl.

  12. kristapsk commented at 7:14 PM on October 1, 2020: contributor

    Isn't these just extra bytes transferred without any benefit? It's not that somebody will use bitcoin-cli against anything else than Bitcoin Core, so there isn't any need to care about "fairly strange HTTP behaviors" IMO.

  13. practicalswift commented at 7:39 PM on October 1, 2020: contributor

    Isn't these just extra bytes transferred without any benefit?

    I think it makes sense to pass Content-Type consistently in all our code.

    From the spec FWIW: "Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource. If the media type remains unknown, the recipient SHOULD treat it as type "application/octet-stream"."

    It's not that somebody will use bitcoin-cli against anything else than Bitcoin Core, so there isn't any need to care about "fairly strange HTTP behaviors" IMO.

    I can think of testing scenarios where one would like to run bitcoin-cli against something other than Bitcoin Core (such as against a fuzzing HTTP server) :)

  14. promag commented at 7:44 PM on October 1, 2020: member

    ACK 7eab781a145a35d0373c4ab4d237a82b4919e88d. @laanwj on the server we could check if content type header is valid iff is set.

  15. laanwj closed this on Oct 1, 2020

  16. laanwj commented at 9:08 PM on October 1, 2020: member

    Isn't these just extra bytes transferred without any benefit? It's not that somebody will use bitcoin-cli against anything else than Bitcoin Core, so there isn't any need to care about "fairly strange HTTP behaviors" IMO.

    Well if you're worried about a few extra bytes being transferred locally have it your way I guess, closign …

  17. laanwj commented at 9:12 PM on October 1, 2020: member

    ISTM all the help examples ATM say -H 'content-type: text/plain;' for the curl.

    That's a kind of bad suggestion, thanks for telling me where it comes from though. Not sure it's worth changing, it's okay, it doesn't really affect anything.

  18. promag commented at 9:12 PM on October 1, 2020: member

    @laanwj I think you closed by accident, they should put more space between those buttons. @kristapsk this is clearly the right thing to do as a JSON-RPC over HTTP client.

  19. sipa commented at 9:13 PM on October 1, 2020: member

    Yeah, I also don't understand why this was closed.

    Concept ACK

  20. laanwj commented at 9:21 PM on October 1, 2020: member

    @laanwj I think you closed by accident, they should put more space between those buttons.

    Because I don't really feel like having an argument about a one-line change that I thought was fairly obvious. I noticed this was off, and we can make this change or not, but if people think it's controversial I'm sure there's more important things.

  21. practicalswift commented at 6:20 AM on October 2, 2020: contributor

    Please consider re-opening.

    Review comments should only be considered to they extent they have technical merit.

    A single semi-negative comment does not necessarily make a change "controversial" :)

  22. fanquake reopened this on Oct 2, 2020

  23. promag commented at 7:17 AM on October 2, 2020: member

    ACK

  24. fanquake approved
  25. fanquake commented at 7:24 AM on October 2, 2020: member

    ACK 7eab781a145a35d0373c4ab4d237a82b4919e88d - Looks fine to me.

  26. fanquake merged this on Oct 2, 2020
  27. fanquake closed this on Oct 2, 2020

  28. kallewoof commented at 8:24 AM on October 2, 2020: member

    Post-merge utACK

  29. Fabcien referenced this in commit 32be44adf4 on Nov 3, 2021
  30. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me