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

Commit 15aea76

Browse files
author
Cesar Blum Silveira
committed
Add test for targets not starting with '/'.
1 parent 6ed1a73 commit 15aea76

File tree

2 files changed

+58
-2
lines changed
  • src/Microsoft.AspNetCore.Server.Kestrel/Http
  • test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests

2 files changed

+58
-2
lines changed

src/Microsoft.AspNetCore.Server.Kestrel/Http/Frame.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,10 +914,16 @@ protected RequestLineStatus TakeStartLine(SocketInput input)
914914
PathBase = caseMatches ? _pathBase : requestUrlPath.Substring(0, _pathBase.Length);
915915
Path = requestUrlPath.Substring(_pathBase.Length);
916916
}
917-
else
917+
else if (requestUrlPath[0] == '/')
918918
{
919919
Path = requestUrlPath;
920920
}
921+
else
922+
{
923+
Path = string.Empty;
924+
PathBase = string.Empty;
925+
QueryString = string.Empty;
926+
}
921927

922928
return RequestLineStatus.Done;
923929
}

test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public void RequestFeatureContainsRawTarget(string requestTarget)
217217
{
218218
var builder = new WebHostBuilder()
219219
.UseKestrel()
220-
.UseUrls($"http://localhost:0/base")
220+
.UseUrls($"http://127.0.0.1:0/base")
221221
.Configure(app =>
222222
{
223223
app.Run(async context =>
@@ -255,6 +255,56 @@ public void RequestFeatureContainsRawTarget(string requestTarget)
255255
}
256256
}
257257

258+
[Theory]
259+
[InlineData("*")]
260+
[InlineData("DoesNotStartWith/")]
261+
[InlineData("*?arg=value")]
262+
[InlineData("*/?arg=value")]
263+
public void NonPathRequestTargetSetInRawTarget(string requestTarget)
264+
{
265+
var builder = new WebHostBuilder()
266+
.UseKestrel()
267+
.UseUrls($"http://127.0.0.1:0/")
268+
.Configure(app =>
269+
{
270+
app.Run(async context =>
271+
{
272+
var connection = context.Connection;
273+
Assert.Equal(requestTarget, context.Features.Get<IHttpRequestFeature>().RawTarget);
274+
Assert.Empty(context.Request.Path.Value);
275+
Assert.Empty(context.Request.PathBase.Value);
276+
Assert.Empty(context.Request.QueryString.Value);
277+
await context.Response.WriteAsync("hello, world");
278+
});
279+
});
280+
281+
using (var host = builder.Build())
282+
{
283+
host.Start();
284+
285+
using (var socket = TestConnection.CreateConnectedLoopbackSocket(host.GetPort()))
286+
{
287+
socket.Send(Encoding.ASCII.GetBytes($"GET {requestTarget} HTTP/1.1\r\n\r\n"));
288+
socket.Shutdown(SocketShutdown.Send);
289+
290+
var response = new StringBuilder();
291+
var buffer = new byte[4096];
292+
while (true)
293+
{
294+
var length = socket.Receive(buffer);
295+
if (length == 0)
296+
{
297+
break;
298+
}
299+
300+
response.Append(Encoding.ASCII.GetString(buffer, 0, length));
301+
}
302+
303+
Assert.StartsWith("HTTP/1.1 200 OK", response.ToString());
304+
}
305+
}
306+
}
307+
258308
private async Task TestRemoteIPAddress(string registerAddress, string requestAddress, string expectAddress)
259309
{
260310
var builder = new WebHostBuilder()

0 commit comments

Comments
 (0)