From d21b2250ac420c18e6298109da35b883bc4dcefa Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Fri, 19 Jul 2024 21:23:19 +0100 Subject: [PATCH] Preserve non-standard/unparseable query strings as-is in snippet output This is particularly notable for cases like the &&& repro here, but is also clearly visible in cases like ?a=b&c, which would often become something more like '?a=b&c='. This only applies when the queryString in the HAR is empty, which will be rare, but HTTP Toolkit (and others) can use this to leave that blank and send only the raw URL to preserve formatting at the cost of the losing the nice structure query param setting code in the output. --- src/index.js | 37 ++++++++++++------- .../output/c/libcurl/unparseable-query.c | 6 +++ .../clojure/clj_http/unparseable-query.clj | 3 ++ .../csharp/httpclient/unparseable-query.cs | 12 ++++++ .../csharp/restsharp/unparseable-query.cs | 3 ++ .../output/go/native/unparseable-query.go | 23 ++++++++++++ .../output/http/1.1/unparseable-query | 2 + .../java/asynchttp/unparseable-query.java | 8 ++++ .../java/nethttp/unparseable-query.java | 6 +++ .../output/java/okhttp/unparseable-query.java | 8 ++++ .../java/unirest/unparseable-query.java | 2 + .../javascript/axios/unparseable-query.js | 9 +++++ .../javascript/fetch/unparseable-query.js | 6 +++ .../javascript/jquery/unparseable-query.js | 11 ++++++ .../javascript/xhr/unparseable-query.js | 14 +++++++ .../output/kotlin/okhttp/unparseable-query.kt | 8 ++++ .../output/node/axios/unparseable-query.js | 9 +++++ .../output/node/fetch/unparseable-query.js | 10 +++++ .../output/node/native/unparseable-query.js | 24 ++++++++++++ .../output/node/request/unparseable-query.js | 9 +++++ .../output/node/unirest/unparseable-query.js | 9 +++++ .../objc/nsurlsession/unparseable-query.m | 18 +++++++++ .../output/ocaml/cohttp/unparseable-query.ml | 9 +++++ .../output/php/curl/unparseable-query.php | 24 ++++++++++++ .../output/php/http1/unparseable-query.php | 13 +++++++ .../output/php/http2/unparseable-query.php | 11 ++++++ .../restmethod/unparseable-query.ps1 | 1 + .../webrequest/unparseable-query.ps1 | 1 + .../python/python3/unparseable-query.py | 10 +++++ .../python/requests/unparseable-query.py | 7 ++++ .../output/r/httr/unparseable-query.r | 7 ++++ .../output/ruby/native/unparseable-query.rb | 11 ++++++ .../output/shell/curl/unparseable-query.sh | 2 + .../output/shell/httpie/unparseable-query.sh | 1 + .../output/shell/wget/unparseable-query.sh | 4 ++ .../nsurlsession/unparseable-query.swift | 18 +++++++++ test/fixtures/requests/unparseable-query.json | 6 +++ 37 files changed, 348 insertions(+), 14 deletions(-) create mode 100644 test/fixtures/output/c/libcurl/unparseable-query.c create mode 100644 test/fixtures/output/clojure/clj_http/unparseable-query.clj create mode 100644 test/fixtures/output/csharp/httpclient/unparseable-query.cs create mode 100644 test/fixtures/output/csharp/restsharp/unparseable-query.cs create mode 100644 test/fixtures/output/go/native/unparseable-query.go create mode 100644 test/fixtures/output/http/1.1/unparseable-query create mode 100644 test/fixtures/output/java/asynchttp/unparseable-query.java create mode 100644 test/fixtures/output/java/nethttp/unparseable-query.java create mode 100644 test/fixtures/output/java/okhttp/unparseable-query.java create mode 100644 test/fixtures/output/java/unirest/unparseable-query.java create mode 100644 test/fixtures/output/javascript/axios/unparseable-query.js create mode 100644 test/fixtures/output/javascript/fetch/unparseable-query.js create mode 100644 test/fixtures/output/javascript/jquery/unparseable-query.js create mode 100644 test/fixtures/output/javascript/xhr/unparseable-query.js create mode 100644 test/fixtures/output/kotlin/okhttp/unparseable-query.kt create mode 100644 test/fixtures/output/node/axios/unparseable-query.js create mode 100644 test/fixtures/output/node/fetch/unparseable-query.js create mode 100644 test/fixtures/output/node/native/unparseable-query.js create mode 100644 test/fixtures/output/node/request/unparseable-query.js create mode 100644 test/fixtures/output/node/unirest/unparseable-query.js create mode 100644 test/fixtures/output/objc/nsurlsession/unparseable-query.m create mode 100644 test/fixtures/output/ocaml/cohttp/unparseable-query.ml create mode 100644 test/fixtures/output/php/curl/unparseable-query.php create mode 100644 test/fixtures/output/php/http1/unparseable-query.php create mode 100644 test/fixtures/output/php/http2/unparseable-query.php create mode 100644 test/fixtures/output/powershell/restmethod/unparseable-query.ps1 create mode 100644 test/fixtures/output/powershell/webrequest/unparseable-query.ps1 create mode 100644 test/fixtures/output/python/python3/unparseable-query.py create mode 100644 test/fixtures/output/python/requests/unparseable-query.py create mode 100644 test/fixtures/output/r/httr/unparseable-query.r create mode 100644 test/fixtures/output/ruby/native/unparseable-query.rb create mode 100644 test/fixtures/output/shell/curl/unparseable-query.sh create mode 100644 test/fixtures/output/shell/httpie/unparseable-query.sh create mode 100644 test/fixtures/output/shell/wget/unparseable-query.sh create mode 100644 test/fixtures/output/swift/nsurlsession/unparseable-query.swift create mode 100644 test/fixtures/requests/unparseable-query.json diff --git a/src/index.js b/src/index.js index c8ebfc8..eb9078e 100644 --- a/src/index.js +++ b/src/index.js @@ -219,20 +219,29 @@ HTTPSnippet.prototype.prepare = function (request) { // merge all possible queryString values request.queryObj = Object.assign(request.queryObj, request.uriObj.query) - // reset uriObj values for a clean url - request.uriObj.query = null - request.uriObj.search = null - request.uriObj.path = request.uriObj.pathname - - // keep the base url clean of queryString - request.url = url.format(request.uriObj) - - // update the uri object - request.uriObj.query = request.queryObj - request.uriObj.search = qs.stringify(request.queryObj) - - if (request.uriObj.search) { - request.uriObj.path = request.uriObj.pathname + '?' + request.uriObj.search + // In some cases (unparseable query - preference to use raw in exporter) the queryString might + // be empty while the URL search is not. In that case, we prefer the URL search. + const hasQueryObj = Object.keys(request.queryObj).length > 0 + if (hasQueryObj || !request.uriObj.search) { + // reset uriObj values for a clean url + request.uriObj.query = null + request.uriObj.search = null + request.uriObj.path = request.uriObj.pathname + + // keep the base url clean of queryString + request.url = url.format(request.uriObj) + + // update the uri object + request.uriObj.query = request.queryObj + request.uriObj.search = qs.stringify(request.queryObj) + + if (request.uriObj.search) { + request.uriObj.path = request.uriObj.pathname + '?' + request.uriObj.search + } + } else { + // We have no request.queryObj (so snippets won't send query params in a structured way) + // We keep the queryString in request.url (so it's sent raw everywhere) + // request.fullUrl is recreated below (maybe mild fixed?) but preserves raw search etc } // construct a full url diff --git a/test/fixtures/output/c/libcurl/unparseable-query.c b/test/fixtures/output/c/libcurl/unparseable-query.c new file mode 100644 index 0000000..2854209 --- /dev/null +++ b/test/fixtures/output/c/libcurl/unparseable-query.c @@ -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?&&&"); + +CURLcode ret = curl_easy_perform(hnd); \ No newline at end of file diff --git a/test/fixtures/output/clojure/clj_http/unparseable-query.clj b/test/fixtures/output/clojure/clj_http/unparseable-query.clj new file mode 100644 index 0000000..597f745 --- /dev/null +++ b/test/fixtures/output/clojure/clj_http/unparseable-query.clj @@ -0,0 +1,3 @@ +(require '[clj-http.client :as client]) + +(client/get "http://mockbin.com/har?&&&") \ No newline at end of file diff --git a/test/fixtures/output/csharp/httpclient/unparseable-query.cs b/test/fixtures/output/csharp/httpclient/unparseable-query.cs new file mode 100644 index 0000000..85d9c25 --- /dev/null +++ b/test/fixtures/output/csharp/httpclient/unparseable-query.cs @@ -0,0 +1,12 @@ +var client = new HttpClient(); +var request = new HttpRequestMessage +{ + Method = HttpMethod.Get, + RequestUri = new Uri("http://mockbin.com/har?&&&"), +}; +using (var response = await client.SendAsync(request)) +{ + response.EnsureSuccessStatusCode(); + var body = await response.Content.ReadAsStringAsync(); + Console.WriteLine(body); +} \ No newline at end of file diff --git a/test/fixtures/output/csharp/restsharp/unparseable-query.cs b/test/fixtures/output/csharp/restsharp/unparseable-query.cs new file mode 100644 index 0000000..4ecfda8 --- /dev/null +++ b/test/fixtures/output/csharp/restsharp/unparseable-query.cs @@ -0,0 +1,3 @@ +var client = new RestClient("http://mockbin.com/har?&&&"); +var request = new RestRequest(Method.GET); +IRestResponse response = client.Execute(request); \ No newline at end of file diff --git a/test/fixtures/output/go/native/unparseable-query.go b/test/fixtures/output/go/native/unparseable-query.go new file mode 100644 index 0000000..45a11c7 --- /dev/null +++ b/test/fixtures/output/go/native/unparseable-query.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "net/http" + "io" +) + +func main() { + + url := "http://mockbin.com/har?&&&" + + req, _ := http.NewRequest("GET", url, nil) + + res, _ := http.DefaultClient.Do(req) + + defer res.Body.Close() + body, _ := io.ReadAll(res.Body) + + fmt.Println(res) + fmt.Println(string(body)) + +} \ No newline at end of file diff --git a/test/fixtures/output/http/1.1/unparseable-query b/test/fixtures/output/http/1.1/unparseable-query new file mode 100644 index 0000000..a30d520 --- /dev/null +++ b/test/fixtures/output/http/1.1/unparseable-query @@ -0,0 +1,2 @@ +GET /har?&&& HTTP/1.1 +Host: mockbin.com \ No newline at end of file diff --git a/test/fixtures/output/java/asynchttp/unparseable-query.java b/test/fixtures/output/java/asynchttp/unparseable-query.java new file mode 100644 index 0000000..5097a3d --- /dev/null +++ b/test/fixtures/output/java/asynchttp/unparseable-query.java @@ -0,0 +1,8 @@ +AsyncHttpClient client = new DefaultAsyncHttpClient(); +client.prepare("GET", "http://mockbin.com/har?&&&") + .execute() + .toCompletableFuture() + .thenAccept(System.out::println) + .join(); + +client.close(); \ No newline at end of file diff --git a/test/fixtures/output/java/nethttp/unparseable-query.java b/test/fixtures/output/java/nethttp/unparseable-query.java new file mode 100644 index 0000000..64bd680 --- /dev/null +++ b/test/fixtures/output/java/nethttp/unparseable-query.java @@ -0,0 +1,6 @@ +HttpRequest request = HttpRequest.newBuilder() + .uri(URI.create("http://mockbin.com/har?&&&")) + .method("GET", HttpRequest.BodyPublishers.noBody()) + .build(); +HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); +System.out.println(response.body()); \ No newline at end of file diff --git a/test/fixtures/output/java/okhttp/unparseable-query.java b/test/fixtures/output/java/okhttp/unparseable-query.java new file mode 100644 index 0000000..605aabb --- /dev/null +++ b/test/fixtures/output/java/okhttp/unparseable-query.java @@ -0,0 +1,8 @@ +OkHttpClient client = new OkHttpClient(); + +Request request = new Request.Builder() + .url("http://mockbin.com/har?&&&") + .get() + .build(); + +Response response = client.newCall(request).execute(); \ No newline at end of file diff --git a/test/fixtures/output/java/unirest/unparseable-query.java b/test/fixtures/output/java/unirest/unparseable-query.java new file mode 100644 index 0000000..0d53364 --- /dev/null +++ b/test/fixtures/output/java/unirest/unparseable-query.java @@ -0,0 +1,2 @@ +HttpResponse response = Unirest.get("http://mockbin.com/har?&&&") + .asString(); \ No newline at end of file diff --git a/test/fixtures/output/javascript/axios/unparseable-query.js b/test/fixtures/output/javascript/axios/unparseable-query.js new file mode 100644 index 0000000..733a6bc --- /dev/null +++ b/test/fixtures/output/javascript/axios/unparseable-query.js @@ -0,0 +1,9 @@ +import axios from "axios"; + +const options = {method: 'GET', url: 'http://mockbin.com/har?&&&'}; + +axios.request(options).then(function (response) { + console.log(response.data); +}).catch(function (error) { + console.error(error); +}); \ No newline at end of file diff --git a/test/fixtures/output/javascript/fetch/unparseable-query.js b/test/fixtures/output/javascript/fetch/unparseable-query.js new file mode 100644 index 0000000..10b5b9e --- /dev/null +++ b/test/fixtures/output/javascript/fetch/unparseable-query.js @@ -0,0 +1,6 @@ +const options = {method: 'GET'}; + +fetch('http://mockbin.com/har?&&&', options) + .then(response => response.json()) + .then(response => console.log(response)) + .catch(err => console.error(err)); \ No newline at end of file diff --git a/test/fixtures/output/javascript/jquery/unparseable-query.js b/test/fixtures/output/javascript/jquery/unparseable-query.js new file mode 100644 index 0000000..fdb5d51 --- /dev/null +++ b/test/fixtures/output/javascript/jquery/unparseable-query.js @@ -0,0 +1,11 @@ +const settings = { + "async": true, + "crossDomain": true, + "url": "http://mockbin.com/har?&&&", + "method": "GET", + "headers": {} +}; + +$.ajax(settings).done(function (response) { + console.log(response); +}); \ No newline at end of file diff --git a/test/fixtures/output/javascript/xhr/unparseable-query.js b/test/fixtures/output/javascript/xhr/unparseable-query.js new file mode 100644 index 0000000..0188eb8 --- /dev/null +++ b/test/fixtures/output/javascript/xhr/unparseable-query.js @@ -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?&&&"); + +xhr.send(data); \ No newline at end of file diff --git a/test/fixtures/output/kotlin/okhttp/unparseable-query.kt b/test/fixtures/output/kotlin/okhttp/unparseable-query.kt new file mode 100644 index 0000000..fa476db --- /dev/null +++ b/test/fixtures/output/kotlin/okhttp/unparseable-query.kt @@ -0,0 +1,8 @@ +val client = OkHttpClient() + +val request = Request.Builder() + .url("http://mockbin.com/har?&&&") + .get() + .build() + +val response = client.newCall(request).execute() \ No newline at end of file diff --git a/test/fixtures/output/node/axios/unparseable-query.js b/test/fixtures/output/node/axios/unparseable-query.js new file mode 100644 index 0000000..9e39489 --- /dev/null +++ b/test/fixtures/output/node/axios/unparseable-query.js @@ -0,0 +1,9 @@ +var axios = require("axios").default; + +var options = {method: 'GET', url: 'http://mockbin.com/har?&&&'}; + +axios.request(options).then(function (response) { + console.log(response.data); +}).catch(function (error) { + console.error(error); +}); \ No newline at end of file diff --git a/test/fixtures/output/node/fetch/unparseable-query.js b/test/fixtures/output/node/fetch/unparseable-query.js new file mode 100644 index 0000000..b06f203 --- /dev/null +++ b/test/fixtures/output/node/fetch/unparseable-query.js @@ -0,0 +1,10 @@ +const fetch = require('node-fetch'); + +let url = 'http://mockbin.com/har?&&&'; + +let options = {method: 'GET'}; + +fetch(url, options) + .then(res => res.json()) + .then(json => console.log(json)) + .catch(err => console.error('error:' + err)); \ No newline at end of file diff --git a/test/fixtures/output/node/native/unparseable-query.js b/test/fixtures/output/node/native/unparseable-query.js new file mode 100644 index 0000000..8ee8728 --- /dev/null +++ b/test/fixtures/output/node/native/unparseable-query.js @@ -0,0 +1,24 @@ +const http = require("http"); + +const options = { + "method": "GET", + "hostname": "mockbin.com", + "port": null, + "path": "/har?&&&", + "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(); \ No newline at end of file diff --git a/test/fixtures/output/node/request/unparseable-query.js b/test/fixtures/output/node/request/unparseable-query.js new file mode 100644 index 0000000..3860cc2 --- /dev/null +++ b/test/fixtures/output/node/request/unparseable-query.js @@ -0,0 +1,9 @@ +const request = require('request'); + +const options = {method: 'GET', url: 'http://mockbin.com/har?&&&'}; + +request(options, function (error, response, body) { + if (error) throw new Error(error); + + console.log(body); +}); \ No newline at end of file diff --git a/test/fixtures/output/node/unirest/unparseable-query.js b/test/fixtures/output/node/unirest/unparseable-query.js new file mode 100644 index 0000000..86c3dd0 --- /dev/null +++ b/test/fixtures/output/node/unirest/unparseable-query.js @@ -0,0 +1,9 @@ +const unirest = require("unirest"); + +const req = unirest("GET", "http://mockbin.com/har?&&&"); + +req.end(function (res) { + if (res.error) throw new Error(res.error); + + console.log(res.body); +}); \ No newline at end of file diff --git a/test/fixtures/output/objc/nsurlsession/unparseable-query.m b/test/fixtures/output/objc/nsurlsession/unparseable-query.m new file mode 100644 index 0000000..4bc5ef8 --- /dev/null +++ b/test/fixtures/output/objc/nsurlsession/unparseable-query.m @@ -0,0 +1,18 @@ +#import + +NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://mockbin.com/har?&&&"] + 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]; \ No newline at end of file diff --git a/test/fixtures/output/ocaml/cohttp/unparseable-query.ml b/test/fixtures/output/ocaml/cohttp/unparseable-query.ml new file mode 100644 index 0000000..f46dbd8 --- /dev/null +++ b/test/fixtures/output/ocaml/cohttp/unparseable-query.ml @@ -0,0 +1,9 @@ +open Cohttp_lwt_unix +open Cohttp +open Lwt + +let uri = Uri.of_string "http://mockbin.com/har?&&&" in + +Client.call `GET uri +>>= fun (res, body_stream) -> + (* Do stuff with the result *) \ No newline at end of file diff --git a/test/fixtures/output/php/curl/unparseable-query.php b/test/fixtures/output/php/curl/unparseable-query.php new file mode 100644 index 0000000..7dc5293 --- /dev/null +++ b/test/fixtures/output/php/curl/unparseable-query.php @@ -0,0 +1,24 @@ + 'http://mockbin.com/har?&&&', + 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; +} \ No newline at end of file diff --git a/test/fixtures/output/php/http1/unparseable-query.php b/test/fixtures/output/php/http1/unparseable-query.php new file mode 100644 index 0000000..bb2f030 --- /dev/null +++ b/test/fixtures/output/php/http1/unparseable-query.php @@ -0,0 +1,13 @@ +setUrl('http://mockbin.com/har?&&&'); +$request->setMethod(HTTP_METH_GET); + +try { + $response = $request->send(); + + echo $response->getBody(); +} catch (HttpException $ex) { + echo $ex; +} \ No newline at end of file diff --git a/test/fixtures/output/php/http2/unparseable-query.php b/test/fixtures/output/php/http2/unparseable-query.php new file mode 100644 index 0000000..c7e9f5a --- /dev/null +++ b/test/fixtures/output/php/http2/unparseable-query.php @@ -0,0 +1,11 @@ +setRequestUrl('http://mockbin.com/har?&&&'); +$request->setRequestMethod('GET'); +$client->enqueue($request)->send(); +$response = $client->getResponse(); + +echo $response->getBody(); \ No newline at end of file diff --git a/test/fixtures/output/powershell/restmethod/unparseable-query.ps1 b/test/fixtures/output/powershell/restmethod/unparseable-query.ps1 new file mode 100644 index 0000000..6a1c059 --- /dev/null +++ b/test/fixtures/output/powershell/restmethod/unparseable-query.ps1 @@ -0,0 +1 @@ +$response = Invoke-RestMethod -Uri 'http://mockbin.com/har?&&&' -Method GET \ No newline at end of file diff --git a/test/fixtures/output/powershell/webrequest/unparseable-query.ps1 b/test/fixtures/output/powershell/webrequest/unparseable-query.ps1 new file mode 100644 index 0000000..b21147e --- /dev/null +++ b/test/fixtures/output/powershell/webrequest/unparseable-query.ps1 @@ -0,0 +1 @@ +$response = Invoke-WebRequest -Uri 'http://mockbin.com/har?&&&' -Method GET \ No newline at end of file diff --git a/test/fixtures/output/python/python3/unparseable-query.py b/test/fixtures/output/python/python3/unparseable-query.py new file mode 100644 index 0000000..cd9cfc5 --- /dev/null +++ b/test/fixtures/output/python/python3/unparseable-query.py @@ -0,0 +1,10 @@ +import http.client + +conn = http.client.HTTPConnection("mockbin.com") + +conn.request("GET", "/har?&&&") + +res = conn.getresponse() +data = res.read() + +print(data.decode("utf-8")) \ No newline at end of file diff --git a/test/fixtures/output/python/requests/unparseable-query.py b/test/fixtures/output/python/requests/unparseable-query.py new file mode 100644 index 0000000..476de8e --- /dev/null +++ b/test/fixtures/output/python/requests/unparseable-query.py @@ -0,0 +1,7 @@ +import requests + +url = "http://mockbin.com/har?&&&" + +response = requests.get(url) + +print(response.text) \ No newline at end of file diff --git a/test/fixtures/output/r/httr/unparseable-query.r b/test/fixtures/output/r/httr/unparseable-query.r new file mode 100644 index 0000000..52d1099 --- /dev/null +++ b/test/fixtures/output/r/httr/unparseable-query.r @@ -0,0 +1,7 @@ +library(httr) + +url <- "http://mockbin.com/har?&&&" + +response <- VERB("GET", url, content_type("application/octet-stream")) + +content(response, "text") \ No newline at end of file diff --git a/test/fixtures/output/ruby/native/unparseable-query.rb b/test/fixtures/output/ruby/native/unparseable-query.rb new file mode 100644 index 0000000..c66aa82 --- /dev/null +++ b/test/fixtures/output/ruby/native/unparseable-query.rb @@ -0,0 +1,11 @@ +require 'uri' +require 'net/http' + +url = URI("http://mockbin.com/har?&&&") + +http = Net::HTTP.new(url.host, url.port) + +request = Net::HTTP::Get.new(url) + +response = http.request(request) +puts response.read_body \ No newline at end of file diff --git a/test/fixtures/output/shell/curl/unparseable-query.sh b/test/fixtures/output/shell/curl/unparseable-query.sh new file mode 100644 index 0000000..c912c2b --- /dev/null +++ b/test/fixtures/output/shell/curl/unparseable-query.sh @@ -0,0 +1,2 @@ +curl --request GET \ + --url 'http://mockbin.com/har?&&&' \ No newline at end of file diff --git a/test/fixtures/output/shell/httpie/unparseable-query.sh b/test/fixtures/output/shell/httpie/unparseable-query.sh new file mode 100644 index 0000000..016d3ec --- /dev/null +++ b/test/fixtures/output/shell/httpie/unparseable-query.sh @@ -0,0 +1 @@ +http GET 'http://mockbin.com/har?&&&' \ No newline at end of file diff --git a/test/fixtures/output/shell/wget/unparseable-query.sh b/test/fixtures/output/shell/wget/unparseable-query.sh new file mode 100644 index 0000000..cf8b52a --- /dev/null +++ b/test/fixtures/output/shell/wget/unparseable-query.sh @@ -0,0 +1,4 @@ +wget --quiet \ + --method GET \ + --output-document \ + - 'http://mockbin.com/har?&&&' \ No newline at end of file diff --git a/test/fixtures/output/swift/nsurlsession/unparseable-query.swift b/test/fixtures/output/swift/nsurlsession/unparseable-query.swift new file mode 100644 index 0000000..0c7980c --- /dev/null +++ b/test/fixtures/output/swift/nsurlsession/unparseable-query.swift @@ -0,0 +1,18 @@ +import Foundation + +let request = NSMutableURLRequest(url: NSURL(string: "http://mockbin.com/har?&&&")! as URL, + cachePolicy: .useProtocolCachePolicy, + timeoutInterval: 10.0) +request.httpMethod = "GET" + +let session = URLSession.shared +let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in + if (error != nil) { + print(error) + } else { + let httpResponse = response as? HTTPURLResponse + print(httpResponse) + } +}) + +dataTask.resume() \ No newline at end of file diff --git a/test/fixtures/requests/unparseable-query.json b/test/fixtures/requests/unparseable-query.json new file mode 100644 index 0000000..925027b --- /dev/null +++ b/test/fixtures/requests/unparseable-query.json @@ -0,0 +1,6 @@ +{ + "method": "GET", + "url": "http://mockbin.com/har?&&&", + "httpVersion": "HTTP/1.1", + "queryString": [] +}