-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Throw HttpSysException with HttpInitialize status details #66859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
72786bb
359c2cc
64a280f
edcf167
fa3a04e
081a2a6
9426098
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Buffers; | ||
| using System.ComponentModel; | ||
| using System.Diagnostics; | ||
| using Microsoft.AspNetCore.Connections; | ||
| using Microsoft.AspNetCore.Http; | ||
|
|
@@ -52,7 +53,7 @@ public HttpSysListener(HttpSysOptions options, IMemoryPoolFactory<byte> memoryPo | |
|
|
||
| if (!HttpApi.Supported) | ||
| { | ||
| throw new PlatformNotSupportedException(); | ||
| throw CreateHttpInitializeFailureException(HttpApi.HttpInitializeStatusCode); | ||
| } | ||
|
|
||
| MemoryPool = memoryPoolFactory.Create(new MemoryPoolOptions { Owner = "httpsys" }); | ||
|
|
@@ -256,6 +257,19 @@ private void DisposeInternal() | |
| _serverSession.Dispose(); | ||
| } | ||
|
|
||
| internal static PlatformNotSupportedException CreateHttpInitializeFailureException(uint httpInitializeStatusCode) | ||
| { | ||
| if (httpInitializeStatusCode == ErrorCodes.ERROR_SUCCESS) | ||
| { | ||
| return new PlatformNotSupportedException(); | ||
| } | ||
|
|
||
| var httpInitializeException = new Win32Exception((int)httpInitializeStatusCode); | ||
| return new PlatformNotSupportedException( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe should throw an HttpSysException
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder if this should just throw the HttpSysException? Any reason to keep using PlatformNotSupportedException?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot see above
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in 6b01d35: for non-success |
||
| $"HttpInitialize failed with status code 0x{httpInitializeStatusCode:X8} (HRESULT 0x{httpInitializeException.HResult:X8}).", | ||
| httpInitializeException); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Accept a request from the incoming request queue. | ||
| /// </summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.ComponentModel; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.AspNetCore.Server.HttpSys; | ||
|
|
||
| public class HttpSysListenerTests | ||
| { | ||
| [Fact] | ||
| public void CreateHttpInitializeFailureException_WithErrorCode_IncludesWin32ExceptionDetails() | ||
| { | ||
| var errorCode = ErrorCodes.ERROR_ACCESS_DENIED; | ||
| var exception = HttpSysListener.CreateHttpInitializeFailureException(errorCode); | ||
| var expectedWin32Exception = new Win32Exception((int)errorCode); | ||
|
|
||
| Assert.Contains($"status code 0x{errorCode:X8}", exception.Message); | ||
|
Comment on lines
+11
to
+16
|
||
| Assert.Contains($"HRESULT 0x{expectedWin32Exception.HResult:X8}", exception.Message); | ||
|
|
||
| var win32Exception = Assert.IsType<Win32Exception>(exception.InnerException); | ||
| Assert.Equal((int)errorCode, win32Exception.NativeErrorCode); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CreateHttpInitializeFailureException_WithSuccessCode_ReturnsExceptionWithoutInnerException() | ||
| { | ||
| var exception = HttpSysListener.CreateHttpInitializeFailureException(ErrorCodes.ERROR_SUCCESS); | ||
|
|
||
| Assert.Null(exception.InnerException); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment here?