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

Keep trailing newlines in POST request #52

Open
geolessel opened this issue Mar 24, 2021 · 2 comments
Open

Keep trailing newlines in POST request #52

geolessel opened this issue Mar 24, 2021 · 2 comments

Comments

@geolessel
Copy link

geolessel commented Mar 24, 2021

Hi and thanks for the great package!

I've been using org-mode and ob-http to learn Elasticsearch. One of the endpoints allows a submission of Content-Type: application/x-ndjson and requires an final newline in the request body. However, no matter how many newlines I enter into the source block, I keep getting the same error that it needs a trailing newline. It would be great to have an option to retain trailing newlines (or at least add one on execution).

An example of one of my requests:

#+begin_src http
  POST ${host}/_bulk
  Content-Type: application/x-ndjson

  {"create": {"_index": "products", "_id": 201}}
  {"name": "Milk Frother", "price": 149, "in_stock": 14}

  


  
#+end_src
@eddsteel
Copy link

eddsteel commented Apr 26, 2023

From the curl manpage:

       -d, --data <data>
              ...
              If  you  start  the data with the letter @, the rest should be a
              file name to read the data from, or - if you want curl  to  read
              the  data  from  stdin.  Posting data from a file named 'foobar'
              would thus be done with -d, --data @foobar. When -d,  --data  is
              told  to  read  from a file like that, carriage returns and new‐
              lines will be stripped out. If you do not want the  @  character
              to have a special interpretation use --data-raw instead.
              ...
       --data-binary <data>
              (HTTP)  This  posts data exactly as specified with no extra pro‐
              cessing whatsoever.

              If you start the data with the letter @, the rest  should  be  a
              filename. Data is posted in a similar manner as -d, --data does,
              except that newlines and carriage returns are preserved and con‐
              versions are never done.

The generated curl command uses -d. I think it would be a safer option to use --data-binary, though it might be nice to allow both with an option.

@eddsteel
Copy link

I thought about it and default curl behaviour (as well as the README example) is to assume form data. So I made a PR to add a new option --data-binary. #59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants