forked from Kong/httpsnippet
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
After version 107, restsharp completely changed their API. This PR fixes the code generator to support the new API. - also add the escaping function from Kong#289 - I think there are probably still escaping bugs here, but it seems to be working Well Enough™
- Loading branch information
Showing
19 changed files
with
243 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 11 additions & 5 deletions
16
src/targets/csharp/restsharp/fixtures/application-form-encoded.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
var client = new RestClient("https://httpbin.org/anything"); | ||
var request = new RestRequest(Method.POST); | ||
request.AddHeader("content-type", "application/x-www-form-urlencoded"); | ||
request.AddParameter("application/x-www-form-urlencoded", "foo=bar&hello=world", ParameterType.RequestBody); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
request.AddParameter("foo", "bar"); | ||
request.AddParameter("hello", "world"); | ||
var response = await client.PostAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
var client = new RestClient("https://httpbin.org/anything"); | ||
var request = new RestRequest(Method.POST); | ||
request.AddHeader("content-type", "application/json"); | ||
request.AddParameter("application/json", "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":[]}],\"boolean\":false}", ParameterType.RequestBody); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
request.AddJsonBody("{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":[]}],\"boolean\":false}", false); | ||
var response = await client.PostAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
var client = new RestClient("https://httpbin.org/cookies"); | ||
var request = new RestRequest(Method.GET); | ||
request.AddCookie("foo", "bar"); | ||
request.AddCookie("bar", "baz"); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/cookies"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
request.AddCookie("foo", "bar", "/cookies", "httpbin.org"); | ||
request.AddCookie("bar", "baz", "/cookies", "httpbin.org"); | ||
var response = await client.GetAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
var client = new RestClient("https://httpbin.org/anything?foo=bar&foo=baz&baz=abc&key=value"); | ||
var request = new RestRequest(Method.POST); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything?foo=bar&foo=baz&baz=abc&key=value"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
request.AddHeader("accept", "application/json"); | ||
request.AddHeader("content-type", "application/x-www-form-urlencoded"); | ||
request.AddCookie("foo", "bar"); | ||
request.AddCookie("bar", "baz"); | ||
request.AddParameter("application/x-www-form-urlencoded", "foo=bar", ParameterType.RequestBody); | ||
IRestResponse response = client.Execute(request); | ||
request.AddCookie("foo", "bar", "/anything", "httpbin.org"); | ||
request.AddCookie("bar", "baz", "/anything", "httpbin.org"); | ||
request.AddParameter("foo", "bar"); | ||
var response = await client.PostAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
var client = new RestClient("https://httpbin.org/headers"); | ||
var request = new RestRequest(Method.GET); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/headers"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
request.AddHeader("accept", "application/json"); | ||
request.AddHeader("x-foo", "Bar"); | ||
request.AddHeader("x-bar", "Foo"); | ||
request.AddHeader("quoted-value", "\"quoted\" 'string'"); | ||
IRestResponse response = client.Execute(request); | ||
var response = await client.GetAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
var client = new RestClient("http://httpbin.org/anything"); | ||
var request = new RestRequest(Method.GET); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("http://httpbin.org/anything"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
var response = await client.GetAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
15 changes: 10 additions & 5 deletions
15
src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
var client = new RestClient("https://httpbin.org/anything"); | ||
var request = new RestRequest(Method.POST); | ||
request.AddHeader("content-type", "application/json"); | ||
request.AddParameter("application/json", "{\n \"foo\": \"bar\"\n}", ParameterType.RequestBody); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
request.AddJsonBody("{\n \"foo\": \"bar\"\n}", false); | ||
var response = await client.PostAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
15 changes: 10 additions & 5 deletions
15
src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
var client = new RestClient("https://httpbin.org/anything"); | ||
var request = new RestRequest(Method.POST); | ||
request.AddHeader("content-type", "application/json"); | ||
request.AddParameter("application/json", "{\"foo\":null}", ParameterType.RequestBody); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
request.AddJsonBody("{\"foo\":null}", false); | ||
var response = await client.PostAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
var client = new RestClient("https://httpbin.org/anything"); | ||
var request = new RestRequest(Method.POST); | ||
request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001"); | ||
request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
request.AlwaysMultipartFormData = true; | ||
request.FormBoundary = "---011000010111000001101001"; | ||
request.AddFile("foo", "src/fixtures/files/hello.txt"); | ||
request.AddParameter("bar", "Bonjour le monde"); | ||
var response = await client.PostAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
var client = new RestClient("https://httpbin.org/anything"); | ||
var request = new RestRequest(Method.POST); | ||
request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001"); | ||
request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
request.AlwaysMultipartFormData = true; | ||
request.FormBoundary = "---011000010111000001101001"; | ||
request.AddFile("foo", "src/fixtures/files/hello.txt"); | ||
var response = await client.PostAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
14 changes: 10 additions & 4 deletions
14
src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
var client = new RestClient("https://httpbin.org/anything"); | ||
var request = new RestRequest(Method.POST); | ||
request.AddHeader("Content-Type", "multipart/form-data"); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
request.AlwaysMultipartFormData = true; | ||
var response = await client.PostAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
17 changes: 12 additions & 5 deletions
17
src/targets/csharp/restsharp/fixtures/multipart-form-data.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
var client = new RestClient("https://httpbin.org/anything"); | ||
var request = new RestRequest(Method.POST); | ||
request.AddHeader("Content-Type", "multipart/form-data; boundary=---011000010111000001101001"); | ||
request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
request.AlwaysMultipartFormData = true; | ||
request.FormBoundary = "---011000010111000001101001"; | ||
request.AddParameter("foo", "bar"); | ||
var response = await client.PostAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
var client = new RestClient("https://httpbin.org/anything?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value"); | ||
var request = new RestRequest(Method.GET); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything?foo%5Bbar%5D=baz%2Czap&fiz=buz&key=value"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
var response = await client.GetAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
13 changes: 9 additions & 4 deletions
13
src/targets/csharp/restsharp/fixtures/postdata-malformed.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,9 @@ | ||
var client = new RestClient("https://httpbin.org/anything"); | ||
var request = new RestRequest(Method.POST); | ||
request.AddHeader("content-type", "application/json"); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
var response = await client.PostAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
var client = new RestClient("https://httpbin.org/anything?startTime=2019-06-13T19%3A08%3A25.455Z&endTime=2015-09-15T14%3A00%3A12-04%3A00"); | ||
var request = new RestRequest(Method.GET); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything?startTime=2019-06-13T19%3A08%3A25.455Z&endTime=2015-09-15T14%3A00%3A12-04%3A00"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
var response = await client.GetAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
var client = new RestClient("https://httpbin.org/anything?foo=bar&foo=baz&baz=abc&key=value"); | ||
var request = new RestRequest(Method.GET); | ||
IRestResponse response = client.Execute(request); | ||
using RestSharp; | ||
|
||
|
||
var options = new RestClientOptions("https://httpbin.org/anything?foo=bar&foo=baz&baz=abc&key=value"); | ||
var client = new RestClient(options); | ||
var request = new RestRequest(""); | ||
var response = await client.GetAsync(request); | ||
|
||
Console.WriteLine("{0}", response.Content); |
Oops, something went wrong.