Skip to content

Commit 8c0bc90

Browse files
authored
Merge pull request #86 from launchdarkly/eb/sc-148431/http-request-modifier
tests/comment edits for new HttpRequestModifier feature
2 parents d688c6a + 912708a commit 8c0bc90

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/LaunchDarkly.EventSource/ConfigurationBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ public ConfigurationBuilder ConnectionTimeout(TimeSpan responseStartTimeout) =>
7878
ResponseStartTimeout(responseStartTimeout);
7979

8080
/// <summary>
81-
/// Sets a delegate hook invoked before an HTTP request has been performed.
81+
/// Sets a delegate hook invoked before an HTTP request is performed. This may be useful if you
82+
/// want to modify some properties of the request that EventSource doesn't already have an option for.
8283
/// </summary>
83-
/// <param name="httpRequestModifier">The hook delegate</param>
84+
/// <param name="httpRequestModifier">code that will be called with the request before it is sent</param>
8485
/// <returns>the builder</returns>
8586
public ConfigurationBuilder HttpRequestModifier(Action<HttpRequestMessage> httpRequestModifier)
8687
{

test/LaunchDarkly.EventSource.Tests/ConfigurationBuilderTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,5 +301,13 @@ public void BuilderSetsRequestBodyString()
301301
var c = b.Build().RequestBodyFactory();
302302
Assert.IsType<StringContent>(c);
303303
}
304+
305+
[Fact]
306+
public void BuilderSetsHttpRequestModifier()
307+
{
308+
Action<HttpRequestMessage> action = request => { };
309+
var b = Configuration.Builder(uri).HttpRequestModifier(action);
310+
Assert.Equal(action, b.Build().HttpRequestModifier);
311+
}
304312
}
305313
}

test/LaunchDarkly.EventSource.Tests/EventSourceHttpBehaviorTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,27 @@ public void CustomRequestHeaders()
144144
}
145145
}
146146

147+
[Fact]
148+
public void HttpRequestModifier()
149+
{
150+
using (var server = HttpServer.Start(EmptyStreamThatStaysOpen))
151+
{
152+
var headers = new Dictionary<string, string> { { "User-Agent", "mozilla" }, { "Authorization", "testing" } };
153+
154+
Action<HttpRequestMessage> modifier = request =>
155+
{
156+
request.RequestUri = new Uri(request.RequestUri.ToString() + "-modified");
157+
};
158+
using (var es = MakeEventSource(server.Uri, builder => builder.HttpRequestModifier(modifier)))
159+
{
160+
_ = Task.Run(es.StartAsync);
161+
162+
var req = server.Recorder.RequireRequest();
163+
Assert.EndsWith("-modified", req.Path);
164+
}
165+
}
166+
}
167+
147168
[Fact]
148169
public void ReceiveEventStreamInChunks()
149170
{

test/LaunchDarkly.EventSource.Tests/LaunchDarkly.EventSource.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
<ItemGroup>
2727
<ProjectReference Include="..\..\src\LaunchDarkly.EventSource\LaunchDarkly.EventSource.csproj" />
28-
<ProjectReference Include="..\..\..\dotnet-test-helpers\src\LaunchDarkly.TestHelpers\LaunchDarkly.TestHelpers.csproj" />
2928
</ItemGroup>
3029

3130
<ItemGroup>

0 commit comments

Comments
 (0)