Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f620dc0

Browse files
authoredJan 29, 2021
Merge pull request #9 from atc-net/hotfix/ensure_content_is_not_set_on_get_head_calls
Ensuring we dont set content, when there is no content
2 parents 6d51ee2 + e64de52 commit f620dc0

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed
 

‎src/Atc.Rest.Client/Builder/IHttpMessageFactory.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public interface IHttpMessageFactory
1717
/// </summary>
1818
/// <exception cref="ArgumentNullException">Thrown when <paramref name="pathTemplate"/> is null.</exception>
1919
/// <param name="pathTemplate">The relative URI to request. Can contain tokens,
20-
/// that will be replaced with real values pass to the <see cref="IMessageRequestBuilder.WithPathParameter(string, string)"/>
20+
/// that will be replaced with real values passed to the <see cref="IMessageRequestBuilder.WithPathParameter(string, object?)"/>
2121
/// method.</param>
2222
/// <returns>A new <see cref="IMessageRequestBuilder"/>.</returns>
2323
IMessageRequestBuilder FromTemplate(string pathTemplate);
2424

2525
IMessageResponseBuilder FromResponse(HttpResponseMessage? response);
2626
}
27-
}
27+
}

‎src/Atc.Rest.Client/Builder/MessageRequestBuilder.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal class MessageRequestBuilder : IMessageRequestBuilder
1515
private readonly Dictionary<string, string> pathMapper;
1616
private readonly Dictionary<string, string> headerMapper;
1717
private readonly Dictionary<string, string> queryMapper;
18-
private string content = string.Empty;
18+
private string? content;
1919

2020
public MessageRequestBuilder(string pathTemplate, IContractSerializer serializer)
2121
{
@@ -24,6 +24,7 @@ public MessageRequestBuilder(string pathTemplate, IContractSerializer serializer
2424
pathMapper = new Dictionary<string, string>(StringComparer.Ordinal);
2525
headerMapper = new Dictionary<string, string>(StringComparer.Ordinal);
2626
queryMapper = new Dictionary<string, string>(StringComparer.Ordinal);
27+
WithHeaderParameter("accept", "application/json");
2728
}
2829

2930
public HttpRequestMessage Build(HttpMethod method)
@@ -37,10 +38,14 @@ public HttpRequestMessage Build(HttpMethod method)
3738
}
3839

3940
message.RequestUri = BuildRequestUri();
40-
message.Content = new StringContent(content);
41-
message.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
4241
message.Method = method;
4342

43+
if (content is not null)
44+
{
45+
message.Content = new StringContent(content);
46+
message.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
47+
}
48+
4449
return message;
4550
}
4651

@@ -126,4 +131,4 @@ private Uri BuildRequestUri()
126131
return new Uri(urlBuilder.ToString(), UriKind.RelativeOrAbsolute);
127132
}
128133
}
129-
}
134+
}

0 commit comments

Comments
 (0)
Please sign in to comment.