Skip to content

Commit e14e7d2

Browse files
author
Shashi Ranjan
committed
using headersObj instead of headers
1 parent 91dd378 commit e14e7d2

6 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/targets/c#/restsharp.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var CodeBuilder = require('../../helpers/code-builder')
44

55
module.exports = function (source, options) {
66
var code = new CodeBuilder()
7-
87
var methods = [ 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS' ]
98

109
if (methods.indexOf(source.method.toUpperCase()) === -1) {
@@ -14,10 +13,13 @@ module.exports = function (source, options) {
1413
code.push('var request = new RestRequest(Method.%s);', source.method.toUpperCase())
1514
}
1615

16+
// Add headers, including the cookies
17+
var headers = Object.keys(source.headersObj)
18+
1719
// construct headers
18-
if (source.headers.length) {
19-
source.headers.forEach(function (header) {
20-
code.push('request.AddHeader("%s", "%s");', header.name, header.value)
20+
if (headers.length) {
21+
headers.map(function (key) {
22+
code.push('request.AddHeader("%s", "%s");', key, source.headersObj[key])
2123
})
2224
}
2325

test/fixtures/output/c#/restsharp/full.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var client = new RestClient("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value");
22
var request = new RestRequest(Method.POST);
3-
request.AddHeader("accept", "application/json");
43
request.AddHeader("content-type", "application/x-www-form-urlencoded");
4+
request.AddHeader("accept", "application/json");
55
request.AddCookie("foo", "bar");
66
request.AddCookie("bar", "baz");
77
request.AddParameter("application/x-www-form-urlencoded", "foo=bar", ParameterType.RequestBody);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var client = new RestClient("http://mockbin.com/har");
22
var request = new RestRequest(Method.GET);
3-
request.AddHeader("accept", "application/json");
43
request.AddHeader("x-foo", "Bar");
4+
request.AddHeader("accept", "application/json");
55
IRestResponse response = client.Execute(request);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var client = new RestClient("http://mockbin.com/har");
22
var request = new RestRequest(Method.POST);
3-
request.AddHeader("content-type", "multipart/form-data");
3+
request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001");
44
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--", ParameterType.RequestBody);
55
IRestResponse response = client.Execute(request);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var client = new RestClient("http://mockbin.com/har");
22
var request = new RestRequest(Method.POST);
3-
request.AddHeader("content-type", "multipart/form-data");
3+
request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001");
44
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--", ParameterType.RequestBody);
55
IRestResponse response = client.Execute(request);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var client = new RestClient("http://mockbin.com/har");
22
var request = new RestRequest(Method.POST);
3-
request.AddHeader("content-type", "multipart/form-data");
3+
request.AddHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001");
44
request.AddParameter("multipart/form-data; boundary=---011000010111000001101001", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--", ParameterType.RequestBody);
55
IRestResponse response = client.Execute(request);

0 commit comments

Comments
 (0)