From: Rodrigo Morales <rodrigo-mailing-lists@morales.pe>
To: Bruno Barbier <brubar.cs@gmail.com>, <emacs-orgmode@gnu.org>
Subject: Re: Why Emacs shows ^M at the end of some lines in sh code blocks that use curl?
Date: Fri, 18 Oct 2024 18:44:56 -0500 [thread overview]
Message-ID: <87y12lc6x3.fsf@morales.pe> (raw)
In-Reply-To: <67115424.df0a0220.20f4.03e0@mx.google.com>
Bruno Barbier <brubar.cs@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
prev parent reply other threads:[~2024-10-18 23:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-17 15:05 Why Emacs shows ^M at the end of some lines in sh code blocks that use curl? Rodrigo Morales
2024-10-17 18:14 ` Bruno Barbier
2024-10-18 23:44 ` Rodrigo Morales [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y12lc6x3.fsf@morales.pe \
--to=rodrigo-mailing-lists@morales.pe \
--cc=brubar.cs@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).