Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit f5838ca

Browse files
committed
Move HasRequestBody to HttpUtls + specify ContentLength=0 when body=null
1 parent 5a7ae04 commit f5838ca

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/ServiceStack.Text.sln

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
Microsoft Visual Studio Solution File, Format Version 12.00
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
23
# Visual Studio 15
3-
VisualStudioVersion = 15.0.26730.3
4+
VisualStudioVersion = 15.0.27004.2009
45
MinimumVisualStudioVersion = 10.0.40219.1
56
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{F7FB50ED-EAFF-4839-935A-5BB4A4158245}"
67
ProjectSection(SolutionItems) = preProject
@@ -9,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{F7FB50ED
910
..\build\build.tasks = ..\build\build.tasks
1011
..\build\copy.bat = ..\build\copy.bat
1112
..\README.md = ..\README.md
13+
..\NuGet\ServiceStack.Text.Core\servicestack.text.core.nuspec = ..\NuGet\ServiceStack.Text.Core\servicestack.text.core.nuspec
1214
..\NuGet\ServiceStack.Text\servicestack.text.nuspec = ..\NuGet\ServiceStack.Text\servicestack.text.nuspec
1315
EndProjectSection
1416
EndProject

src/ServiceStack.Text/HttpUtils.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,20 @@ public static string SetHashParam(this string url, string key, string val)
106106
return url + prefix + key + "=" + val.UrlEncode();
107107
}
108108

109+
public static bool HasRequestBody(this string httpMethod)
110+
{
111+
switch (httpMethod)
112+
{
113+
case HttpMethods.Get:
114+
case HttpMethods.Delete:
115+
case HttpMethods.Head:
116+
case HttpMethods.Options:
117+
return false;
118+
}
119+
120+
return true;
121+
}
122+
109123
public static string GetJsonFromUrl(this string url,
110124
Action<HttpWebRequest> requestFilter = null, Action<HttpWebResponse> responseFilter = null)
111125
{
@@ -520,6 +534,10 @@ public static string SendStringToUrl(this string url, string method = null,
520534
writer.Write(requestBody);
521535
}
522536
}
537+
else if (method != null && method.HasRequestBody())
538+
{
539+
webReq.ContentLength = 0;
540+
}
523541

524542
using (var webRes = PclExport.Instance.GetResponse(webReq))
525543
using (var stream = webRes.GetResponseStream())

0 commit comments

Comments
 (0)