Skip to content
Merged
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
15 changes: 12 additions & 3 deletions src/targets/shell/curl.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,22 @@ module.exports = function (source, options) {
const opts = Object.assign({
indent: ' ',
short: false,
binary: false
binary: false,
globOff: false
}, options)

const code = new CodeBuilder(opts.indent, opts.indent !== false ? ' \\\n' + opts.indent : ' ')

code.push('curl %s %s', opts.short ? '-X' : '--request', source.method)
.push(util.format('%s%s', opts.short ? '' : '--url ', helpers.quote(source.fullUrl)))
const globOption = opts.short ? '-g' : '--globoff'
const requestOption = opts.short ? '-X' : '--request'
let formattedUrl = helpers.quote(source.fullUrl)

code.push('curl %s %s', requestOption, source.method)
if (opts.globOff) {
formattedUrl = unescape(formattedUrl)
code.push(globOption)
}
code.push(util.format('%s%s', opts.short ? '' : '--url ', formattedUrl))

if (source.httpVersion === 'HTTP/1.0') {
code.push(opts.short ? '-0' : '--http1.0')
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/output/c/libcurl/nested.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value");

CURLcode ret = curl_easy_perform(hnd);
5 changes: 5 additions & 0 deletions test/fixtures/output/clojure/clj_http/nested.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(require '[clj-http.client :as client])

(client/get "http://mockbin.com/har" {:query-params {:foo[bar] "baz,zap"
:fiz "buz"
:key "value"}})
12 changes: 12 additions & 0 deletions test/fixtures/output/csharp/httpclient/nested.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value"),
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}
3 changes: 3 additions & 0 deletions test/fixtures/output/csharp/restsharp/nested.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var client = new RestClient("http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
23 changes: 23 additions & 0 deletions test/fixtures/output/go/native/nested.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"
"net/http"
"io/ioutil"
)

func main() {

url := "http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value"

req, _ := http.NewRequest("GET", url, nil)

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)

fmt.Println(res)
fmt.Println(string(body))

}
4 changes: 4 additions & 0 deletions test/fixtures/output/http/1.1/nested
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
GET /har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value HTTP/1.1
Host: mockbin.com


8 changes: 8 additions & 0 deletions test/fixtures/output/java/asynchttp/nested.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.prepare("GET", "http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();

client.close();
6 changes: 6 additions & 0 deletions test/fixtures/output/java/nethttp/nested.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value"))
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
8 changes: 8 additions & 0 deletions test/fixtures/output/java/okhttp/nested.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
.url("http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value")
.get()
.build();

Response response = client.newCall(request).execute();
2 changes: 2 additions & 0 deletions test/fixtures/output/java/unirest/nested.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
HttpResponse<String> response = Unirest.get("http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value")
.asString();
13 changes: 13 additions & 0 deletions test/fixtures/output/javascript/axios/nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import axios from "axios";

const options = {
method: 'GET',
url: 'http://mockbin.com/har',
params: {'foo[bar]': 'baz,zap', fiz: 'buz', key: 'value'}
};

axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
6 changes: 6 additions & 0 deletions test/fixtures/output/javascript/fetch/nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const options = {method: 'GET'};

fetch('http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
11 changes: 11 additions & 0 deletions test/fixtures/output/javascript/jquery/nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const settings = {
"async": true,
"crossDomain": true,
"url": "http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value",
"method": "GET",
"headers": {}
};

$.ajax(settings).done(function (response) {
console.log(response);
});
14 changes: 14 additions & 0 deletions test/fixtures/output/javascript/xhr/nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const data = null;

const xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
}
});

xhr.open("GET", "http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value");

xhr.send(data);
8 changes: 8 additions & 0 deletions test/fixtures/output/kotlin/okhttp/nested.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
val client = OkHttpClient()

val request = Request.Builder()
.url("http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value")
.get()
.build()

val response = client.newCall(request).execute()
13 changes: 13 additions & 0 deletions test/fixtures/output/node/axios/nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var axios = require("axios").default;

var options = {
method: 'GET',
url: 'http://mockbin.com/har',
params: {'foo[bar]': 'baz,zap', fiz: 'buz', key: 'value'}
};

axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
10 changes: 10 additions & 0 deletions test/fixtures/output/node/fetch/nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const fetch = require('node-fetch');

let url = 'http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value';

let options = {method: 'GET'};

fetch(url, options)
.then(res => res.json())
.then(json => console.log(json))
.catch(err => console.error('error:' + err));
24 changes: 24 additions & 0 deletions test/fixtures/output/node/native/nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const http = require("http");

const options = {
"method": "GET",
"hostname": "mockbin.com",
"port": null,
"path": "/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value",
"headers": {}
};

const req = http.request(options, function (res) {
const chunks = [];

res.on("data", function (chunk) {
chunks.push(chunk);
});

res.on("end", function () {
const body = Buffer.concat(chunks);
console.log(body.toString());
});
});

req.end();
14 changes: 14 additions & 0 deletions test/fixtures/output/node/request/nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const request = require('request');

const options = {
method: 'GET',
url: 'http://mockbin.com/har',
qs: {'foo[bar]': 'baz,zap', fiz: 'buz', key: 'value'}
};

request(options, function (error, response, body) {
if (error) throw new Error(error);

console.log(body);
});

16 changes: 16 additions & 0 deletions test/fixtures/output/node/unirest/nested.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const unirest = require("unirest");

const req = unirest("GET", "http://mockbin.com/har");

req.query({
"foo[bar]": "baz,zap",
"fiz": "buz",
"key": "value"
});

req.end(function (res) {
if (res.error) throw new Error(res.error);

console.log(res.body);
});

18 changes: 18 additions & 0 deletions test/fixtures/output/objc/nsurlsession/nested.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#import <Foundation/Foundation.h>

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
[request setHTTPMethod:@"GET"];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSLog(@"%@", httpResponse);
}
}];
[dataTask resume];
9 changes: 9 additions & 0 deletions test/fixtures/output/ocaml/cohttp/nested.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value" in

Client.call `GET uri
>>= fun (res, body_stream) ->
(* Do stuff with the result *)
24 changes: 24 additions & 0 deletions test/fixtures/output/php/curl/nested.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
19 changes: 19 additions & 0 deletions test/fixtures/output/php/http1/nested.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

$request = new HttpRequest();
$request->setUrl('http://mockbin.com/har');
$request->setMethod(HTTP_METH_GET);

$request->setQueryData([
'foo[bar]' => 'baz,zap',
'fiz' => 'buz',
'key' => 'value'
]);

try {
$response = $request->send();

echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
17 changes: 17 additions & 0 deletions test/fixtures/output/php/http2/nested.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$client = new http\Client;
$request = new http\Client\Request;

$request->setRequestUrl('http://mockbin.com/har');
$request->setRequestMethod('GET');
$request->setQuery(new http\QueryString([
'foo[bar]' => 'baz,zap',
'fiz' => 'buz',
'key' => 'value'
]));

$client->enqueue($request)->send();
$response = $client->getResponse();

echo $response->getBody();
1 change: 1 addition & 0 deletions test/fixtures/output/powershell/restmethod/nested.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$response = Invoke-RestMethod -Uri 'http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value' -Method GET
1 change: 1 addition & 0 deletions test/fixtures/output/powershell/webrequest/nested.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$response = Invoke-WebRequest -Uri 'http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value' -Method GET
10 changes: 10 additions & 0 deletions test/fixtures/output/python/python3/nested.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import http.client

conn = http.client.HTTPConnection("mockbin.com")

conn.request("GET", "/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value")

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
9 changes: 9 additions & 0 deletions test/fixtures/output/python/requests/nested.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import requests

url = "http://mockbin.com/har"

querystring = {"foo[bar]":"baz,zap","fiz":"buz","key":"value"}

response = requests.request("GET", url, params=querystring)

print(response.text)
12 changes: 12 additions & 0 deletions test/fixtures/output/r/httr/nested.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
library(httr)

url <- "http://mockbin.com/har"

queryString <- list(
foo[bar] = "baz,zap",
fiz = "buz"
)

response <- VERB("GET", url, query = queryString, content_type("application/octet-stream"))

content(response, "text")
11 changes: 11 additions & 0 deletions test/fixtures/output/ruby/native/nested.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'uri'
require 'net/http'

url = URI("http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Get.new(url)

response = http.request(request)
puts response.read_body
2 changes: 2 additions & 0 deletions test/fixtures/output/shell/curl/nested.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
curl --request GET \
--url 'http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value'
1 change: 1 addition & 0 deletions test/fixtures/output/shell/httpie/nested.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http GET 'http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value'
Loading