Bruno Barbier <brubar...@gmail.com> writes: > it's not related to Org (HTTP headers use '\r\n', your JSON
Thanks for pointing me in the right direction. I searched related information on the Internet and I found out there is an specific section in Request for Comments (RFC2616) that explicitly states that '\r\n' should be used as the line break for HTTP headers. I learned this from https://stackoverflow.com/a/5757349 > You could include a translation step. For example, using 'tr': > > #+begin_src shell :results raw > curl --include --silent > https://filesampleshub.com/download/code/json/sample1.json | tr -d '\r' > #+end_src > > If you are fetching arbitrary data, you do not want to do that though. > You may ask curl to dump the headers in a file, and translate only > that file (using --dump-header). I agree with you on not using tr -d '\r' for both the response body and the response headers. Starting from now, when I feel the need to show the response headers in my notes, I'll dump the headers to a file and then show pass that file to 'tr' as shown below: #+begin_src sh curl --dump-header /tmp/curl-header.txt --silent --request GET 'https://filesampleshub.com/download/code/json/sample1.json' echo '----' cat /tmp/curl-header.txt | tr -d '\r' #+end_src #+RESULTS: #+begin_example { "fear": "quiet", "chest": -1477429467, "how": false, "graph": false, "camp": 929234312, "plural": "settle" }---- HTTP/2 200 accept-ranges: bytes access-control-allow-origin: * age: 3641498 cache-control: public, max-age=0, must-revalidate content-disposition: inline; filename="sample1.json" content-type: application/json; charset=utf-8 date: Fri, 18 Oct 2024 22:43:39 GMT etag: "c4b4a9669841a9ab437f5dce6c9c9230" last-modified: Fri, 06 Sep 2024 19:12:01 GMT server: Vercel strict-transport-security: max-age=63072000 x-matched-path: /download/code/json/sample1.json x-vercel-cache: HIT x-vercel-id: gru1::9cdc6-1729291419743-bcee78204a79 content-length: 136 #+end_example Sometimes when I want to focus on the behavior of an API and don't write such long command due to that technical detail, I could simply use restclient. See example below (in my system, the header lines shown by restclient don't show the ^M character) #+begin_src restclient GET https://filesampleshub.com/download/code/json/sample1.json #+end_src #+RESULTS: #+BEGIN_SRC js { "fear": "quiet", "chest": -1477429467, "how": false, "graph": false, "camp": 929234312, "plural": "settle" } // GET https://filesampleshub.com/download/code/json/sample1.json // HTTP/1.1 200 OK // Accept-Ranges: bytes // Access-Control-Allow-Origin: * // Age: 3641582 // Cache-Control: public, max-age=0, must-revalidate // Content-Disposition: inline; filename="sample1.json" // Content-Length: 136 // Content-Type: application/json; charset=utf-8 // Date: Fri, 18 Oct 2024 22:45:03 GMT // Etag: "c4b4a9669841a9ab437f5dce6c9c9230" // Last-Modified: Fri, 06 Sep 2024 19:12:01 GMT // Server: Vercel // Strict-Transport-Security: max-age=63072000 // X-Matched-Path: /download/code/json/sample1.json // X-Vercel-Cache: HIT // X-Vercel-Id: gru1::4ktmb-1729291503557-396fe6c0ce31 // Request duration: 0.258368s #+END_SRC