Skip to content

Commit 659511f

Browse files
author
Michael Hallett
committed
Added a condition for CF on Encode Parameters; Code Cleanup;
1 parent b051b23 commit 659511f

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

RestSharp/Http.Async.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#endregion
1616

1717
using System;
18+
using System.Linq;
1819
using System.Net;
1920
using System.Threading;
2021
using RestSharp.Extensions;
@@ -219,10 +220,8 @@ private long CalculateContentLength()
219220
length += this.Encoding.GetByteCount(LINE_BREAK);
220221
}
221222

222-
foreach (var param in Parameters)
223-
{
224-
length += this.Encoding.GetByteCount(GetMultipartFormData(param));
225-
}
223+
length = this.Parameters.Aggregate(length,
224+
(current, param) => current + this.Encoding.GetByteCount(this.GetMultipartFormData(param)));
226225

227226
length += this.Encoding.GetByteCount(GetMultipartFooter());
228227
return length;
@@ -304,7 +303,6 @@ private static void TimeoutCallback(object state, bool timedOut)
304303

305304
private static void GetRawResponseAsync(IAsyncResult result, Action<HttpWebResponse> callback)
306305
{
307-
var response = new HttpResponse { ResponseStatus = ResponseStatus.None };
308306
HttpWebResponse raw;
309307

310308
try

RestSharp/Http.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,17 @@ private void AddSharedHeaderActions()
244244
#endif
245245
}
246246

247-
private const string FormBoundary = "-----------------------------28947758029299";
247+
private const string FORM_BOUNDARY = "-----------------------------28947758029299";
248248

249249
private static string GetMultipartFormContentType()
250250
{
251-
return string.Format("multipart/form-data; boundary={0}", FormBoundary);
251+
return string.Format("multipart/form-data; boundary={0}", FORM_BOUNDARY);
252252
}
253253

254254
private static string GetMultipartFileHeader(HttpFile file)
255255
{
256256
return string.Format("--{0}{4}Content-Disposition: form-data; name=\"{1}\"; filename=\"{2}\"{4}Content-Type: {3}{4}{4}",
257-
FormBoundary, file.Name, file.FileName, file.ContentType ?? "application/octet-stream", LINE_BREAK);
257+
FORM_BOUNDARY, file.Name, file.FileName, file.ContentType ?? "application/octet-stream", LINE_BREAK);
258258
}
259259

260260
private string GetMultipartFormData(HttpParameter param)
@@ -263,12 +263,12 @@ private string GetMultipartFormData(HttpParameter param)
263263
? "--{0}{3}Content-Type: {1}{3}Content-Disposition: form-data; name=\"{1}\"{3}{3}{2}{3}"
264264
: "--{0}{3}Content-Disposition: form-data; name=\"{1}\"{3}{3}{2}{3}";
265265

266-
return string.Format(format, FormBoundary, param.Name, param.Value, LINE_BREAK);
266+
return string.Format(format, FORM_BOUNDARY, param.Name, param.Value, LINE_BREAK);
267267
}
268268

269269
private static string GetMultipartFooter()
270270
{
271-
return string.Format("--{0}--{1}", FormBoundary, LINE_BREAK);
271+
return string.Format("--{0}--{1}", FORM_BOUNDARY, LINE_BREAK);
272272
}
273273

274274
private readonly IDictionary<string, Action<HttpWebRequest, string>> restrictedHeaderActions;

RestSharp/RestClient.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ public Uri BuildUri(IRestRequest request)
321321

322322
private static string EncodeParameters(IEnumerable<Parameter> parameters)
323323
{
324+
#if !PocketPC
324325
return string.Join("&", parameters.Select(EncodeParameter).ToArray());
326+
#else
327+
return string.Join("&", parameters.Select(x => EncodeParameter(x)).ToArray());
328+
#endif
325329
}
326330

327331
private static string EncodeParameter(Parameter parameter)

0 commit comments

Comments
 (0)