#183 Set empty paths for OPTIONS * requests
This commit is contained in:
parent
c2f52db3a5
commit
3d1dbbaae5
|
|
@ -64,6 +64,10 @@ namespace Microsoft.Net.Http.Server
|
|||
SslStatus = memoryBlob.RequestBlob->pSslInfo == null ? SslStatus.Insecure :
|
||||
memoryBlob.RequestBlob->pSslInfo->SslClientCertNegotiated == 0 ? SslStatus.NoClientCert :
|
||||
SslStatus.ClientCert;
|
||||
|
||||
KnownMethod = memoryBlob.RequestBlob->Verb;
|
||||
Method = HttpApi.GetVerb(memoryBlob.RequestBlob);
|
||||
|
||||
if (memoryBlob.RequestBlob->pRawUrl != null && memoryBlob.RequestBlob->RawUrlLength > 0)
|
||||
{
|
||||
RawUrl = Marshal.PtrToStringAnsi((IntPtr)memoryBlob.RequestBlob->pRawUrl, memoryBlob.RequestBlob->RawUrlLength);
|
||||
|
|
@ -89,8 +93,14 @@ namespace Microsoft.Net.Http.Server
|
|||
var prefix = requestContext.Server.Settings.UrlPrefixes.GetPrefix((int)memoryBlob.RequestBlob->UrlContext);
|
||||
var originalPath = RequestUriBuilder.GetRequestPath(RawUrl, cookedUrlPath, RequestContext.Logger);
|
||||
|
||||
// 'OPTIONS * HTTP/1.1'
|
||||
if (KnownMethod == HttpApi.HTTP_VERB.HttpVerbOPTIONS && string.Equals(RawUrl, "*", StringComparison.Ordinal))
|
||||
{
|
||||
PathBase = string.Empty;
|
||||
Path = string.Empty;
|
||||
}
|
||||
// These paths are both unescaped already.
|
||||
if (originalPath.Length == prefix.Path.Length - 1)
|
||||
else if (originalPath.Length == prefix.Path.Length - 1)
|
||||
{
|
||||
// They matched exactly except for the trailing slash.
|
||||
PathBase = originalPath;
|
||||
|
|
@ -119,8 +129,6 @@ namespace Microsoft.Net.Http.Server
|
|||
ProtocolVersion = new Version(major, minor);
|
||||
}
|
||||
|
||||
KnownMethod = memoryBlob.RequestBlob->Verb;
|
||||
Method = HttpApi.GetVerb(memoryBlob.RequestBlob);
|
||||
Headers = new HeaderCollection(new RequestHeaders(_nativeRequestContext));
|
||||
|
||||
var requestV2 = (HttpApi.HTTP_REQUEST_V2*)memoryBlob.RequestBlob;
|
||||
|
|
|
|||
|
|
@ -111,6 +111,21 @@ namespace Microsoft.Net.Http.Server
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Request_OptionsStar_EmptyPath()
|
||||
{
|
||||
string root;
|
||||
using (var server = Utilities.CreateHttpServerReturnRoot("/", out root))
|
||||
{
|
||||
var responseTask = SendSocketRequestAsync(root, "*", "OPTIONS");
|
||||
var context = await server.AcceptAsync();
|
||||
Assert.Equal("", context.Request.PathBase);
|
||||
Assert.Equal("", context.Request.Path);
|
||||
Assert.Equal("*", context.Request.RawUrl);
|
||||
context.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
// The test server defines these prefixes: "/", "/11", "/2/3", "/2", "/11/2"
|
||||
[InlineData("/", "", "/")]
|
||||
|
|
@ -163,11 +178,11 @@ namespace Microsoft.Net.Http.Server
|
|||
}
|
||||
}
|
||||
|
||||
private async Task<string> SendSocketRequestAsync(string address, string path)
|
||||
private async Task<string> SendSocketRequestAsync(string address, string path, string method = "GET")
|
||||
{
|
||||
var uri = new Uri(address);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.AppendLine("GET " + path + " HTTP/1.1");
|
||||
builder.AppendLine($"{method} {path} HTTP/1.1");
|
||||
builder.AppendLine("Connection: close");
|
||||
builder.Append("HOST: ");
|
||||
builder.AppendLine(uri.Authority);
|
||||
|
|
|
|||
Loading…
Reference in New Issue