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

Provide option to use --data-binary instead of -d/--data #59

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ To use =ob-http= in an =org-babel= source block, the http language must be enabl
| =:get-header= | N/A | =:get-header X-Subject-Token= |
| =:curl= | N/A | =:curl --insecure --compressed= additional arguments for curl |
| =:resolve= | =--resolve= | =:resolve example.com:80:127.0.0.1,example.com:443:127.0.0.1= |
| =:data-binary= | =--data-binary= | Use =--data-binary= instead of =--data= in the curl command |

** examples

Expand Down Expand Up @@ -156,6 +157,7 @@ supported headers:
- port
- user
- max-time
- data-binary

: * api test
: :PROPERTIES:
Expand Down Expand Up @@ -196,3 +198,36 @@ supported headers:
: #+RESULTS:
: [[file:zweifisch.jpeg]]


other data payloads

: #+BEGIN_SRC http :data-binary
: POST http://httpbin.org/post
: Content-Type: application/octet-stream
:
: lots
: of
: line breaks
: and insignificant=punctuation
: #+END_SRC
:
: #+RESULTS:
: #+begin_example
: {
: "args": {},
: "data": "lots\nof\nline breaks\nand insignificant=punctuation",
: "files": {},
: "form": {},
: "headers": {
: "Accept": "*/*",
: "Content-Length": "48",
: "Content-Type": "application/octet-stream",
: "Host": "httpbin.org",
: "User-Agent": "curl/7.87.0",
: "X-Amzn-Trace-Id": "Root=1-6449b5bf-1e5eac452e4393943dce4a61"
: },
: "json": null,
: "origin": "44.237.72.92",
: "url": "http://httpbin.org/post"
: }
: #+end_example
9 changes: 6 additions & 3 deletions ob-http.el
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
(follow-redirect . :any)
(path-prefix . :any)
(resolve . :any)
(max-time . :any))
(max-time . :any)
(data-binary . :any))
"http header arguments")

(defgroup ob-http nil
Expand Down Expand Up @@ -219,6 +220,7 @@
(resolve (cdr (assoc :resolve params)))
(request-body (ob-http-request-body request))
(error-output (org-babel-temp-file "curl-error"))
(binary (assoc :data-binary params))
(args (append ob-http:curl-custom-arguments (list "-i"
(when (and proxy (not noproxy)) `("-x" ,proxy))
(when noproxy '("--noproxy" "*"))
Expand All @@ -230,9 +232,10 @@
(when (assoc :user params) `("--user" ,(cdr (assoc :user params))))
(mapcar (lambda (x) `("-H" ,x)) (ob-http-request-headers request))
(when (s-present? request-body)
(let ((tmp (org-babel-temp-file "http-")))
(let ((tmp (org-babel-temp-file "http-"))
(data-opt (if binary "--data-binary" "--data")))
(with-temp-file tmp (insert request-body))
`("-d" ,(format "@%s" tmp))))
(list data-opt (format "@%s" tmp))))
(when cookie-jar `("--cookie-jar" ,cookie-jar))
(when cookie `("--cookie" ,cookie))
(when resolve (mapcar (lambda (x) `("--resolve" ,x)) (split-string resolve ",")))
Expand Down