Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques
{
var message =
$"The {nameof(HeaderPropagationValues)}.{nameof(HeaderPropagationValues.Headers)} property has not been " +
$"initialized. Register the header propagation middleware by adding 'app.{nameof(HeaderPropagationApplicationBuilderExtensions.UseHeaderPropagation)}() " +
$"in the 'Configure(...)' method.";
$"initialized. Register the header propagation middleware by adding 'app.{nameof(HeaderPropagationApplicationBuilderExtensions.UseHeaderPropagation)}()' " +
$"in the 'Configure(...)' method. Also, do not use an HttpClient with header propagation outside of an incoming HTTP request.";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$"in the 'Configure(...)' method. Also, do not use an HttpClient with header propagation outside of an incoming HTTP request.";
$"in the 'Configure(...)' method. Header propagation can only be used within the context of an HTTP request.";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

throw new InvalidOperationException(message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,35 @@ public async Task HeaderPropagation_WithoutMiddleware_Throws()
Assert.IsType<InvalidOperationException>(captured);
Assert.Equal(
"The HeaderPropagationValues.Headers property has not been initialized. Register the header propagation middleware " +
"by adding 'app.UseHeaderPropagation() in the 'Configure(...)' method.",
"by adding 'app.UseHeaderPropagation()' in the 'Configure(...)' method. Also, do not use an HttpClient with header " +
"propagation outside of an incoming HTTP request.",
captured.Message);
}

[Fact]
public async Task HeaderPropagation_OutsideOfIncomingRequest_Throws()
{
// Arrange
var services = new ServiceCollection();
services.AddHttpClient("test").AddHeaderPropagation();
services.AddHeaderPropagation(options =>
{
options.Headers.Add("X-TraceId");
});
var serviceProvider = services.BuildServiceProvider();

// Act
var client = serviceProvider.GetRequiredService<IHttpClientFactory>().CreateClient("test");
var exception = await Assert.ThrowsAsync<InvalidOperationException>(() => client.GetAsync("http://localhost/"));

// Assert
Assert.Equal(
"The HeaderPropagationValues.Headers property has not been initialized. Register the header propagation middleware " +
"by adding 'app.UseHeaderPropagation()' in the 'Configure(...)' method. Also, do not use an HttpClient with header " +
"propagation outside of an incoming HTTP request.",
exception.Message);
}

[Fact]
public async Task HeaderInRequest_AddCorrectValue()
{
Expand Down