Remove unused code. Reduce class nesting.
This commit is contained in:
parent
4b36501bd8
commit
ce06c0b241
|
|
@ -164,10 +164,10 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
retry = false;
|
retry = false;
|
||||||
uint bytesTransferred = 0;
|
uint bytesTransferred = 0;
|
||||||
statusCode = UnsafeNclNativeMethods.HttpApi.HttpReceiveHttpRequest(
|
statusCode = HttpApi.HttpReceiveHttpRequest(
|
||||||
Server.RequestQueue.Handle,
|
Server.RequestQueue.Handle,
|
||||||
_nativeRequestContext.RequestBlob->RequestId,
|
_nativeRequestContext.RequestBlob->RequestId,
|
||||||
(uint)UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY,
|
(uint)HttpApi.HTTP_FLAGS.HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY,
|
||||||
_nativeRequestContext.RequestBlob,
|
_nativeRequestContext.RequestBlob,
|
||||||
_nativeRequestContext.Size,
|
_nativeRequestContext.Size,
|
||||||
&bytesTransferred,
|
&bytesTransferred,
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
public sealed class AuthenticationManager
|
public sealed class AuthenticationManager
|
||||||
{
|
{
|
||||||
private static readonly int AuthInfoSize =
|
private static readonly int AuthInfoSize =
|
||||||
Marshal.SizeOf<UnsafeNclNativeMethods.HttpApi.HTTP_SERVER_AUTHENTICATION_INFO>();
|
Marshal.SizeOf<HttpApi.HTTP_SERVER_AUTHENTICATION_INFO>();
|
||||||
|
|
||||||
private WebListener _server;
|
private WebListener _server;
|
||||||
private AuthenticationSchemes _authSchemes;
|
private AuthenticationSchemes _authSchemes;
|
||||||
|
|
@ -73,12 +73,12 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
private unsafe void SetServerSecurity()
|
private unsafe void SetServerSecurity()
|
||||||
{
|
{
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_SERVER_AUTHENTICATION_INFO authInfo =
|
HttpApi.HTTP_SERVER_AUTHENTICATION_INFO authInfo =
|
||||||
new UnsafeNclNativeMethods.HttpApi.HTTP_SERVER_AUTHENTICATION_INFO();
|
new HttpApi.HTTP_SERVER_AUTHENTICATION_INFO();
|
||||||
|
|
||||||
authInfo.Flags = UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT;
|
authInfo.Flags = HttpApi.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT;
|
||||||
var authSchemes = (UnsafeNclNativeMethods.HttpApi.HTTP_AUTH_TYPES)_authSchemes;
|
var authSchemes = (HttpApi.HTTP_AUTH_TYPES)_authSchemes;
|
||||||
if (authSchemes != UnsafeNclNativeMethods.HttpApi.HTTP_AUTH_TYPES.NONE)
|
if (authSchemes != HttpApi.HTTP_AUTH_TYPES.NONE)
|
||||||
{
|
{
|
||||||
authInfo.AuthSchemes = authSchemes;
|
authInfo.AuthSchemes = authSchemes;
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
IntPtr infoptr = new IntPtr(&authInfo);
|
IntPtr infoptr = new IntPtr(&authInfo);
|
||||||
|
|
||||||
_server.UrlGroup.SetProperty(
|
_server.UrlGroup.SetProperty(
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_SERVER_PROPERTY.HttpServerAuthenticationProperty,
|
HttpApi.HTTP_SERVER_PROPERTY.HttpServerAuthenticationProperty,
|
||||||
infoptr, (uint)AuthInfoSize);
|
infoptr, (uint)AuthInfoSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -144,25 +144,25 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static unsafe bool CheckAuthenticated(UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_INFO* requestInfo)
|
internal static unsafe bool CheckAuthenticated(HttpApi.HTTP_REQUEST_INFO* requestInfo)
|
||||||
{
|
{
|
||||||
if (requestInfo != null
|
if (requestInfo != null
|
||||||
&& requestInfo->InfoType == UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_INFO_TYPE.HttpRequestInfoTypeAuth
|
&& requestInfo->InfoType == HttpApi.HTTP_REQUEST_INFO_TYPE.HttpRequestInfoTypeAuth
|
||||||
&& requestInfo->pInfo->AuthStatus == UnsafeNclNativeMethods.HttpApi.HTTP_AUTH_STATUS.HttpAuthStatusSuccess)
|
&& requestInfo->pInfo->AuthStatus == HttpApi.HTTP_AUTH_STATUS.HttpAuthStatusSuccess)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static unsafe ClaimsPrincipal GetUser(UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_INFO* requestInfo, int infoCount)
|
internal static unsafe ClaimsPrincipal GetUser(HttpApi.HTTP_REQUEST_INFO* requestInfo, int infoCount)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < infoCount; i++)
|
for (int i = 0; i < infoCount; i++)
|
||||||
{
|
{
|
||||||
var info = &requestInfo[i];
|
var info = &requestInfo[i];
|
||||||
if (requestInfo != null
|
if (requestInfo != null
|
||||||
&& info->InfoType == UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_INFO_TYPE.HttpRequestInfoTypeAuth
|
&& info->InfoType == HttpApi.HTTP_REQUEST_INFO_TYPE.HttpRequestInfoTypeAuth
|
||||||
&& info->pInfo->AuthStatus == UnsafeNclNativeMethods.HttpApi.HTTP_AUTH_STATUS.HttpAuthStatusSuccess)
|
&& info->pInfo->AuthStatus == HttpApi.HTTP_AUTH_STATUS.HttpAuthStatusSuccess)
|
||||||
{
|
{
|
||||||
return new WindowsPrincipal(new WindowsIdentity(info->pInfo->AccessToken,
|
return new WindowsPrincipal(new WindowsIdentity(info->pInfo->AccessToken,
|
||||||
GetAuthTypeFromRequest(info->pInfo->AuthType).ToString()));
|
GetAuthTypeFromRequest(info->pInfo->AuthType).ToString()));
|
||||||
|
|
@ -171,19 +171,19 @@ namespace Microsoft.Net.Http.Server
|
||||||
return new ClaimsPrincipal(new ClaimsIdentity()); // Anonymous / !IsAuthenticated
|
return new ClaimsPrincipal(new ClaimsIdentity()); // Anonymous / !IsAuthenticated
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AuthenticationSchemes GetAuthTypeFromRequest(UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE input)
|
private static AuthenticationSchemes GetAuthTypeFromRequest(HttpApi.HTTP_REQUEST_AUTH_TYPE input)
|
||||||
{
|
{
|
||||||
switch (input)
|
switch (input)
|
||||||
{
|
{
|
||||||
case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeBasic:
|
case HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeBasic:
|
||||||
return AuthenticationSchemes.Basic;
|
return AuthenticationSchemes.Basic;
|
||||||
// case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeDigest:
|
// case HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeDigest:
|
||||||
// return AuthenticationSchemes.Digest;
|
// return AuthenticationSchemes.Digest;
|
||||||
case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeNTLM:
|
case HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeNTLM:
|
||||||
return AuthenticationSchemes.NTLM;
|
return AuthenticationSchemes.NTLM;
|
||||||
case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeNegotiate:
|
case HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeNegotiate:
|
||||||
return AuthenticationSchemes.Negotiate;
|
return AuthenticationSchemes.Negotiate;
|
||||||
case UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeKerberos:
|
case HttpApi.HTTP_REQUEST_AUTH_TYPE.HttpRequestAuthTypeKerberos:
|
||||||
return AuthenticationSchemes.Kerberos;
|
return AuthenticationSchemes.Kerberos;
|
||||||
default:
|
default:
|
||||||
throw new NotImplementedException(input.ToString());
|
throw new NotImplementedException(input.ToString());
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
uint statusCode;
|
uint statusCode;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
statusCode = UnsafeNclNativeMethods.HttpApi.HttpWaitForDisconnectEx(requestQueueHandle: _requestQueue.Handle,
|
statusCode = HttpApi.HttpWaitForDisconnectEx(requestQueueHandle: _requestQueue.Handle,
|
||||||
connectionId: connectionId, reserved: 0, overlapped: nativeOverlapped);
|
connectionId: connectionId, reserved: 0, overlapped: nativeOverlapped);
|
||||||
}
|
}
|
||||||
catch (Win32Exception exception)
|
catch (Win32Exception exception)
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -35,7 +35,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
protected override bool ReleaseHandle()
|
protected override bool ReleaseHandle()
|
||||||
{
|
{
|
||||||
return (UnsafeNclNativeMethods.SafeNetHandles.HttpCloseRequestQueue(handle) ==
|
return (HttpApi.HttpCloseRequestQueue(handle) ==
|
||||||
UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS);
|
UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
if (Interlocked.Increment(ref disposed) == 1)
|
if (Interlocked.Increment(ref disposed) == 1)
|
||||||
{
|
{
|
||||||
// Closing server session also closes all open url groups under that server session.
|
// Closing server session also closes all open url groups under that server session.
|
||||||
return (UnsafeNclNativeMethods.HttpApi.HttpCloseServerSession(serverSessionId) ==
|
return (HttpApi.HttpCloseServerSession(serverSessionId) ==
|
||||||
UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS);
|
UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
internal class RequestQueue
|
internal class RequestQueue
|
||||||
{
|
{
|
||||||
private static readonly int BindingInfoSize =
|
private static readonly int BindingInfoSize =
|
||||||
Marshal.SizeOf<UnsafeNclNativeMethods.HttpApi.HTTP_BINDING_INFO>();
|
Marshal.SizeOf<HttpApi.HTTP_BINDING_INFO>();
|
||||||
|
|
||||||
private readonly UrlGroup _urlGroup;
|
private readonly UrlGroup _urlGroup;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
@ -39,8 +39,8 @@ namespace Microsoft.Net.Http.Server
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
HttpRequestQueueV2Handle requestQueueHandle = null;
|
HttpRequestQueueV2Handle requestQueueHandle = null;
|
||||||
var statusCode = UnsafeNclNativeMethods.SafeNetHandles.HttpCreateRequestQueue(
|
var statusCode = HttpApi.HttpCreateRequestQueue(
|
||||||
UnsafeNclNativeMethods.HttpApi.Version, null, null, 0, out requestQueueHandle);
|
HttpApi.Version, null, null, 0, out requestQueueHandle);
|
||||||
|
|
||||||
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
@ -69,13 +69,13 @@ namespace Microsoft.Net.Http.Server
|
||||||
// Set the association between request queue and url group. After this, requests for registered urls will
|
// Set the association between request queue and url group. After this, requests for registered urls will
|
||||||
// get delivered to this request queue.
|
// get delivered to this request queue.
|
||||||
|
|
||||||
var info = new UnsafeNclNativeMethods.HttpApi.HTTP_BINDING_INFO();
|
var info = new HttpApi.HTTP_BINDING_INFO();
|
||||||
info.Flags = UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT;
|
info.Flags = HttpApi.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT;
|
||||||
info.RequestQueueHandle = Handle.DangerousGetHandle();
|
info.RequestQueueHandle = Handle.DangerousGetHandle();
|
||||||
|
|
||||||
var infoptr = new IntPtr(&info);
|
var infoptr = new IntPtr(&info);
|
||||||
|
|
||||||
_urlGroup.SetProperty(UnsafeNclNativeMethods.HttpApi.HTTP_SERVER_PROPERTY.HttpServerBindingProperty,
|
_urlGroup.SetProperty(HttpApi.HTTP_SERVER_PROPERTY.HttpServerBindingProperty,
|
||||||
infoptr, (uint)BindingInfoSize);
|
infoptr, (uint)BindingInfoSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,21 +87,21 @@ namespace Microsoft.Net.Http.Server
|
||||||
// is fine since http.sys allows to set HttpServerBindingProperty multiple times for valid
|
// is fine since http.sys allows to set HttpServerBindingProperty multiple times for valid
|
||||||
// Url groups.
|
// Url groups.
|
||||||
|
|
||||||
var info = new UnsafeNclNativeMethods.HttpApi.HTTP_BINDING_INFO();
|
var info = new HttpApi.HTTP_BINDING_INFO();
|
||||||
info.Flags = UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.NONE;
|
info.Flags = HttpApi.HTTP_FLAGS.NONE;
|
||||||
info.RequestQueueHandle = IntPtr.Zero;
|
info.RequestQueueHandle = IntPtr.Zero;
|
||||||
|
|
||||||
var infoptr = new IntPtr(&info);
|
var infoptr = new IntPtr(&info);
|
||||||
|
|
||||||
_urlGroup.SetProperty(UnsafeNclNativeMethods.HttpApi.HTTP_SERVER_PROPERTY.HttpServerBindingProperty,
|
_urlGroup.SetProperty(HttpApi.HTTP_SERVER_PROPERTY.HttpServerBindingProperty,
|
||||||
infoptr, (uint)BindingInfoSize, throwOnError: false);
|
infoptr, (uint)BindingInfoSize, throwOnError: false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The listener must be active for this to work.
|
// The listener must be active for this to work.
|
||||||
internal unsafe void SetLengthLimit(long length)
|
internal unsafe void SetLengthLimit(long length)
|
||||||
{
|
{
|
||||||
var result = UnsafeNclNativeMethods.HttpApi.HttpSetRequestQueueProperty(Handle,
|
var result = HttpApi.HttpSetRequestQueueProperty(Handle,
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_SERVER_PROPERTY.HttpServerQueueLengthProperty,
|
HttpApi.HTTP_SERVER_PROPERTY.HttpServerQueueLengthProperty,
|
||||||
new IntPtr((void*)&length), (uint)Marshal.SizeOf<long>(), 0, IntPtr.Zero);
|
new IntPtr((void*)&length), (uint)Marshal.SizeOf<long>(), 0, IntPtr.Zero);
|
||||||
|
|
||||||
if (result != 0)
|
if (result != 0)
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ namespace Microsoft.Net.Http.Server
|
||||||
internal unsafe ServerSession()
|
internal unsafe ServerSession()
|
||||||
{
|
{
|
||||||
ulong serverSessionId = 0;
|
ulong serverSessionId = 0;
|
||||||
var statusCode = UnsafeNclNativeMethods.HttpApi.HttpCreateServerSession(
|
var statusCode = HttpApi.HttpCreateServerSession(
|
||||||
UnsafeNclNativeMethods.HttpApi.Version, &serverSessionId, 0);
|
HttpApi.Version, &serverSessionId, 0);
|
||||||
|
|
||||||
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using static Microsoft.Net.Http.Server.UnsafeNclNativeMethods.HttpApi;
|
using static Microsoft.Net.Http.Server.HttpApi;
|
||||||
using static Microsoft.Net.Http.Server.UnsafeNclNativeMethods.TokenBinding;
|
using static Microsoft.Net.Http.Server.UnsafeNclNativeMethods.TokenBinding;
|
||||||
|
|
||||||
namespace Microsoft.Net.Http.Server
|
namespace Microsoft.Net.Http.Server
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -33,7 +33,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
ulong urlGroupId = 0;
|
ulong urlGroupId = 0;
|
||||||
var statusCode = UnsafeNclNativeMethods.HttpApi.HttpCreateUrlGroup(
|
var statusCode = HttpApi.HttpCreateUrlGroup(
|
||||||
_serverSession.Id.DangerousGetServerSessionId(), &urlGroupId, 0);
|
_serverSession.Id.DangerousGetServerSessionId(), &urlGroupId, 0);
|
||||||
|
|
||||||
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
||||||
|
|
@ -47,11 +47,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
internal ulong Id { get; private set; }
|
internal ulong Id { get; private set; }
|
||||||
|
|
||||||
internal void SetProperty(UnsafeNclNativeMethods.HttpApi.HTTP_SERVER_PROPERTY property, IntPtr info, uint infosize, bool throwOnError = true)
|
internal void SetProperty(HttpApi.HTTP_SERVER_PROPERTY property, IntPtr info, uint infosize, bool throwOnError = true)
|
||||||
{
|
{
|
||||||
Debug.Assert(info != IntPtr.Zero, "SetUrlGroupProperty called with invalid pointer");
|
Debug.Assert(info != IntPtr.Zero, "SetUrlGroupProperty called with invalid pointer");
|
||||||
|
|
||||||
var statusCode = UnsafeNclNativeMethods.HttpApi.HttpSetUrlGroupProperty(Id, property, info, infosize);
|
var statusCode = HttpApi.HttpSetUrlGroupProperty(Id, property, info, infosize);
|
||||||
|
|
||||||
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
@ -68,7 +68,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
LogHelper.LogInfo(_logger, "Listening on prefix: " + uriPrefix);
|
LogHelper.LogInfo(_logger, "Listening on prefix: " + uriPrefix);
|
||||||
|
|
||||||
var statusCode = UnsafeNclNativeMethods.HttpApi.HttpAddUrlToUrlGroup(Id, uriPrefix, (ulong)contextId, 0);
|
var statusCode = HttpApi.HttpAddUrlToUrlGroup(Id, uriPrefix, (ulong)contextId, 0);
|
||||||
|
|
||||||
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
@ -87,7 +87,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
LogHelper.LogInfo(_logger, "Stop listening on prefix: " + uriPrefix);
|
LogHelper.LogInfo(_logger, "Stop listening on prefix: " + uriPrefix);
|
||||||
|
|
||||||
var statusCode = UnsafeNclNativeMethods.HttpApi.HttpRemoveUrlFromUrlGroup(Id, uriPrefix, 0);
|
var statusCode = HttpApi.HttpRemoveUrlFromUrlGroup(Id, uriPrefix, 0);
|
||||||
|
|
||||||
if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_NOT_FOUND)
|
if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_NOT_FOUND)
|
||||||
{
|
{
|
||||||
|
|
@ -107,7 +107,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
Debug.Assert(Id != 0, "HttpCloseUrlGroup called with invalid url group id");
|
Debug.Assert(Id != 0, "HttpCloseUrlGroup called with invalid url group id");
|
||||||
|
|
||||||
uint statusCode = UnsafeNclNativeMethods.HttpApi.HttpCloseUrlGroup(Id);
|
uint statusCode = HttpApi.HttpCloseUrlGroup(Id);
|
||||||
|
|
||||||
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -43,11 +43,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
private const uint CertBoblSize = 1500;
|
private const uint CertBoblSize = 1500;
|
||||||
private static readonly IOCompletionCallback IOCallback = new IOCompletionCallback(WaitCallback);
|
private static readonly IOCompletionCallback IOCallback = new IOCompletionCallback(WaitCallback);
|
||||||
private static readonly int RequestChannelBindStatusSize =
|
private static readonly int RequestChannelBindStatusSize =
|
||||||
Marshal.SizeOf<UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_CHANNEL_BIND_STATUS>();
|
Marshal.SizeOf<HttpApi.HTTP_REQUEST_CHANNEL_BIND_STATUS>();
|
||||||
|
|
||||||
private SafeNativeOverlapped _overlapped;
|
private SafeNativeOverlapped _overlapped;
|
||||||
private byte[] _backingBuffer;
|
private byte[] _backingBuffer;
|
||||||
private UnsafeNclNativeMethods.HttpApi.HTTP_SSL_CLIENT_CERT_INFO* _memoryBlob;
|
private HttpApi.HTTP_SSL_CLIENT_CERT_INFO* _memoryBlob;
|
||||||
private uint _size;
|
private uint _size;
|
||||||
private TaskCompletionSource<object> _tcs;
|
private TaskCompletionSource<object> _tcs;
|
||||||
private RequestContext _requestContext;
|
private RequestContext _requestContext;
|
||||||
|
|
@ -124,7 +124,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private UnsafeNclNativeMethods.HttpApi.HTTP_SSL_CLIENT_CERT_INFO* RequestBlob
|
private HttpApi.HTTP_SSL_CLIENT_CERT_INFO* RequestBlob
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
@ -154,7 +154,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
var boundHandle = RequestContext.Server.RequestQueue.BoundHandle;
|
var boundHandle = RequestContext.Server.RequestQueue.BoundHandle;
|
||||||
_overlapped = new SafeNativeOverlapped(boundHandle,
|
_overlapped = new SafeNativeOverlapped(boundHandle,
|
||||||
boundHandle.AllocateNativeOverlapped(IOCallback, this, _backingBuffer));
|
boundHandle.AllocateNativeOverlapped(IOCallback, this, _backingBuffer));
|
||||||
_memoryBlob = (UnsafeNclNativeMethods.HttpApi.HTTP_SSL_CLIENT_CERT_INFO*)Marshal.UnsafeAddrOfPinnedArrayElement(_backingBuffer, 0);
|
_memoryBlob = (HttpApi.HTTP_SSL_CLIENT_CERT_INFO*)Marshal.UnsafeAddrOfPinnedArrayElement(_backingBuffer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When you use netsh to configure HTTP.SYS with clientcertnegotiation = enable
|
// When you use netsh to configure HTTP.SYS with clientcertnegotiation = enable
|
||||||
|
|
@ -185,10 +185,10 @@ namespace Microsoft.Net.Http.Server
|
||||||
uint bytesReceived = 0;
|
uint bytesReceived = 0;
|
||||||
|
|
||||||
uint statusCode =
|
uint statusCode =
|
||||||
UnsafeNclNativeMethods.HttpApi.HttpReceiveClientCertificate(
|
HttpApi.HttpReceiveClientCertificate(
|
||||||
RequestQueueHandle,
|
RequestQueueHandle,
|
||||||
RequestContext.Request.UConnectionId,
|
RequestContext.Request.UConnectionId,
|
||||||
(uint)UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.NONE,
|
(uint)HttpApi.HTTP_FLAGS.NONE,
|
||||||
RequestBlob,
|
RequestBlob,
|
||||||
size,
|
size,
|
||||||
&bytesReceived,
|
&bytesReceived,
|
||||||
|
|
@ -196,7 +196,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_MORE_DATA)
|
if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_MORE_DATA)
|
||||||
{
|
{
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_SSL_CLIENT_CERT_INFO* pClientCertInfo = RequestBlob;
|
HttpApi.HTTP_SSL_CLIENT_CERT_INFO* pClientCertInfo = RequestBlob;
|
||||||
size = bytesReceived + pClientCertInfo->CertEncodedSize;
|
size = bytesReceived + pClientCertInfo->CertEncodedSize;
|
||||||
Reset(size);
|
Reset(size);
|
||||||
retry = true;
|
retry = true;
|
||||||
|
|
@ -259,15 +259,15 @@ namespace Microsoft.Net.Http.Server
|
||||||
// return the size of the initial cert structure. To get the full size,
|
// return the size of the initial cert structure. To get the full size,
|
||||||
// we need to add the certificate encoding size as well.
|
// we need to add the certificate encoding size as well.
|
||||||
|
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_SSL_CLIENT_CERT_INFO* pClientCertInfo = asyncResult.RequestBlob;
|
HttpApi.HTTP_SSL_CLIENT_CERT_INFO* pClientCertInfo = asyncResult.RequestBlob;
|
||||||
asyncResult.Reset(numBytes + pClientCertInfo->CertEncodedSize);
|
asyncResult.Reset(numBytes + pClientCertInfo->CertEncodedSize);
|
||||||
|
|
||||||
uint bytesReceived = 0;
|
uint bytesReceived = 0;
|
||||||
errorCode =
|
errorCode =
|
||||||
UnsafeNclNativeMethods.HttpApi.HttpReceiveClientCertificate(
|
HttpApi.HttpReceiveClientCertificate(
|
||||||
requestContext.Server.RequestQueue.Handle,
|
requestContext.Server.RequestQueue.Handle,
|
||||||
requestContext.Request.UConnectionId,
|
requestContext.Request.UConnectionId,
|
||||||
(uint)UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.NONE,
|
(uint)HttpApi.HTTP_FLAGS.NONE,
|
||||||
asyncResult._memoryBlob,
|
asyncResult._memoryBlob,
|
||||||
asyncResult._size,
|
asyncResult._size,
|
||||||
&bytesReceived,
|
&bytesReceived,
|
||||||
|
|
@ -291,7 +291,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_SSL_CLIENT_CERT_INFO* pClientCertInfo = asyncResult._memoryBlob;
|
HttpApi.HTTP_SSL_CLIENT_CERT_INFO* pClientCertInfo = asyncResult._memoryBlob;
|
||||||
if (pClientCertInfo == null)
|
if (pClientCertInfo == null)
|
||||||
{
|
{
|
||||||
asyncResult.Complete(0, null);
|
asyncResult.Complete(0, null);
|
||||||
|
|
@ -391,10 +391,10 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
// Http.sys team: ServiceName will always be null if
|
// Http.sys team: ServiceName will always be null if
|
||||||
// HTTP_RECEIVE_SECURE_CHANNEL_TOKEN flag is set.
|
// HTTP_RECEIVE_SECURE_CHANNEL_TOKEN flag is set.
|
||||||
statusCode = UnsafeNclNativeMethods.HttpApi.HttpReceiveClientCertificate(
|
statusCode = HttpApi.HttpReceiveClientCertificate(
|
||||||
requestQueue.Handle,
|
requestQueue.Handle,
|
||||||
connectionId,
|
connectionId,
|
||||||
(uint)UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.HTTP_RECEIVE_SECURE_CHANNEL_TOKEN,
|
(uint)HttpApi.HTTP_FLAGS.HTTP_RECEIVE_SECURE_CHANNEL_TOKEN,
|
||||||
blobPtr,
|
blobPtr,
|
||||||
(uint)size,
|
(uint)size,
|
||||||
&bytesReceived,
|
&bytesReceived,
|
||||||
|
|
@ -438,7 +438,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
private static int GetTokenOffsetFromBlob(IntPtr blob)
|
private static int GetTokenOffsetFromBlob(IntPtr blob)
|
||||||
{
|
{
|
||||||
Debug.Assert(blob != IntPtr.Zero);
|
Debug.Assert(blob != IntPtr.Zero);
|
||||||
IntPtr tokenPointer = Marshal.ReadIntPtr(blob, (int)Marshal.OffsetOf<UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_CHANNEL_BIND_STATUS>("ChannelToken"));
|
IntPtr tokenPointer = Marshal.ReadIntPtr(blob, (int)Marshal.OffsetOf<HttpApi.HTTP_REQUEST_CHANNEL_BIND_STATUS>("ChannelToken"));
|
||||||
Debug.Assert(tokenPointer != IntPtr.Zero);
|
Debug.Assert(tokenPointer != IntPtr.Zero);
|
||||||
return (int)IntPtrHelper.Subtract(tokenPointer, blob);
|
return (int)IntPtrHelper.Subtract(tokenPointer, blob);
|
||||||
}
|
}
|
||||||
|
|
@ -446,7 +446,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
private static int GetTokenSizeFromBlob(IntPtr blob)
|
private static int GetTokenSizeFromBlob(IntPtr blob)
|
||||||
{
|
{
|
||||||
Debug.Assert(blob != IntPtr.Zero);
|
Debug.Assert(blob != IntPtr.Zero);
|
||||||
return Marshal.ReadInt32(blob, (int)Marshal.OffsetOf<UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_CHANNEL_BIND_STATUS>("ChannelTokenSize"));
|
return Marshal.ReadInt32(blob, (int)Marshal.OffsetOf<HttpApi.HTTP_REQUEST_CHANNEL_BIND_STATUS>("ChannelTokenSize"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
private const int DefaultBufferSize = 4096;
|
private const int DefaultBufferSize = 4096;
|
||||||
private const int AlignmentPadding = 8;
|
private const int AlignmentPadding = 8;
|
||||||
private UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST* _memoryBlob;
|
private HttpApi.HTTP_REQUEST* _memoryBlob;
|
||||||
private IntPtr _originalBlobAddress;
|
private IntPtr _originalBlobAddress;
|
||||||
private byte[] _backingBuffer;
|
private byte[] _backingBuffer;
|
||||||
private int _bufferAlignment;
|
private int _bufferAlignment;
|
||||||
|
|
@ -42,7 +42,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
internal NativeRequestContext(AsyncAcceptContext result)
|
internal NativeRequestContext(AsyncAcceptContext result)
|
||||||
{
|
{
|
||||||
_acceptResult = result;
|
_acceptResult = result;
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST* requestBlob = Allocate(0);
|
HttpApi.HTTP_REQUEST* requestBlob = Allocate(0);
|
||||||
if (requestBlob == null)
|
if (requestBlob == null)
|
||||||
{
|
{
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
|
|
@ -61,7 +61,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST* RequestBlob
|
internal HttpApi.HTTP_REQUEST* RequestBlob
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
@ -98,7 +98,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST* blob = _memoryBlob;
|
HttpApi.HTTP_REQUEST* blob = _memoryBlob;
|
||||||
return blob == null ? _originalBlobAddress : (IntPtr)blob;
|
return blob == null ? _originalBlobAddress : (IntPtr)blob;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +138,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetBlob(UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST* requestBlob)
|
private void SetBlob(HttpApi.HTTP_REQUEST* requestBlob)
|
||||||
{
|
{
|
||||||
Debug.Assert(_memoryBlob != null || _backingBuffer == null, "RequestContextBase::Dispose()|SetBlob() called after ReleasePins().");
|
Debug.Assert(_memoryBlob != null || _backingBuffer == null, "RequestContextBase::Dispose()|SetBlob() called after ReleasePins().");
|
||||||
if (requestBlob == null)
|
if (requestBlob == null)
|
||||||
|
|
@ -170,7 +170,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
_backingBuffer = new byte[size + AlignmentPadding];
|
_backingBuffer = new byte[size + AlignmentPadding];
|
||||||
}
|
}
|
||||||
|
|
||||||
private UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST* Allocate(uint size)
|
private HttpApi.HTTP_REQUEST* Allocate(uint size)
|
||||||
{
|
{
|
||||||
// We can't reuse overlapped objects
|
// We can't reuse overlapped objects
|
||||||
if (_nativeOverlapped != null)
|
if (_nativeOverlapped != null)
|
||||||
|
|
@ -191,7 +191,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
var requestAddress = Marshal.UnsafeAddrOfPinnedArrayElement(RequestBuffer, 0);
|
var requestAddress = Marshal.UnsafeAddrOfPinnedArrayElement(RequestBuffer, 0);
|
||||||
_bufferAlignment = (int)(requestAddress.ToInt64() & 0x07);
|
_bufferAlignment = (int)(requestAddress.ToInt64() & 0x07);
|
||||||
|
|
||||||
return (UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST*)(requestAddress + _bufferAlignment);
|
return (HttpApi.HTTP_REQUEST*)(requestAddress + _bufferAlignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Reset(ulong requestId, uint size)
|
internal void Reset(ulong requestId, uint size)
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
RawUrl = Marshal.PtrToStringAnsi((IntPtr)memoryBlob.RequestBlob->pRawUrl, memoryBlob.RequestBlob->RawUrlLength);
|
RawUrl = Marshal.PtrToStringAnsi((IntPtr)memoryBlob.RequestBlob->pRawUrl, memoryBlob.RequestBlob->RawUrlLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_COOKED_URL cookedUrl = memoryBlob.RequestBlob->CookedUrl;
|
HttpApi.HTTP_COOKED_URL cookedUrl = memoryBlob.RequestBlob->CookedUrl;
|
||||||
if (cookedUrl.pHost != null && cookedUrl.HostLength > 0)
|
if (cookedUrl.pHost != null && cookedUrl.HostLength > 0)
|
||||||
{
|
{
|
||||||
// TODO: Unused
|
// TODO: Unused
|
||||||
|
|
@ -119,10 +119,10 @@ namespace Microsoft.Net.Http.Server
|
||||||
}
|
}
|
||||||
|
|
||||||
KnownMethod = memoryBlob.RequestBlob->Verb;
|
KnownMethod = memoryBlob.RequestBlob->Verb;
|
||||||
Method = UnsafeNclNativeMethods.HttpApi.GetVerb(memoryBlob.RequestBlob);
|
Method = HttpApi.GetVerb(memoryBlob.RequestBlob);
|
||||||
Headers = new HeaderCollection(new RequestHeaders(_nativeRequestContext));
|
Headers = new HeaderCollection(new RequestHeaders(_nativeRequestContext));
|
||||||
|
|
||||||
var requestV2 = (UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_V2*)memoryBlob.RequestBlob;
|
var requestV2 = (HttpApi.HTTP_REQUEST_V2*)memoryBlob.RequestBlob;
|
||||||
User = AuthenticationManager.GetUser(requestV2->pRequestInfo, requestV2->RequestInfoCount);
|
User = AuthenticationManager.GetUser(requestV2->pRequestInfo, requestV2->RequestInfoCount);
|
||||||
|
|
||||||
GetTlsTokenBindingInfo();
|
GetTlsTokenBindingInfo();
|
||||||
|
|
@ -207,9 +207,9 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
public HeaderCollection Headers { get; }
|
public HeaderCollection Headers { get; }
|
||||||
|
|
||||||
internal UnsafeNclNativeMethods.HttpApi.HTTP_VERB KnownMethod { get; }
|
internal HttpApi.HTTP_VERB KnownMethod { get; }
|
||||||
|
|
||||||
public bool IsHeadMethod => KnownMethod == UnsafeNclNativeMethods.HttpApi.HTTP_VERB.HttpVerbHEAD;
|
public bool IsHeadMethod => KnownMethod == HttpApi.HTTP_VERB.HttpVerbHEAD;
|
||||||
|
|
||||||
public string Method { get; }
|
public string Method { get; }
|
||||||
|
|
||||||
|
|
@ -251,7 +251,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
if (_remoteEndPoint == null)
|
if (_remoteEndPoint == null)
|
||||||
{
|
{
|
||||||
_remoteEndPoint = UnsafeNclNativeMethods.HttpApi.GetRemoteEndPoint(RequestBuffer, BufferAlignment, OriginalBlobAddress);
|
_remoteEndPoint = HttpApi.GetRemoteEndPoint(RequestBuffer, BufferAlignment, OriginalBlobAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _remoteEndPoint;
|
return _remoteEndPoint;
|
||||||
|
|
@ -264,7 +264,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
if (_localEndPoint == null)
|
if (_localEndPoint == null)
|
||||||
{
|
{
|
||||||
_localEndPoint = UnsafeNclNativeMethods.HttpApi.GetLocalEndPoint(RequestBuffer, BufferAlignment, OriginalBlobAddress);
|
_localEndPoint = HttpApi.GetLocalEndPoint(RequestBuffer, BufferAlignment, OriginalBlobAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _localEndPoint;
|
return _localEndPoint;
|
||||||
|
|
@ -349,13 +349,13 @@ namespace Microsoft.Net.Http.Server
|
||||||
// Value: "iexplore.exe"=dword:00000001
|
// Value: "iexplore.exe"=dword:00000001
|
||||||
private unsafe void GetTlsTokenBindingInfo()
|
private unsafe void GetTlsTokenBindingInfo()
|
||||||
{
|
{
|
||||||
var nativeRequest = (UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_V2*)_nativeRequestContext.RequestBlob;
|
var nativeRequest = (HttpApi.HTTP_REQUEST_V2*)_nativeRequestContext.RequestBlob;
|
||||||
for (int i = 0; i < nativeRequest->RequestInfoCount; i++)
|
for (int i = 0; i < nativeRequest->RequestInfoCount; i++)
|
||||||
{
|
{
|
||||||
var pThisInfo = &nativeRequest->pRequestInfo[i];
|
var pThisInfo = &nativeRequest->pRequestInfo[i];
|
||||||
if (pThisInfo->InfoType == UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_INFO_TYPE.HttpRequestInfoTypeSslTokenBinding)
|
if (pThisInfo->InfoType == HttpApi.HTTP_REQUEST_INFO_TYPE.HttpRequestInfoTypeSslTokenBinding)
|
||||||
{
|
{
|
||||||
var pTokenBindingInfo = (UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_TOKEN_BINDING_INFO*)pThisInfo->pInfo;
|
var pTokenBindingInfo = (HttpApi.HTTP_REQUEST_TOKEN_BINDING_INFO*)pThisInfo->pInfo;
|
||||||
_providedTokenBindingId = TokenBindingUtil.GetProvidedTokenIdFromBindingInfo(pTokenBindingInfo, out _referredTokenBindingId);
|
_providedTokenBindingId = TokenBindingUtil.GetProvidedTokenIdFromBindingInfo(pTokenBindingInfo, out _referredTokenBindingId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Request.KnownMethod != UnsafeNclNativeMethods.HttpApi.HTTP_VERB.HttpVerbGET)
|
if (Request.KnownMethod != HttpApi.HTTP_VERB.HttpVerbGET)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +186,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
throw new InvalidOperationException("This request is not a valid upgrade request.");
|
throw new InvalidOperationException("This request is not a valid upgrade request.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Request.KnownMethod != UnsafeNclNativeMethods.HttpApi.HTTP_VERB.HttpVerbGET)
|
if (Request.KnownMethod != HttpApi.HTTP_VERB.HttpVerbGET)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("This request is not a valid upgrade request; invalid verb: " + Request.Method);
|
throw new InvalidOperationException("This request is not a valid upgrade request; invalid verb: " + Request.Method);
|
||||||
}
|
}
|
||||||
|
|
@ -352,7 +352,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var statusCode = UnsafeNclNativeMethods.HttpApi.HttpCancelHttpRequest(Server.RequestQueue.Handle,
|
var statusCode = HttpApi.HttpCancelHttpRequest(Server.RequestQueue.Handle,
|
||||||
Request.RequestId, IntPtr.Zero);
|
Request.RequestId, IntPtr.Zero);
|
||||||
|
|
||||||
// Either the connection has already dropped, or the last write is in progress.
|
// Either the connection has already dropped, or the last write is in progress.
|
||||||
|
|
|
||||||
|
|
@ -85,13 +85,13 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
private string GetKnownHeader(HttpSysRequestHeader header)
|
private string GetKnownHeader(HttpSysRequestHeader header)
|
||||||
{
|
{
|
||||||
return UnsafeNclNativeMethods.HttpApi.GetKnownHeader(_requestMemoryBlob.RequestBuffer,
|
return HttpApi.GetKnownHeader(_requestMemoryBlob.RequestBuffer,
|
||||||
_requestMemoryBlob.BufferAlignment, _requestMemoryBlob.OriginalBlobAddress, (int)header);
|
_requestMemoryBlob.BufferAlignment, _requestMemoryBlob.OriginalBlobAddress, (int)header);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GetUnknownHeaders(IDictionary<string, StringValues> extra)
|
private void GetUnknownHeaders(IDictionary<string, StringValues> extra)
|
||||||
{
|
{
|
||||||
UnsafeNclNativeMethods.HttpApi.GetUnknownHeaders(extra, _requestMemoryBlob.RequestBuffer,
|
HttpApi.GetUnknownHeaders(extra, _requestMemoryBlob.RequestBuffer,
|
||||||
_requestMemoryBlob.BufferAlignment, _requestMemoryBlob.OriginalBlobAddress);
|
_requestMemoryBlob.BufferAlignment, _requestMemoryBlob.OriginalBlobAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
if (_dataChunkIndex != -1)
|
if (_dataChunkIndex != -1)
|
||||||
{
|
{
|
||||||
dataRead = UnsafeNclNativeMethods.HttpApi.GetChunks(_requestContext.Request.RequestBuffer,
|
dataRead = HttpApi.GetChunks(_requestContext.Request.RequestBuffer,
|
||||||
_requestContext.Request.BufferAlignment, _requestContext.Request.OriginalBlobAddress,
|
_requestContext.Request.BufferAlignment, _requestContext.Request.OriginalBlobAddress,
|
||||||
ref _dataChunkIndex, ref _dataChunkOffset, buffer, offset, size);
|
ref _dataChunkIndex, ref _dataChunkOffset, buffer, offset, size);
|
||||||
}
|
}
|
||||||
|
|
@ -179,7 +179,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
uint flags = 0;
|
uint flags = 0;
|
||||||
|
|
||||||
statusCode =
|
statusCode =
|
||||||
UnsafeNclNativeMethods.HttpApi.HttpReceiveRequestEntityBody(
|
HttpApi.HttpReceiveRequestEntityBody(
|
||||||
RequestQueueHandle,
|
RequestQueueHandle,
|
||||||
RequestId,
|
RequestId,
|
||||||
flags,
|
flags,
|
||||||
|
|
@ -232,7 +232,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
uint dataRead = 0;
|
uint dataRead = 0;
|
||||||
if (_dataChunkIndex != -1)
|
if (_dataChunkIndex != -1)
|
||||||
{
|
{
|
||||||
dataRead = UnsafeNclNativeMethods.HttpApi.GetChunks(_requestContext.Request.RequestBuffer, _requestContext.Request.BufferAlignment,
|
dataRead = HttpApi.GetChunks(_requestContext.Request.RequestBuffer, _requestContext.Request.BufferAlignment,
|
||||||
_requestContext.Request.OriginalBlobAddress, ref _dataChunkIndex, ref _dataChunkOffset, buffer, offset, size);
|
_requestContext.Request.OriginalBlobAddress, ref _dataChunkIndex, ref _dataChunkOffset, buffer, offset, size);
|
||||||
|
|
||||||
if (_dataChunkIndex != -1 && dataRead == size)
|
if (_dataChunkIndex != -1 && dataRead == size)
|
||||||
|
|
@ -262,7 +262,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
uint flags = 0;
|
uint flags = 0;
|
||||||
|
|
||||||
statusCode =
|
statusCode =
|
||||||
UnsafeNclNativeMethods.HttpApi.HttpReceiveRequestEntityBody(
|
HttpApi.HttpReceiveRequestEntityBody(
|
||||||
RequestQueueHandle,
|
RequestQueueHandle,
|
||||||
RequestId,
|
RequestId,
|
||||||
flags,
|
flags,
|
||||||
|
|
@ -350,7 +350,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
uint dataRead = 0;
|
uint dataRead = 0;
|
||||||
if (_dataChunkIndex != -1)
|
if (_dataChunkIndex != -1)
|
||||||
{
|
{
|
||||||
dataRead = UnsafeNclNativeMethods.HttpApi.GetChunks(_requestContext.Request.RequestBuffer, _requestContext.Request.BufferAlignment,
|
dataRead = HttpApi.GetChunks(_requestContext.Request.RequestBuffer, _requestContext.Request.BufferAlignment,
|
||||||
_requestContext.Request.OriginalBlobAddress, ref _dataChunkIndex, ref _dataChunkOffset, buffer, offset, size);
|
_requestContext.Request.OriginalBlobAddress, ref _dataChunkIndex, ref _dataChunkOffset, buffer, offset, size);
|
||||||
if (_dataChunkIndex != -1 && dataRead == size)
|
if (_dataChunkIndex != -1 && dataRead == size)
|
||||||
{
|
{
|
||||||
|
|
@ -386,7 +386,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
uint flags = 0;
|
uint flags = 0;
|
||||||
|
|
||||||
statusCode =
|
statusCode =
|
||||||
UnsafeNclNativeMethods.HttpApi.HttpReceiveRequestEntityBody(
|
HttpApi.HttpReceiveRequestEntityBody(
|
||||||
RequestQueueHandle,
|
RequestQueueHandle,
|
||||||
RequestId,
|
RequestId,
|
||||||
flags,
|
flags,
|
||||||
|
|
|
||||||
|
|
@ -406,9 +406,9 @@ namespace Microsoft.Net.Http.Server
|
||||||
_requestContext.Abort();
|
_requestContext.Abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
private UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS ComputeLeftToWrite(bool endOfRequest = false)
|
private HttpApi.HTTP_FLAGS ComputeLeftToWrite(bool endOfRequest = false)
|
||||||
{
|
{
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS flags = UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.NONE;
|
HttpApi.HTTP_FLAGS flags = HttpApi.HTTP_FLAGS.NONE;
|
||||||
if (!_requestContext.Response.ComputedHeaders)
|
if (!_requestContext.Response.ComputedHeaders)
|
||||||
{
|
{
|
||||||
flags = _requestContext.Response.ComputeHeaders(endOfRequest, _buffer.TotalBytes);
|
flags = _requestContext.Response.ComputeHeaders(endOfRequest, _buffer.TotalBytes);
|
||||||
|
|
@ -565,7 +565,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
internal unsafe Task SendFileAsyncCore(string fileName, long offset, long? count, CancellationToken cancellationToken)
|
internal unsafe Task SendFileAsyncCore(string fileName, long offset, long? count, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
_requestContext.Response.Start();
|
_requestContext.Response.Start();
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS flags = ComputeLeftToWrite();
|
HttpApi.HTTP_FLAGS flags = ComputeLeftToWrite();
|
||||||
if (count == 0 && _leftToWrite != 0)
|
if (count == 0 && _leftToWrite != 0)
|
||||||
{
|
{
|
||||||
return Helpers.CompletedTask();
|
return Helpers.CompletedTask();
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
public sealed class TimeoutManager
|
public sealed class TimeoutManager
|
||||||
{
|
{
|
||||||
private static readonly int TimeoutLimitSize =
|
private static readonly int TimeoutLimitSize =
|
||||||
Marshal.SizeOf<UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_LIMIT_INFO>();
|
Marshal.SizeOf<HttpApi.HTTP_TIMEOUT_LIMIT_INFO>();
|
||||||
|
|
||||||
private WebListener _server;
|
private WebListener _server;
|
||||||
private int[] _timeouts;
|
private int[] _timeouts;
|
||||||
|
|
@ -69,11 +69,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return GetTimeSpanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.EntityBody);
|
return GetTimeSpanTimeout(HttpApi.HTTP_TIMEOUT_TYPE.EntityBody);
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
SetTimeSpanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.EntityBody, value);
|
SetTimeSpanTimeout(HttpApi.HTTP_TIMEOUT_TYPE.EntityBody, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,11 +92,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return GetTimeSpanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.DrainEntityBody);
|
return GetTimeSpanTimeout(HttpApi.HTTP_TIMEOUT_TYPE.DrainEntityBody);
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
SetTimeSpanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.DrainEntityBody, value);
|
SetTimeSpanTimeout(HttpApi.HTTP_TIMEOUT_TYPE.DrainEntityBody, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,11 +110,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return GetTimeSpanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.RequestQueue);
|
return GetTimeSpanTimeout(HttpApi.HTTP_TIMEOUT_TYPE.RequestQueue);
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
SetTimeSpanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.RequestQueue, value);
|
SetTimeSpanTimeout(HttpApi.HTTP_TIMEOUT_TYPE.RequestQueue, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,11 +129,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return GetTimeSpanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.IdleConnection);
|
return GetTimeSpanTimeout(HttpApi.HTTP_TIMEOUT_TYPE.IdleConnection);
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
SetTimeSpanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.IdleConnection, value);
|
SetTimeSpanTimeout(HttpApi.HTTP_TIMEOUT_TYPE.IdleConnection, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -149,11 +149,11 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return GetTimeSpanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.HeaderWait);
|
return GetTimeSpanTimeout(HttpApi.HTTP_TIMEOUT_TYPE.HeaderWait);
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
SetTimeSpanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.HeaderWait, value);
|
SetTimeSpanTimeout(HttpApi.HTTP_TIMEOUT_TYPE.HeaderWait, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -189,13 +189,13 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
#region Helpers
|
#region Helpers
|
||||||
|
|
||||||
private TimeSpan GetTimeSpanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE type)
|
private TimeSpan GetTimeSpanTimeout(HttpApi.HTTP_TIMEOUT_TYPE type)
|
||||||
{
|
{
|
||||||
// Since we maintain local state, GET is local.
|
// Since we maintain local state, GET is local.
|
||||||
return new TimeSpan(0, 0, (int)_timeouts[(int)type]);
|
return new TimeSpan(0, 0, (int)_timeouts[(int)type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetTimeSpanTimeout(UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE type, TimeSpan value)
|
private void SetTimeSpanTimeout(HttpApi.HTTP_TIMEOUT_TYPE type, TimeSpan value)
|
||||||
{
|
{
|
||||||
// All timeouts are defined as USHORT in native layer (except MinSendRate, which is ULONG). Make sure that
|
// All timeouts are defined as USHORT in native layer (except MinSendRate, which is ULONG). Make sure that
|
||||||
// timeout value is within range.
|
// timeout value is within range.
|
||||||
|
|
@ -217,25 +217,25 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
private unsafe void SetServerTimeouts(int[] timeouts, uint minSendBytesPerSecond)
|
private unsafe void SetServerTimeouts(int[] timeouts, uint minSendBytesPerSecond)
|
||||||
{
|
{
|
||||||
var timeoutinfo = new UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_LIMIT_INFO();
|
var timeoutinfo = new HttpApi.HTTP_TIMEOUT_LIMIT_INFO();
|
||||||
|
|
||||||
timeoutinfo.Flags = UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT;
|
timeoutinfo.Flags = HttpApi.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT;
|
||||||
timeoutinfo.DrainEntityBody =
|
timeoutinfo.DrainEntityBody =
|
||||||
(ushort)timeouts[(int)UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.DrainEntityBody];
|
(ushort)timeouts[(int)HttpApi.HTTP_TIMEOUT_TYPE.DrainEntityBody];
|
||||||
timeoutinfo.EntityBody =
|
timeoutinfo.EntityBody =
|
||||||
(ushort)timeouts[(int)UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.EntityBody];
|
(ushort)timeouts[(int)HttpApi.HTTP_TIMEOUT_TYPE.EntityBody];
|
||||||
timeoutinfo.RequestQueue =
|
timeoutinfo.RequestQueue =
|
||||||
(ushort)timeouts[(int)UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.RequestQueue];
|
(ushort)timeouts[(int)HttpApi.HTTP_TIMEOUT_TYPE.RequestQueue];
|
||||||
timeoutinfo.IdleConnection =
|
timeoutinfo.IdleConnection =
|
||||||
(ushort)timeouts[(int)UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.IdleConnection];
|
(ushort)timeouts[(int)HttpApi.HTTP_TIMEOUT_TYPE.IdleConnection];
|
||||||
timeoutinfo.HeaderWait =
|
timeoutinfo.HeaderWait =
|
||||||
(ushort)timeouts[(int)UnsafeNclNativeMethods.HttpApi.HTTP_TIMEOUT_TYPE.HeaderWait];
|
(ushort)timeouts[(int)HttpApi.HTTP_TIMEOUT_TYPE.HeaderWait];
|
||||||
timeoutinfo.MinSendRate = minSendBytesPerSecond;
|
timeoutinfo.MinSendRate = minSendBytesPerSecond;
|
||||||
|
|
||||||
var infoptr = new IntPtr(&timeoutinfo);
|
var infoptr = new IntPtr(&timeoutinfo);
|
||||||
|
|
||||||
_server.UrlGroup.SetProperty(
|
_server.UrlGroup.SetProperty(
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_SERVER_PROPERTY.HttpServerTimeoutsProperty,
|
HttpApi.HTTP_SERVER_PROPERTY.HttpServerTimeoutsProperty,
|
||||||
infoptr, (uint)TimeoutLimitSize);
|
infoptr, (uint)TimeoutLimitSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,15 +81,15 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
public WebListener(ILoggerFactory factory)
|
public WebListener(ILoggerFactory factory)
|
||||||
{
|
{
|
||||||
if (!UnsafeNclNativeMethods.HttpApi.Supported)
|
if (!HttpApi.Supported)
|
||||||
{
|
{
|
||||||
throw new PlatformNotSupportedException();
|
throw new PlatformNotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger = LogHelper.CreateLogger(factory, typeof(WebListener));
|
_logger = LogHelper.CreateLogger(factory, typeof(WebListener));
|
||||||
|
|
||||||
Debug.Assert(UnsafeNclNativeMethods.HttpApi.ApiVersion ==
|
Debug.Assert(HttpApi.ApiVersion ==
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_API_VERSION.Version20, "Invalid Http api version");
|
HttpApi.HTTP_API_VERSION.Version20, "Invalid Http api version");
|
||||||
|
|
||||||
_state = State.Stopped;
|
_state = State.Stopped;
|
||||||
_internalLock = new object();
|
_internalLock = new object();
|
||||||
|
|
@ -399,7 +399,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
internal unsafe bool ValidateAuth(NativeRequestContext requestMemory)
|
internal unsafe bool ValidateAuth(NativeRequestContext requestMemory)
|
||||||
{
|
{
|
||||||
var requestV2 = (UnsafeNclNativeMethods.HttpApi.HTTP_REQUEST_V2*)requestMemory.RequestBlob;
|
var requestV2 = (HttpApi.HTTP_REQUEST_V2*)requestMemory.RequestBlob;
|
||||||
if (!AuthenticationManager.AllowAnonymous && !AuthenticationManager.CheckAuthenticated(requestV2->pRequestInfo))
|
if (!AuthenticationManager.AllowAnonymous && !AuthenticationManager.CheckAuthenticated(requestV2->pRequestInfo))
|
||||||
{
|
{
|
||||||
SendError(requestMemory.RequestBlob->RequestId, HttpStatusCode.Unauthorized,
|
SendError(requestMemory.RequestBlob->RequestId, HttpStatusCode.Unauthorized,
|
||||||
|
|
@ -411,8 +411,8 @@ namespace Microsoft.Net.Http.Server
|
||||||
|
|
||||||
private unsafe void SendError(ulong requestId, HttpStatusCode httpStatusCode, IList<string> authChallenges)
|
private unsafe void SendError(ulong requestId, HttpStatusCode httpStatusCode, IList<string> authChallenges)
|
||||||
{
|
{
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_V2 httpResponse = new UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_V2();
|
HttpApi.HTTP_RESPONSE_V2 httpResponse = new HttpApi.HTTP_RESPONSE_V2();
|
||||||
httpResponse.Response_V1.Version = new UnsafeNclNativeMethods.HttpApi.HTTP_VERSION();
|
httpResponse.Response_V1.Version = new HttpApi.HTTP_VERSION();
|
||||||
httpResponse.Response_V1.Version.MajorVersion = (ushort)1;
|
httpResponse.Response_V1.Version.MajorVersion = (ushort)1;
|
||||||
httpResponse.Response_V1.Version.MinorVersion = (ushort)1;
|
httpResponse.Response_V1.Version.MinorVersion = (ushort)1;
|
||||||
|
|
||||||
|
|
@ -425,25 +425,25 @@ namespace Microsoft.Net.Http.Server
|
||||||
{
|
{
|
||||||
pinnedHeaders = new List<GCHandle>();
|
pinnedHeaders = new List<GCHandle>();
|
||||||
|
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_INFO[] knownHeaderInfo = null;
|
HttpApi.HTTP_RESPONSE_INFO[] knownHeaderInfo = null;
|
||||||
knownHeaderInfo = new UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_INFO[1];
|
knownHeaderInfo = new HttpApi.HTTP_RESPONSE_INFO[1];
|
||||||
gcHandle = GCHandle.Alloc(knownHeaderInfo, GCHandleType.Pinned);
|
gcHandle = GCHandle.Alloc(knownHeaderInfo, GCHandleType.Pinned);
|
||||||
pinnedHeaders.Add(gcHandle);
|
pinnedHeaders.Add(gcHandle);
|
||||||
httpResponse.pResponseInfo = (UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_INFO*)gcHandle.AddrOfPinnedObject();
|
httpResponse.pResponseInfo = (HttpApi.HTTP_RESPONSE_INFO*)gcHandle.AddrOfPinnedObject();
|
||||||
|
|
||||||
knownHeaderInfo[httpResponse.ResponseInfoCount].Type = UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_INFO_TYPE.HttpResponseInfoTypeMultipleKnownHeaders;
|
knownHeaderInfo[httpResponse.ResponseInfoCount].Type = HttpApi.HTTP_RESPONSE_INFO_TYPE.HttpResponseInfoTypeMultipleKnownHeaders;
|
||||||
knownHeaderInfo[httpResponse.ResponseInfoCount].Length =
|
knownHeaderInfo[httpResponse.ResponseInfoCount].Length =
|
||||||
(uint)Marshal.SizeOf<UnsafeNclNativeMethods.HttpApi.HTTP_MULTIPLE_KNOWN_HEADERS>();
|
(uint)Marshal.SizeOf<HttpApi.HTTP_MULTIPLE_KNOWN_HEADERS>();
|
||||||
|
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_MULTIPLE_KNOWN_HEADERS header = new UnsafeNclNativeMethods.HttpApi.HTTP_MULTIPLE_KNOWN_HEADERS();
|
HttpApi.HTTP_MULTIPLE_KNOWN_HEADERS header = new HttpApi.HTTP_MULTIPLE_KNOWN_HEADERS();
|
||||||
|
|
||||||
header.HeaderId = UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_HEADER_ID.Enum.HttpHeaderWwwAuthenticate;
|
header.HeaderId = HttpApi.HTTP_RESPONSE_HEADER_ID.Enum.HttpHeaderWwwAuthenticate;
|
||||||
header.Flags = UnsafeNclNativeMethods.HttpApi.HTTP_RESPONSE_INFO_FLAGS.PreserveOrder; // The docs say this is for www-auth only.
|
header.Flags = HttpApi.HTTP_RESPONSE_INFO_FLAGS.PreserveOrder; // The docs say this is for www-auth only.
|
||||||
|
|
||||||
UnsafeNclNativeMethods.HttpApi.HTTP_KNOWN_HEADER[] nativeHeaderValues = new UnsafeNclNativeMethods.HttpApi.HTTP_KNOWN_HEADER[authChallenges.Count];
|
HttpApi.HTTP_KNOWN_HEADER[] nativeHeaderValues = new HttpApi.HTTP_KNOWN_HEADER[authChallenges.Count];
|
||||||
gcHandle = GCHandle.Alloc(nativeHeaderValues, GCHandleType.Pinned);
|
gcHandle = GCHandle.Alloc(nativeHeaderValues, GCHandleType.Pinned);
|
||||||
pinnedHeaders.Add(gcHandle);
|
pinnedHeaders.Add(gcHandle);
|
||||||
header.KnownHeaders = (UnsafeNclNativeMethods.HttpApi.HTTP_KNOWN_HEADER*)gcHandle.AddrOfPinnedObject();
|
header.KnownHeaders = (HttpApi.HTTP_KNOWN_HEADER*)gcHandle.AddrOfPinnedObject();
|
||||||
|
|
||||||
for (int headerValueIndex = 0; headerValueIndex < authChallenges.Count; headerValueIndex++)
|
for (int headerValueIndex = 0; headerValueIndex < authChallenges.Count; headerValueIndex++)
|
||||||
{
|
{
|
||||||
|
|
@ -460,7 +460,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
// This type is a struct, not an object, so pinning it causes a boxed copy to be created. We can't do that until after all the fields are set.
|
// This type is a struct, not an object, so pinning it causes a boxed copy to be created. We can't do that until after all the fields are set.
|
||||||
gcHandle = GCHandle.Alloc(header, GCHandleType.Pinned);
|
gcHandle = GCHandle.Alloc(header, GCHandleType.Pinned);
|
||||||
pinnedHeaders.Add(gcHandle);
|
pinnedHeaders.Add(gcHandle);
|
||||||
knownHeaderInfo[0].pInfo = (UnsafeNclNativeMethods.HttpApi.HTTP_MULTIPLE_KNOWN_HEADERS*)gcHandle.AddrOfPinnedObject();
|
knownHeaderInfo[0].pInfo = (HttpApi.HTTP_MULTIPLE_KNOWN_HEADERS*)gcHandle.AddrOfPinnedObject();
|
||||||
|
|
||||||
httpResponse.ResponseInfoCount = 1;
|
httpResponse.ResponseInfoCount = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -483,7 +483,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
httpResponse.Response_V1.Headers.UnknownHeaderCount = 0;
|
httpResponse.Response_V1.Headers.UnknownHeaderCount = 0;
|
||||||
|
|
||||||
statusCode =
|
statusCode =
|
||||||
UnsafeNclNativeMethods.HttpApi.HttpSendHttpResponse(
|
HttpApi.HttpSendHttpResponse(
|
||||||
_requestQueue.Handle,
|
_requestQueue.Handle,
|
||||||
requestId,
|
requestId,
|
||||||
0,
|
0,
|
||||||
|
|
@ -499,7 +499,7 @@ namespace Microsoft.Net.Http.Server
|
||||||
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
// if we fail to send a 401 something's seriously wrong, abort the request
|
// if we fail to send a 401 something's seriously wrong, abort the request
|
||||||
UnsafeNclNativeMethods.HttpApi.HttpCancelHttpRequest(_requestQueue.Handle, requestId, IntPtr.Zero);
|
HttpApi.HttpCancelHttpRequest(_requestQueue.Handle, requestId, IntPtr.Zero);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc.
|
|
||||||
// All Rights Reserved
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR
|
|
||||||
// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
|
|
||||||
// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF
|
|
||||||
// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR
|
|
||||||
// NON-INFRINGEMENT.
|
|
||||||
// See the Apache 2 License for the specific language governing
|
|
||||||
// permissions and limitations under the License.
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// <copyright file="TraceEventType.cs" company="Microsoft">
|
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
// </copyright>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#if NETSTANDARD1_3
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
namespace System.Diagnostics
|
|
||||||
{
|
|
||||||
internal enum TraceEventType
|
|
||||||
{
|
|
||||||
Critical = 0x01,
|
|
||||||
Error = 0x02,
|
|
||||||
Warning = 0x04,
|
|
||||||
Information = 0x08,
|
|
||||||
Verbose = 0x10,
|
|
||||||
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Advanced)]
|
|
||||||
Start = 0x0100,
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Advanced)]
|
|
||||||
Stop = 0x0200,
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Advanced)]
|
|
||||||
Suspend = 0x0400,
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Advanced)]
|
|
||||||
Resume = 0x0800,
|
|
||||||
[EditorBrowsable(EditorBrowsableState.Advanced)]
|
|
||||||
Transfer = 0x1000,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc.
|
|
||||||
// All Rights Reserved
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR
|
|
||||||
// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
|
|
||||||
// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF
|
|
||||||
// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR
|
|
||||||
// NON-INFRINGEMENT.
|
|
||||||
// See the Apache 2 License for the specific language governing
|
|
||||||
// permissions and limitations under the License.
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// <copyright file="ExternDll.cs" company="Microsoft">
|
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
// </copyright>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#if NETSTANDARD1_3
|
|
||||||
|
|
||||||
namespace System
|
|
||||||
{
|
|
||||||
internal static class ExternDll
|
|
||||||
{
|
|
||||||
public const string api_ms_win_core_localization_LIB = "api-ms-win-core-localization-l2-1-0.dll";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,115 +0,0 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc.
|
|
||||||
// All Rights Reserved
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR
|
|
||||||
// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
|
|
||||||
// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF
|
|
||||||
// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR
|
|
||||||
// NON-INFRINGEMENT.
|
|
||||||
// See the Apache 2 License for the specific language governing
|
|
||||||
// permissions and limitations under the License.
|
|
||||||
|
|
||||||
// ==++==
|
|
||||||
//
|
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
//
|
|
||||||
// ==--==
|
|
||||||
/*=============================================================================
|
|
||||||
**
|
|
||||||
** Class: ExternalException
|
|
||||||
**
|
|
||||||
**
|
|
||||||
** Purpose: Exception base class for all errors from Interop or Structured
|
|
||||||
** Exception Handling code.
|
|
||||||
**
|
|
||||||
**
|
|
||||||
=============================================================================*/
|
|
||||||
|
|
||||||
#if NETSTANDARD1_3
|
|
||||||
|
|
||||||
namespace System.Runtime.InteropServices
|
|
||||||
{
|
|
||||||
using System;
|
|
||||||
using System.Globalization;
|
|
||||||
|
|
||||||
// Base exception for COM Interop errors &; Structured Exception Handler
|
|
||||||
// exceptions.
|
|
||||||
//
|
|
||||||
internal class ExternalException : Exception
|
|
||||||
{
|
|
||||||
public ExternalException()
|
|
||||||
{
|
|
||||||
SetErrorCode(__HResults.E_FAIL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExternalException(String message)
|
|
||||||
: base(message)
|
|
||||||
{
|
|
||||||
SetErrorCode(__HResults.E_FAIL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExternalException(String message, Exception inner)
|
|
||||||
: base(message, inner)
|
|
||||||
{
|
|
||||||
SetErrorCode(__HResults.E_FAIL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ExternalException(String message, int errorCode)
|
|
||||||
: base(message)
|
|
||||||
{
|
|
||||||
SetErrorCode(errorCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetErrorCode(int errorCode)
|
|
||||||
{
|
|
||||||
HResult = ErrorCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class __HResults
|
|
||||||
{
|
|
||||||
internal const int E_FAIL = unchecked((int)0x80004005);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual int ErrorCode
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return HResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override String ToString()
|
|
||||||
{
|
|
||||||
String message = Message;
|
|
||||||
String s;
|
|
||||||
String _className = GetType().ToString();
|
|
||||||
s = _className + " (0x" + HResult.ToString("X8", CultureInfo.InvariantCulture) + ")";
|
|
||||||
|
|
||||||
if (!(String.IsNullOrEmpty(message)))
|
|
||||||
{
|
|
||||||
s = s + ": " + message;
|
|
||||||
}
|
|
||||||
|
|
||||||
Exception _innerException = InnerException;
|
|
||||||
|
|
||||||
if (_innerException != null)
|
|
||||||
{
|
|
||||||
s = s + " ---> " + _innerException.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (StackTrace != null)
|
|
||||||
s += Environment.NewLine + StackTrace;
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc.
|
|
||||||
// All Rights Reserved
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
//
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR
|
|
||||||
// CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
|
|
||||||
// WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF
|
|
||||||
// TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR
|
|
||||||
// NON-INFRINGEMENT.
|
|
||||||
// See the Apache 2 License for the specific language governing
|
|
||||||
// permissions and limitations under the License.
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
// <copyright file="SafeNativeMethods.cs" company="Microsoft">
|
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
// </copyright>
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#if NETSTANDARD1_3
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace System
|
|
||||||
{
|
|
||||||
internal static class SafeNativeMethods
|
|
||||||
{
|
|
||||||
public const int
|
|
||||||
FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100,
|
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200,
|
|
||||||
FORMAT_MESSAGE_FROM_STRING = 0x00000400,
|
|
||||||
FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000,
|
|
||||||
FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000;
|
|
||||||
|
|
||||||
[DllImport(ExternDll.api_ms_win_core_localization_LIB, CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = true, BestFitMapping = true)]
|
|
||||||
public static unsafe extern int FormatMessage(int dwFlags, IntPtr lpSource_mustBeNull, uint dwMessageId,
|
|
||||||
int dwLanguageId, StringBuilder lpBuffer, int nSize, IntPtr[] arguments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
Loading…
Reference in New Issue