Skip to content

Commit 71eec07

Browse files
authored
Add --globoff option to shell_curl (#199)
* Add nested query fixture * Add --globoff option to shell/curl * Update expected output to match recent changes
1 parent 200b1fd commit 71eec07

File tree

38 files changed

+424
-3
lines changed

38 files changed

+424
-3
lines changed

src/targets/shell/curl.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,22 @@ module.exports = function (source, options) {
1818
const opts = Object.assign({
1919
indent: ' ',
2020
short: false,
21-
binary: false
21+
binary: false,
22+
globOff: false
2223
}, options)
2324

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

26-
code.push('curl %s %s', opts.short ? '-X' : '--request', source.method)
27-
.push(util.format('%s%s', opts.short ? '' : '--url ', helpers.quote(source.fullUrl)))
27+
const globOption = opts.short ? '-g' : '--globoff'
28+
const requestOption = opts.short ? '-X' : '--request'
29+
let formattedUrl = helpers.quote(source.fullUrl)
30+
31+
code.push('curl %s %s', requestOption, source.method)
32+
if (opts.globOff) {
33+
formattedUrl = unescape(formattedUrl)
34+
code.push(globOption)
35+
}
36+
code.push(util.format('%s%s', opts.short ? '' : '--url ', formattedUrl))
2837

2938
if (source.httpVersion === 'HTTP/1.0') {
3039
code.push(opts.short ? '-0' : '--http1.0')
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CURL *hnd = curl_easy_init();
2+
3+
curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "GET");
4+
curl_easy_setopt(hnd, CURLOPT_URL, "http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value");
5+
6+
CURLcode ret = curl_easy_perform(hnd);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(require '[clj-http.client :as client])
2+
3+
(client/get "http://mockbin.com/har" {:query-params {:foo[bar] "baz,zap"
4+
:fiz "buz"
5+
:key "value"}})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var client = new HttpClient();
2+
var request = new HttpRequestMessage
3+
{
4+
Method = HttpMethod.Get,
5+
RequestUri = new Uri("http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value"),
6+
};
7+
using (var response = await client.SendAsync(request))
8+
{
9+
response.EnsureSuccessStatusCode();
10+
var body = await response.Content.ReadAsStringAsync();
11+
Console.WriteLine(body);
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var client = new RestClient("http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value");
2+
var request = new RestRequest(Method.GET);
3+
IRestResponse response = client.Execute(request);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net/http"
6+
"io/ioutil"
7+
)
8+
9+
func main() {
10+
11+
url := "http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value"
12+
13+
req, _ := http.NewRequest("GET", url, nil)
14+
15+
res, _ := http.DefaultClient.Do(req)
16+
17+
defer res.Body.Close()
18+
body, _ := ioutil.ReadAll(res.Body)
19+
20+
fmt.Println(res)
21+
fmt.Println(string(body))
22+
23+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GET /har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value HTTP/1.1
2+
Host: mockbin.com
3+
4+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
AsyncHttpClient client = new DefaultAsyncHttpClient();
2+
client.prepare("GET", "http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value")
3+
.execute()
4+
.toCompletableFuture()
5+
.thenAccept(System.out::println)
6+
.join();
7+
8+
client.close();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
HttpRequest request = HttpRequest.newBuilder()
2+
.uri(URI.create("http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value"))
3+
.method("GET", HttpRequest.BodyPublishers.noBody())
4+
.build();
5+
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
6+
System.out.println(response.body());
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
OkHttpClient client = new OkHttpClient();
2+
3+
Request request = new Request.Builder()
4+
.url("http://mockbin.com/har?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value")
5+
.get()
6+
.build();
7+
8+
Response response = client.newCall(request).execute();

0 commit comments

Comments
 (0)