Skip to content

Commit 0801f79

Browse files
committed
Merge branch 'master' of github.com:ahmadnassri/httpsnippet
2 parents 81afac9 + a03e24d commit 0801f79

12 files changed

Lines changed: 27 additions & 35 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ See it in action on companion service: [APIembed](https://apiembed.com/)
1111
[![Code Climate][codeclimate-quality]][codeclimate-url]
1212
[![Coverage Status][codeclimate-coverage]][codeclimate-url]
1313
[![Dependencies][david-image]][david-url]
14+
[![Gitter][gitter-image]][gitter-url]
1415

1516
## Install
1617

@@ -213,3 +214,6 @@ For more information on SemVer, please visit <http://semver.org/>.
213214

214215
[david-url]: https://david-dm.org/Mashape/httpsnippet
215216
[david-image]: https://img.shields.io/david/Mashape/httpsnippet.svg?style=flat-square
217+
218+
[gitter-url]: https://gitter.im/Mashape/httpsnippet
219+
[gitter-image]: https://img.shields.io/badge/Gitter-Join%20Chat-blue.svg?style=flat-square

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.16.0",
2+
"version": "1.16.2",
33
"name": "httpsnippet",
44
"description": "HTTP Request snippet generator for *most* languages",
55
"author": "Ahmad Nassri <ahmad@mashape.com> (https://www.mashape.com/)",

‎src/targets/ocaml/cohttp.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ module.exports = function (source, options) {
3030
// Add headers, including the cookies
3131
var headers = Object.keys(source.allHeaders)
3232

33-
if (headers.length) {
34-
code.push('let headers = Header.init ()')
33+
if (headers.length === 1) {
34+
code.push('let headers = Header.add (Header.init ()) "%s" "%s" in', headers[0], source.allHeaders[headers[0]])
35+
} else if (headers.length > 1) {
36+
code.push('let headers = Header.add_list (Header.init ()) [')
3537

3638
headers.map(function (key) {
37-
code.push(1, '|> fun h -> Header.add h "%s" "%s"', key, source.allHeaders[key])
39+
code.push(1, '("%s", "%s");', key, source.allHeaders[key])
3840
})
3941

40-
code.push('in')
42+
code.push('] in')
4143
}
4244

4345
// Add body

‎test/fixtures/output/ocaml/cohttp/application-form-encoded.ml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ open Cohttp
33
open Lwt
44

55
let uri = Uri.of_string "http://mockbin.com/har" in
6-
let headers = Header.init ()
7-
|> fun h -> Header.add h "content-type" "application/x-www-form-urlencoded"
8-
in
6+
let headers = Header.add (Header.init ()) "content-type" "application/x-www-form-urlencoded" in
97
let body = Cohttp_lwt_body.of_string "foo=bar&hello=world" in
108

119
Client.call ~headers ~body `POST uri

‎test/fixtures/output/ocaml/cohttp/application-json.ml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ open Cohttp
33
open Lwt
44

55
let uri = Uri.of_string "http://mockbin.com/har" in
6-
let headers = Header.init ()
7-
|> fun h -> Header.add h "content-type" "application/json"
8-
in
6+
let headers = Header.add (Header.init ()) "content-type" "application/json" in
97
let body = Cohttp_lwt_body.of_string "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}]}" in
108

119
Client.call ~headers ~body `POST uri

‎test/fixtures/output/ocaml/cohttp/cookies.ml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ open Cohttp
33
open Lwt
44

55
let uri = Uri.of_string "http://mockbin.com/har" in
6-
let headers = Header.init ()
7-
|> fun h -> Header.add h "cookie" "foo=bar; bar=baz"
8-
in
6+
let headers = Header.add (Header.init ()) "cookie" "foo=bar; bar=baz" in
97

108
Client.call ~headers `POST uri
119
>>= fun (res, body_stream) ->

‎test/fixtures/output/ocaml/cohttp/full.ml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ open Cohttp
33
open Lwt
44

55
let uri = Uri.of_string "http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value" in
6-
let headers = Header.init ()
7-
|> fun h -> Header.add h "cookie" "foo=bar; bar=baz"
8-
|> fun h -> Header.add h "accept" "application/json"
9-
|> fun h -> Header.add h "content-type" "application/x-www-form-urlencoded"
10-
in
6+
let headers = Header.add_list (Header.init ()) [
7+
("cookie", "foo=bar; bar=baz");
8+
("accept", "application/json");
9+
("content-type", "application/x-www-form-urlencoded");
10+
] in
1111
let body = Cohttp_lwt_body.of_string "foo=bar" in
1212

1313
Client.call ~headers ~body `POST uri

‎test/fixtures/output/ocaml/cohttp/headers.ml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ open Cohttp
33
open Lwt
44

55
let uri = Uri.of_string "http://mockbin.com/har" in
6-
let headers = Header.init ()
7-
|> fun h -> Header.add h "accept" "application/json"
8-
|> fun h -> Header.add h "x-foo" "Bar"
9-
in
6+
let headers = Header.add_list (Header.init ()) [
7+
("accept", "application/json");
8+
("x-foo", "Bar");
9+
] in
1010

1111
Client.call ~headers `GET uri
1212
>>= fun (res, body_stream) ->

‎test/fixtures/output/ocaml/cohttp/multipart-data.ml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ open Cohttp
33
open Lwt
44

55
let uri = Uri.of_string "http://mockbin.com/har" in
6-
let headers = Header.init ()
7-
|> fun h -> Header.add h "content-type" "multipart/form-data; boundary=---011000010111000001101001"
8-
in
6+
let headers = Header.add (Header.init ()) "content-type" "multipart/form-data; boundary=---011000010111000001101001" in
97
let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001--" in
108

119
Client.call ~headers ~body `POST uri

‎test/fixtures/output/ocaml/cohttp/multipart-file.ml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ open Cohttp
33
open Lwt
44

55
let uri = Uri.of_string "http://mockbin.com/har" in
6-
let headers = Header.init ()
7-
|> fun h -> Header.add h "content-type" "multipart/form-data; boundary=---011000010111000001101001"
8-
in
6+
let headers = Header.add (Header.init ()) "content-type" "multipart/form-data; boundary=---011000010111000001101001" in
97
let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--" in
108

119
Client.call ~headers ~body `POST uri

0 commit comments

Comments
 (0)