Skip to content

Commit

Permalink
GetHeadersString()判断Uri
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Jan 18, 2021
1 parent 685f8ce commit 47d97b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 0 additions & 1 deletion App/Clients/IUserApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace App.Clients
/// </summary>
[LoggingFilter]
[OAuthToken]
[HttpHost("http://localhost:6000/")]
public interface IUserApi : IHttpApi
{
[HttpGet("api/users/{account}")]
Expand Down
15 changes: 10 additions & 5 deletions WebApiClientCore/HttpApiRequestMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,18 @@ private void EnsureMediaTypeEqual(string newMediaType)
/// <returns></returns>
public string GetHeadersString()
{
const string host = "Host";
var builder = new StringBuilder()
.AppendLine($"{this.Method} {this.RequestUri.PathAndQuery} HTTP/{this.Version}");
var uri = this.RequestUri;
var builder = new StringBuilder();

if (this.Headers.Contains(host) == false)
if (uri != null && uri.IsAbsoluteUri)
{
builder.AppendLine($"{host}: {this.RequestUri.Authority}");
const string host = "Host";
builder.AppendLine($"{this.Method} {uri.PathAndQuery} HTTP/{this.Version}");

if (this.Headers.Contains(host) == false)
{
builder.AppendLine($"{host}: {uri.Authority}");
}
}

builder.Append(this.Headers.ToString());
Expand Down

0 comments on commit 47d97b3

Please sign in to comment.