From 68f0024c21acef4d030726f16ac9c9c0e83c772b Mon Sep 17 00:00:00 2001 From: Bill Mill Date: Fri, 16 Jun 2023 14:14:52 -0400 Subject: [PATCH 1/5] feat: suppert restsharp 107+ Updates restsharp support following their breaking changes, reported in https://github.com/Kong/httpsnippet/issues/312 --- src/helpers/escape.test.ts | 27 ++++++ src/helpers/escape.ts | 88 +++++++++++++++++++ src/targets/csharp/restsharp/client.ts | 69 ++++++++++++--- .../fixtures/application-form-encoded.cs | 11 +-- .../restsharp/fixtures/application-json.cs | 10 +-- .../csharp/restsharp/fixtures/cookies.cs | 11 +-- src/targets/csharp/restsharp/fixtures/full.cs | 14 +-- .../csharp/restsharp/fixtures/headers.cs | 7 +- .../restsharp/fixtures/http-insecure.cs | 7 +- .../restsharp/fixtures/jsonObj-multiline.cs | 10 +-- .../restsharp/fixtures/jsonObj-null-value.cs | 10 +-- .../restsharp/fixtures/multipart-data.cs | 13 +-- .../restsharp/fixtures/multipart-file.cs | 12 +-- .../fixtures/multipart-form-data-no-params.cs | 9 +- .../restsharp/fixtures/multipart-form-data.cs | 12 +-- .../csharp/restsharp/fixtures/nested.cs | 7 +- .../restsharp/fixtures/postdata-malformed.cs | 8 +- .../restsharp/fixtures/query-encoded.cs | 7 +- .../csharp/restsharp/fixtures/query.cs | 7 +- .../csharp/restsharp/fixtures/short.cs | 7 +- .../csharp/restsharp/fixtures/text-plain.cs | 10 +-- 21 files changed, 266 insertions(+), 90 deletions(-) create mode 100644 src/helpers/escape.test.ts create mode 100644 src/helpers/escape.ts diff --git a/src/helpers/escape.test.ts b/src/helpers/escape.test.ts new file mode 100644 index 000000000..c7d7ad65b --- /dev/null +++ b/src/helpers/escape.test.ts @@ -0,0 +1,27 @@ +import { escapeString } from './escape'; + +describe('Escape methods', () => { + describe('escapeString', () => { + it('does nothing to a safe string', () => { + expect(escapeString('hello world')).toBe('hello world'); + }); + + it('escapes double quotes by default', () => { + expect(escapeString('"hello world"')).toBe('\\"hello world\\"'); + }); + + it('escapes newlines by default', () => { + expect(escapeString('hello\r\nworld')).toBe('hello\\r\\nworld'); + }); + + it('escapes backslashes', () => { + expect(escapeString('hello\\world')).toBe('hello\\\\world'); + }); + + it('escapes unrepresentable characters', () => { + expect( + escapeString('hello \u0000') // 0 = ASCII 'null' character + ).toBe('hello \\u0000'); + }); + }); +}); diff --git a/src/helpers/escape.ts b/src/helpers/escape.ts new file mode 100644 index 000000000..fabe32904 --- /dev/null +++ b/src/helpers/escape.ts @@ -0,0 +1,88 @@ +export interface EscapeOptions { + /** + * The delimiter that will be used to wrap the string (and so must be escaped + * when used within the string). + * Defaults to " + */ + delimiter?: string; + + /** + * The char to use to escape the delimiter and other special characters. + * Defaults to \ + */ + escapeChar?: string; + + /** + * Whether newlines (\n and \r) should be escaped within the string. + * Defaults to true. + */ + escapeNewlines?: boolean; +} + +/** + * Escape characters within a value to make it safe to insert directly into a + * snippet. Takes options which define the escape requirements. + * + * This is closely based on the JSON-stringify string serialization algorithm, + * but generalized for other string delimiters (e.g. " or ') and different escape + * characters (e.g. Powershell uses `) + * + * See https://tc39.es/ecma262/multipage/structured-data.html#sec-quotejsonstring + * for the complete original algorithm. + */ +export function escapeString(rawValue: any, options: EscapeOptions = {}) { + const { delimiter = '"', escapeChar = '\\', escapeNewlines = true } = options; + + const stringValue = rawValue.toString(); + + return [...stringValue] + .map(c => { + if (c === '\b') { + return `${escapeChar}b`; + } else if (c === '\t') { + return `${escapeChar}t`; + } else if (c === '\n') { + if (escapeNewlines) { + return `${escapeChar}n`; + } + return c; // Don't just continue, or this is caught by < \u0020 + } else if (c === '\f') { + return `${escapeChar}f`; + } else if (c === '\r') { + if (escapeNewlines) { + return `${escapeChar}r`; + } + return c; // Don't just continue, or this is caught by < \u0020 + } else if (c === escapeChar) { + return escapeChar + escapeChar; + } else if (c === delimiter) { + return escapeChar + delimiter; + } else if (c < '\u0020' || c > '\u007E') { + // Delegate the trickier non-ASCII cases to the normal algorithm. Some of these + // are escaped as \uXXXX, whilst others are represented literally. Since we're + // using this primarily for header values that are generally (though not 100% + // strictly?) ASCII-only, this should almost never happen. + return JSON.stringify(c).slice(1, -1); + } + return c; + }) + .join(''); +} + +/** + * Make a string value safe to insert literally into a snippet within single quotes, + * by escaping problematic characters, including single quotes inside the string, + * backslashes, newlines, and other special characters. + * + * If value is not a string, it will be stringified with .toString() first. + */ +export const escapeForSingleQuotes = (value: any) => escapeString(value, { delimiter: "'" }); + +/** + * Make a string value safe to insert literally into a snippet within double quotes, + * by escaping problematic characters, including double quotes inside the string, + * backslashes, newlines, and other special characters. + * + * If value is not a string, it will be stringified with .toString() first. + */ +export const escapeForDoubleQuotes = (value: any) => escapeString(value, { delimiter: '"' }); diff --git a/src/targets/csharp/restsharp/client.ts b/src/targets/csharp/restsharp/client.ts index 973894a8e..43f85742d 100644 --- a/src/targets/csharp/restsharp/client.ts +++ b/src/targets/csharp/restsharp/client.ts @@ -1,7 +1,11 @@ import type { Client } from '../../targets'; import { CodeBuilder } from '../../../helpers/code-builder'; -import { getHeader } from '../../../helpers/headers'; +import { escapeForDoubleQuotes } from '../../../helpers/escape'; + +function title(s: string): string { + return s[0].toUpperCase() + s.slice(1).toLowerCase(); +} export const restsharp: Client = { info: { @@ -10,7 +14,7 @@ export const restsharp: Client = { link: 'http://restsharp.org/', description: 'Simple REST and HTTP API Client for .NET', }, - convert: ({ allHeaders, method, fullUrl, headersObj, cookies, postData }) => { + convert: ({ method, fullUrl, headersObj, cookies, postData, uriObj }) => { const { push, join } = new CodeBuilder(); const isSupportedMethod = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'].includes( method.toUpperCase() @@ -20,26 +24,67 @@ export const restsharp: Client = { return 'Method not supported'; } - push(`var client = new RestClient("${fullUrl}");`); - push(`var request = new RestRequest(Method.${method.toUpperCase()});`); + push(`var options = new RestClientOptions("${fullUrl}");`); + push('var client = new RestClient(options);'); - // Add headers, including the cookies + // The first argument is the sub-path to the base URL, given as the + // constructor to RestClient; for our purposes we're just giving the entire + // URL as the base path so it can be an empty string + push('var request = new RestRequest("");'); + // If we have multipart form data, set this value. Setting the content-type header manually and then trying to add a mutlipart file parameter + const isMultipart = postData.mimeType && postData.mimeType === 'multipart/form-data'; + if (isMultipart) { + push('request.AlwaysMultipartFormData = true;'); + } + + // Add headers, including the cookies Object.keys(headersObj).forEach(key => { - push(`request.AddHeader("${key}", "${headersObj[key]}");`); + // if we have post data, restsharp really wants to set the contentType + // itself; do not add a content-type header or you end up with failures + // which manifest as unhandled exceptions. + if (postData.mimeType && key.toLowerCase() === 'content-type') { + if (isMultipart && postData.boundary) { + push(`request.FormBoundary = "${postData.boundary}";`); + } + return; + } + push(`request.AddHeader("${key}", "${escapeForDoubleQuotes(headersObj[key])}");`); }); cookies.forEach(({ name, value }) => { - push(`request.AddCookie("${name}", "${value}");`); + push(`request.AddCookie("${name}", "${escapeForDoubleQuotes(value)}", "${uriObj.pathname}", "${uriObj.host}");`); }); - if (postData.text) { - const header = getHeader(allHeaders, 'content-type'); - const text = JSON.stringify(postData.text); - push(`request.AddParameter("${header}", ${text}, ParameterType.RequestBody);`); + switch (postData.mimeType) { + case 'multipart/form-data': + if (!postData.params) break; + postData.params.forEach(param => { + if (param.fileName) { + push(`request.AddFile("${param.name}", "${param.fileName}");`); + } else { + push(`request.AddParameter("${param.name}", "${param.value}");`); + } + }); + break; + case 'application/x-www-form-urlencoded': + if (!postData.params) break; + postData.params.forEach(param => { + push(`request.AddParameter("${param.name}", "${param.value}");`); + }); + break; + case 'application/json': { + if (!postData.text) break; + const text = JSON.stringify(postData.text); + push(`request.AddJsonBody(${text}, false);`); + break; + } + default: + if (!postData.text) break; + push(`request.AddStringBody("${postData.text}", "${postData.mimeType}");`); } - push('IRestResponse response = client.Execute(request);'); + push(`var response = await client.${title(method)}Async(request); `); return join(); }, }; diff --git a/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs b/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs index 05f6dddcb..819b521ab 100644 --- a/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs +++ b/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs @@ -1,5 +1,6 @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/application-json.cs b/src/targets/csharp/restsharp/fixtures/application-json.cs index b57c30add..34edd58c7 100644 --- a/src/targets/csharp/restsharp/fixtures/application-json.cs +++ b/src/targets/csharp/restsharp/fixtures/application-json.cs @@ -1,5 +1,5 @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/cookies.cs b/src/targets/csharp/restsharp/fixtures/cookies.cs index d2a59ac10..59e948a73 100644 --- a/src/targets/csharp/restsharp/fixtures/cookies.cs +++ b/src/targets/csharp/restsharp/fixtures/cookies.cs @@ -1,5 +1,6 @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/full.cs b/src/targets/csharp/restsharp/fixtures/full.cs index d18090a79..12cb8bef2 100644 --- a/src/targets/csharp/restsharp/fixtures/full.cs +++ b/src/targets/csharp/restsharp/fixtures/full.cs @@ -1,8 +1,8 @@ -var client = new RestClient("https://httpbin.org/anything?foo=bar&foo=baz&baz=abc&key=value"); -var request = new RestRequest(Method.POST); +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); \ No newline at end of file +request.AddCookie("foo", "bar", "/anything", "httpbin.org"); +request.AddCookie("bar", "baz", "/anything", "httpbin.org"); +request.AddParameter("foo", "bar"); +var response = await client.PostAsync(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/headers.cs b/src/targets/csharp/restsharp/fixtures/headers.cs index d89882101..de39cfda0 100644 --- a/src/targets/csharp/restsharp/fixtures/headers.cs +++ b/src/targets/csharp/restsharp/fixtures/headers.cs @@ -1,6 +1,7 @@ -var client = new RestClient("https://httpbin.org/headers"); -var request = new RestRequest(Method.GET); +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"); -IRestResponse response = client.Execute(request); \ No newline at end of file +var response = await client.GetAsync(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/http-insecure.cs b/src/targets/csharp/restsharp/fixtures/http-insecure.cs index 7fd60f467..8bd8082dc 100644 --- a/src/targets/csharp/restsharp/fixtures/http-insecure.cs +++ b/src/targets/csharp/restsharp/fixtures/http-insecure.cs @@ -1,3 +1,4 @@ -var client = new RestClient("http://httpbin.org/anything"); -var request = new RestRequest(Method.GET); -IRestResponse response = client.Execute(request); \ No newline at end of file +var options = new RestClientOptions("http://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +var response = await client.GetAsync(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs b/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs index e0ee8ed20..515e5054c 100644 --- a/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs +++ b/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs @@ -1,5 +1,5 @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs b/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs index 21685e0c5..5e501f544 100644 --- a/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs +++ b/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs @@ -1,5 +1,5 @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-data.cs b/src/targets/csharp/restsharp/fixtures/multipart-data.cs index f0e00ceb9..61342dde2 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-data.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-data.cs @@ -1,5 +1,8 @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-file.cs b/src/targets/csharp/restsharp/fixtures/multipart-file.cs index 03cd703e1..9af68d0e4 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-file.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-file.cs @@ -1,5 +1,7 @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs b/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs index 79f99ba17..d8664ab8d 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs @@ -1,4 +1,5 @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs b/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs index 0d8e48f7d..35f238645 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs @@ -1,5 +1,7 @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/nested.cs b/src/targets/csharp/restsharp/fixtures/nested.cs index 345a3c7a5..cfe5393bb 100644 --- a/src/targets/csharp/restsharp/fixtures/nested.cs +++ b/src/targets/csharp/restsharp/fixtures/nested.cs @@ -1,3 +1,4 @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs b/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs index e7a496e4d..f52707aeb 100644 --- a/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs +++ b/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs @@ -1,4 +1,4 @@ -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); \ No newline at end of file +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +var response = await client.PostAsync(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/query-encoded.cs b/src/targets/csharp/restsharp/fixtures/query-encoded.cs index c998ebb76..6c2d70968 100644 --- a/src/targets/csharp/restsharp/fixtures/query-encoded.cs +++ b/src/targets/csharp/restsharp/fixtures/query-encoded.cs @@ -1,3 +1,4 @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/query.cs b/src/targets/csharp/restsharp/fixtures/query.cs index 0d8135f6e..95da83249 100644 --- a/src/targets/csharp/restsharp/fixtures/query.cs +++ b/src/targets/csharp/restsharp/fixtures/query.cs @@ -1,3 +1,4 @@ -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); \ No newline at end of file +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); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/short.cs b/src/targets/csharp/restsharp/fixtures/short.cs index a62cf8a80..2a7c87320 100644 --- a/src/targets/csharp/restsharp/fixtures/short.cs +++ b/src/targets/csharp/restsharp/fixtures/short.cs @@ -1,3 +1,4 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.GET); -IRestResponse response = client.Execute(request); \ No newline at end of file +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +var response = await client.GetAsync(request); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/text-plain.cs b/src/targets/csharp/restsharp/fixtures/text-plain.cs index c434206c7..9eb0d9bbc 100644 --- a/src/targets/csharp/restsharp/fixtures/text-plain.cs +++ b/src/targets/csharp/restsharp/fixtures/text-plain.cs @@ -1,5 +1,5 @@ -var client = new RestClient("https://httpbin.org/anything"); -var request = new RestRequest(Method.POST); -request.AddHeader("content-type", "text/plain"); -request.AddParameter("text/plain", "Hello World", ParameterType.RequestBody); -IRestResponse response = client.Execute(request); \ No newline at end of file +var options = new RestClientOptions("https://httpbin.org/anything"); +var client = new RestClient(options); +var request = new RestRequest(""); +request.AddStringBody("Hello World", "text/plain"); +var response = await client.PostAsync(request); \ No newline at end of file From 5434855092fb389d83522c7790bb8a0b9edf59f8 Mon Sep 17 00:00:00 2001 From: Bill Mill Date: Fri, 16 Jun 2023 14:46:36 -0400 Subject: [PATCH 2/5] add 'using RestSharp' --- src/targets/csharp/restsharp/client.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/targets/csharp/restsharp/client.ts b/src/targets/csharp/restsharp/client.ts index 43f85742d..068aca065 100644 --- a/src/targets/csharp/restsharp/client.ts +++ b/src/targets/csharp/restsharp/client.ts @@ -24,6 +24,7 @@ export const restsharp: Client = { return 'Method not supported'; } + push('using RestSharp;\n\n'); push(`var options = new RestClientOptions("${fullUrl}");`); push('var client = new RestClient(options);'); From de74700c9b03b7814e992f3d783e8bb779a05e7d Mon Sep 17 00:00:00 2001 From: Bill Mill Date: Fri, 16 Jun 2023 14:46:41 -0400 Subject: [PATCH 3/5] update fixtures --- .../csharp/restsharp/fixtures/application-form-encoded.cs | 3 +++ src/targets/csharp/restsharp/fixtures/application-json.cs | 3 +++ src/targets/csharp/restsharp/fixtures/cookies.cs | 3 +++ src/targets/csharp/restsharp/fixtures/full.cs | 3 +++ src/targets/csharp/restsharp/fixtures/headers.cs | 3 +++ src/targets/csharp/restsharp/fixtures/http-insecure.cs | 3 +++ src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs | 3 +++ src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs | 3 +++ src/targets/csharp/restsharp/fixtures/multipart-data.cs | 3 +++ src/targets/csharp/restsharp/fixtures/multipart-file.cs | 3 +++ .../csharp/restsharp/fixtures/multipart-form-data-no-params.cs | 3 +++ src/targets/csharp/restsharp/fixtures/multipart-form-data.cs | 3 +++ src/targets/csharp/restsharp/fixtures/nested.cs | 3 +++ src/targets/csharp/restsharp/fixtures/postdata-malformed.cs | 3 +++ src/targets/csharp/restsharp/fixtures/query-encoded.cs | 3 +++ src/targets/csharp/restsharp/fixtures/query.cs | 3 +++ src/targets/csharp/restsharp/fixtures/short.cs | 3 +++ src/targets/csharp/restsharp/fixtures/text-plain.cs | 3 +++ 18 files changed, 54 insertions(+) diff --git a/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs b/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs index 819b521ab..e9c16676b 100644 --- a/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs +++ b/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/application-json.cs b/src/targets/csharp/restsharp/fixtures/application-json.cs index 34edd58c7..9a4a0d7d2 100644 --- a/src/targets/csharp/restsharp/fixtures/application-json.cs +++ b/src/targets/csharp/restsharp/fixtures/application-json.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/cookies.cs b/src/targets/csharp/restsharp/fixtures/cookies.cs index 59e948a73..1567cbb8e 100644 --- a/src/targets/csharp/restsharp/fixtures/cookies.cs +++ b/src/targets/csharp/restsharp/fixtures/cookies.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/cookies"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/full.cs b/src/targets/csharp/restsharp/fixtures/full.cs index 12cb8bef2..87011da15 100644 --- a/src/targets/csharp/restsharp/fixtures/full.cs +++ b/src/targets/csharp/restsharp/fixtures/full.cs @@ -1,3 +1,6 @@ +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(""); diff --git a/src/targets/csharp/restsharp/fixtures/headers.cs b/src/targets/csharp/restsharp/fixtures/headers.cs index de39cfda0..dde35f7f6 100644 --- a/src/targets/csharp/restsharp/fixtures/headers.cs +++ b/src/targets/csharp/restsharp/fixtures/headers.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/headers"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/http-insecure.cs b/src/targets/csharp/restsharp/fixtures/http-insecure.cs index 8bd8082dc..e268449c9 100644 --- a/src/targets/csharp/restsharp/fixtures/http-insecure.cs +++ b/src/targets/csharp/restsharp/fixtures/http-insecure.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("http://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs b/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs index 515e5054c..6fbb00180 100644 --- a/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs +++ b/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs b/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs index 5e501f544..9bce6bec1 100644 --- a/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs +++ b/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/multipart-data.cs b/src/targets/csharp/restsharp/fixtures/multipart-data.cs index 61342dde2..fcda5f289 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-data.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-data.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/multipart-file.cs b/src/targets/csharp/restsharp/fixtures/multipart-file.cs index 9af68d0e4..5a38a3e16 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-file.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-file.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs b/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs index d8664ab8d..65924aca3 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs b/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs index 35f238645..a561d71fb 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/nested.cs b/src/targets/csharp/restsharp/fixtures/nested.cs index cfe5393bb..cdada0519 100644 --- a/src/targets/csharp/restsharp/fixtures/nested.cs +++ b/src/targets/csharp/restsharp/fixtures/nested.cs @@ -1,3 +1,6 @@ +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(""); diff --git a/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs b/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs index f52707aeb..eae5dd38a 100644 --- a/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs +++ b/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/query-encoded.cs b/src/targets/csharp/restsharp/fixtures/query-encoded.cs index 6c2d70968..6a93eeee6 100644 --- a/src/targets/csharp/restsharp/fixtures/query-encoded.cs +++ b/src/targets/csharp/restsharp/fixtures/query-encoded.cs @@ -1,3 +1,6 @@ +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(""); diff --git a/src/targets/csharp/restsharp/fixtures/query.cs b/src/targets/csharp/restsharp/fixtures/query.cs index 95da83249..58cbbd30d 100644 --- a/src/targets/csharp/restsharp/fixtures/query.cs +++ b/src/targets/csharp/restsharp/fixtures/query.cs @@ -1,3 +1,6 @@ +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(""); diff --git a/src/targets/csharp/restsharp/fixtures/short.cs b/src/targets/csharp/restsharp/fixtures/short.cs index 2a7c87320..92443e4fa 100644 --- a/src/targets/csharp/restsharp/fixtures/short.cs +++ b/src/targets/csharp/restsharp/fixtures/short.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); diff --git a/src/targets/csharp/restsharp/fixtures/text-plain.cs b/src/targets/csharp/restsharp/fixtures/text-plain.cs index 9eb0d9bbc..f7f7c7c9d 100644 --- a/src/targets/csharp/restsharp/fixtures/text-plain.cs +++ b/src/targets/csharp/restsharp/fixtures/text-plain.cs @@ -1,3 +1,6 @@ +using RestSharp; + + var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); From 3efce8ef9bb1a12afbbbc04abbce98be98597bc2 Mon Sep 17 00:00:00 2001 From: Bill Mill Date: Fri, 16 Jun 2023 14:49:53 -0400 Subject: [PATCH 4/5] add write response.content at end --- src/targets/csharp/restsharp/client.ts | 5 ++++- .../csharp/restsharp/fixtures/application-form-encoded.cs | 4 +++- src/targets/csharp/restsharp/fixtures/application-json.cs | 4 +++- src/targets/csharp/restsharp/fixtures/cookies.cs | 4 +++- src/targets/csharp/restsharp/fixtures/full.cs | 4 +++- src/targets/csharp/restsharp/fixtures/headers.cs | 4 +++- src/targets/csharp/restsharp/fixtures/http-insecure.cs | 4 +++- src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs | 4 +++- src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs | 4 +++- src/targets/csharp/restsharp/fixtures/multipart-data.cs | 4 +++- src/targets/csharp/restsharp/fixtures/multipart-file.cs | 4 +++- .../restsharp/fixtures/multipart-form-data-no-params.cs | 4 +++- src/targets/csharp/restsharp/fixtures/multipart-form-data.cs | 4 +++- src/targets/csharp/restsharp/fixtures/nested.cs | 4 +++- src/targets/csharp/restsharp/fixtures/postdata-malformed.cs | 4 +++- src/targets/csharp/restsharp/fixtures/query-encoded.cs | 4 +++- src/targets/csharp/restsharp/fixtures/query.cs | 4 +++- src/targets/csharp/restsharp/fixtures/short.cs | 4 +++- src/targets/csharp/restsharp/fixtures/text-plain.cs | 4 +++- 19 files changed, 58 insertions(+), 19 deletions(-) diff --git a/src/targets/csharp/restsharp/client.ts b/src/targets/csharp/restsharp/client.ts index 068aca065..20fa85cf3 100644 --- a/src/targets/csharp/restsharp/client.ts +++ b/src/targets/csharp/restsharp/client.ts @@ -85,7 +85,10 @@ export const restsharp: Client = { push(`request.AddStringBody("${postData.text}", "${postData.mimeType}");`); } - push(`var response = await client.${title(method)}Async(request); `); + push(`var response = await client.${title(method)}Async(request);\n`); + + push('Console.WriteLine("{0}", response.Content);'); + return join(); }, }; diff --git a/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs b/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs index e9c16676b..c1acb2e73 100644 --- a/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs +++ b/src/targets/csharp/restsharp/fixtures/application-form-encoded.cs @@ -6,4 +6,6 @@ var request = new RestRequest(""); request.AddParameter("foo", "bar"); request.AddParameter("hello", "world"); -var response = await client.PostAsync(request); \ No newline at end of file +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/application-json.cs b/src/targets/csharp/restsharp/fixtures/application-json.cs index 9a4a0d7d2..8fa3dad74 100644 --- a/src/targets/csharp/restsharp/fixtures/application-json.cs +++ b/src/targets/csharp/restsharp/fixtures/application-json.cs @@ -5,4 +5,6 @@ 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); \ No newline at end of file +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/cookies.cs b/src/targets/csharp/restsharp/fixtures/cookies.cs index 1567cbb8e..1bedc6df1 100644 --- a/src/targets/csharp/restsharp/fixtures/cookies.cs +++ b/src/targets/csharp/restsharp/fixtures/cookies.cs @@ -6,4 +6,6 @@ var request = new RestRequest(""); request.AddCookie("foo", "bar", "/cookies", "httpbin.org"); request.AddCookie("bar", "baz", "/cookies", "httpbin.org"); -var response = await client.GetAsync(request); \ No newline at end of file +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/full.cs b/src/targets/csharp/restsharp/fixtures/full.cs index 87011da15..aa3fd11d7 100644 --- a/src/targets/csharp/restsharp/fixtures/full.cs +++ b/src/targets/csharp/restsharp/fixtures/full.cs @@ -8,4 +8,6 @@ request.AddCookie("foo", "bar", "/anything", "httpbin.org"); request.AddCookie("bar", "baz", "/anything", "httpbin.org"); request.AddParameter("foo", "bar"); -var response = await client.PostAsync(request); \ No newline at end of file +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/headers.cs b/src/targets/csharp/restsharp/fixtures/headers.cs index dde35f7f6..ab3004d7a 100644 --- a/src/targets/csharp/restsharp/fixtures/headers.cs +++ b/src/targets/csharp/restsharp/fixtures/headers.cs @@ -7,4 +7,6 @@ request.AddHeader("accept", "application/json"); request.AddHeader("x-foo", "Bar"); request.AddHeader("x-bar", "Foo"); -var response = await client.GetAsync(request); \ No newline at end of file +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/http-insecure.cs b/src/targets/csharp/restsharp/fixtures/http-insecure.cs index e268449c9..79986efb8 100644 --- a/src/targets/csharp/restsharp/fixtures/http-insecure.cs +++ b/src/targets/csharp/restsharp/fixtures/http-insecure.cs @@ -4,4 +4,6 @@ var options = new RestClientOptions("http://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); -var response = await client.GetAsync(request); \ No newline at end of file +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs b/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs index 6fbb00180..2bd85bd7a 100644 --- a/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs +++ b/src/targets/csharp/restsharp/fixtures/jsonObj-multiline.cs @@ -5,4 +5,6 @@ var client = new RestClient(options); var request = new RestRequest(""); request.AddJsonBody("{\n \"foo\": \"bar\"\n}", false); -var response = await client.PostAsync(request); \ No newline at end of file +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs b/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs index 9bce6bec1..a9a5ca673 100644 --- a/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs +++ b/src/targets/csharp/restsharp/fixtures/jsonObj-null-value.cs @@ -5,4 +5,6 @@ var client = new RestClient(options); var request = new RestRequest(""); request.AddJsonBody("{\"foo\":null}", false); -var response = await client.PostAsync(request); \ No newline at end of file +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-data.cs b/src/targets/csharp/restsharp/fixtures/multipart-data.cs index fcda5f289..b256b6997 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-data.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-data.cs @@ -8,4 +8,6 @@ request.FormBoundary = "---011000010111000001101001"; request.AddFile("foo", "src/fixtures/files/hello.txt"); request.AddParameter("bar", "Bonjour le monde"); -var response = await client.PostAsync(request); \ No newline at end of file +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-file.cs b/src/targets/csharp/restsharp/fixtures/multipart-file.cs index 5a38a3e16..d1fda9b99 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-file.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-file.cs @@ -7,4 +7,6 @@ request.AlwaysMultipartFormData = true; request.FormBoundary = "---011000010111000001101001"; request.AddFile("foo", "src/fixtures/files/hello.txt"); -var response = await client.PostAsync(request); \ No newline at end of file +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs b/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs index 65924aca3..f52b66da6 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-form-data-no-params.cs @@ -5,4 +5,6 @@ var client = new RestClient(options); var request = new RestRequest(""); request.AlwaysMultipartFormData = true; -var response = await client.PostAsync(request); \ No newline at end of file +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs b/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs index a561d71fb..2456020a1 100644 --- a/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs +++ b/src/targets/csharp/restsharp/fixtures/multipart-form-data.cs @@ -7,4 +7,6 @@ request.AlwaysMultipartFormData = true; request.FormBoundary = "---011000010111000001101001"; request.AddParameter("foo", "bar"); -var response = await client.PostAsync(request); \ No newline at end of file +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/nested.cs b/src/targets/csharp/restsharp/fixtures/nested.cs index cdada0519..57b8ffb28 100644 --- a/src/targets/csharp/restsharp/fixtures/nested.cs +++ b/src/targets/csharp/restsharp/fixtures/nested.cs @@ -4,4 +4,6 @@ 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); \ No newline at end of file +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs b/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs index eae5dd38a..147e990fa 100644 --- a/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs +++ b/src/targets/csharp/restsharp/fixtures/postdata-malformed.cs @@ -4,4 +4,6 @@ var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); -var response = await client.PostAsync(request); \ No newline at end of file +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/query-encoded.cs b/src/targets/csharp/restsharp/fixtures/query-encoded.cs index 6a93eeee6..f60e554dc 100644 --- a/src/targets/csharp/restsharp/fixtures/query-encoded.cs +++ b/src/targets/csharp/restsharp/fixtures/query-encoded.cs @@ -4,4 +4,6 @@ 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); \ No newline at end of file +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/query.cs b/src/targets/csharp/restsharp/fixtures/query.cs index 58cbbd30d..bca7ca7b7 100644 --- a/src/targets/csharp/restsharp/fixtures/query.cs +++ b/src/targets/csharp/restsharp/fixtures/query.cs @@ -4,4 +4,6 @@ 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); \ No newline at end of file +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/short.cs b/src/targets/csharp/restsharp/fixtures/short.cs index 92443e4fa..76ad84cec 100644 --- a/src/targets/csharp/restsharp/fixtures/short.cs +++ b/src/targets/csharp/restsharp/fixtures/short.cs @@ -4,4 +4,6 @@ var options = new RestClientOptions("https://httpbin.org/anything"); var client = new RestClient(options); var request = new RestRequest(""); -var response = await client.GetAsync(request); \ No newline at end of file +var response = await client.GetAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file diff --git a/src/targets/csharp/restsharp/fixtures/text-plain.cs b/src/targets/csharp/restsharp/fixtures/text-plain.cs index f7f7c7c9d..20d61e5b7 100644 --- a/src/targets/csharp/restsharp/fixtures/text-plain.cs +++ b/src/targets/csharp/restsharp/fixtures/text-plain.cs @@ -5,4 +5,6 @@ var client = new RestClient(options); var request = new RestRequest(""); request.AddStringBody("Hello World", "text/plain"); -var response = await client.PostAsync(request); \ No newline at end of file +var response = await client.PostAsync(request); + +Console.WriteLine("{0}", response.Content); \ No newline at end of file From 544b2261eabf470ec916210fd574dfea3e3cdfbf Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Fri, 16 Jun 2023 16:05:07 -0700 Subject: [PATCH 5/5] fix: undoing some accidental changes --- src/helpers/escape.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/helpers/escape.ts b/src/helpers/escape.ts index fabe32904..4330fc88f 100644 --- a/src/helpers/escape.ts +++ b/src/helpers/escape.ts @@ -45,6 +45,7 @@ export function escapeString(rawValue: any, options: EscapeOptions = {}) { if (escapeNewlines) { return `${escapeChar}n`; } + return c; // Don't just continue, or this is caught by < \u0020 } else if (c === '\f') { return `${escapeChar}f`; @@ -52,6 +53,7 @@ export function escapeString(rawValue: any, options: EscapeOptions = {}) { if (escapeNewlines) { return `${escapeChar}r`; } + return c; // Don't just continue, or this is caught by < \u0020 } else if (c === escapeChar) { return escapeChar + escapeChar; @@ -64,6 +66,7 @@ export function escapeString(rawValue: any, options: EscapeOptions = {}) { // strictly?) ASCII-only, this should almost never happen. return JSON.stringify(c).slice(1, -1); } + return c; }) .join('');