Added nullability to HttpApi

nullableenabled
David Hall 2023-10-04 16:12:21 -06:00
parent c84535d13e
commit 2226f6c44c
5 changed files with 195 additions and 43 deletions

View File

@ -1,4 +1,3 @@
namespace Vanara.PInvoke;
/// <summary>Items from HttpApi.dll.</summary>
@ -235,9 +234,11 @@ public static partial class HttpApi
[Flags]
public enum HTTP_CREATE_REQUEST_QUEUE_FLAG : uint
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
HTTP_CREATE_REQUEST_QUEUE_FLAG_OPEN_EXISTING = 0x00000001,
HTTP_CREATE_REQUEST_QUEUE_FLAG_CONTROLLER = 0x00000002,
HTTP_CREATE_REQUEST_QUEUE_FLAG_DELEGATION = 0x00000008,
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
/// <summary/>
@ -1601,10 +1602,12 @@ public static partial class HttpApi
[Flags]
public enum HTTP_REQUEST_SIZING_INFO_FLAG : uint
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
HTTP_REQUEST_SIZING_INFO_FLAG_TCP_FAST_OPEN = 0x00000001,
HTTP_REQUEST_SIZING_INFO_FLAG_TLS_SESSION_RESUMPTION = 0x00000002,
HTTP_REQUEST_SIZING_INFO_FLAG_TLS_FALSE_START = 0x00000004,
HTTP_REQUEST_SIZING_INFO_FLAG_FIRST_REQUEST = 0x00000008,
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
/// <summary>List of possible sizes for which information will be retured in HTTP_REQUEST_SIZING_INFO.</summary>
@ -1636,6 +1639,7 @@ public static partial class HttpApi
[PInvokeData("http.h")]
public enum HTTP_REQUEST_TIMING_TYPE
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
HttpRequestTimingTypeConnectionStart,
HttpRequestTimingTypeDataStart,
HttpRequestTimingTypeTlsCertificateLoadStart,
@ -1667,6 +1671,7 @@ public static partial class HttpApi
HttpRequestTimingTypeHttp3HeaderDecodeStart,
HttpRequestTimingTypeHttp3HeaderDecodeEnd,
HttpRequestTimingTypeMax
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
/// <summary>
@ -2070,8 +2075,10 @@ public static partial class HttpApi
[PInvokeData("http.h")]
public enum HTTP_SERVICE_CONFIG_SETTING_KEY
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
HttpNone = 0,
HttpTlsThrottle
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
/// <summary>A combination of zero or more of the following flag values can be combined with OR as appropriate.</summary>
@ -2156,6 +2163,7 @@ public static partial class HttpApi
HeaderWaitTimeout,
}
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
/// <summary>The extended param type for the SSL extended params.</summary>
[PInvokeData("http.h")]
public enum HTTP_SSL_SERVICE_CONFIG_EX_PARAM_TYPE
@ -2177,6 +2185,7 @@ public static partial class HttpApi
HttpSchemeHttps,
HttpSchemeMaximum
}
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
/// <summary>The URL flags qualifying the URL that is removed.</summary>
[PInvokeData("http.h", MSDNShortId = "NF:http.HttpRemoveUrlFromUrlGroup")]

View File

@ -582,7 +582,7 @@ public static partial class HttpApi
[DllImport(Lib_Httpapi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("http.h", MSDNShortId = "NF:http.HttpCreateRequestQueue")]
public static extern Win32Error HttpCreateRequestQueue(HTTPAPI_VERSION Version, [Optional, MarshalAs(UnmanagedType.LPWStr)] string? Name,
[In, Optional] SECURITY_ATTRIBUTES SecurityAttributes, [In, Optional] HTTP_CREATE_REQUEST_QUEUE_FLAG Flags,
[In, Optional] SECURITY_ATTRIBUTES? SecurityAttributes, [In, Optional] HTTP_CREATE_REQUEST_QUEUE_FLAG Flags,
out SafeHREQQUEUE RequestQueueHandle);
/// <summary>The <c>HttpCreateServerSession</c> function creates a server session for the specified version.</summary>
@ -997,7 +997,7 @@ public static partial class HttpApi
{
if (!CorrespondingTypeAttribute.CanSet<T, HTTP_SERVICE_CONFIG_ID>(out var ConfigId))
throw new ArgumentOutOfRangeException(nameof(pConfigInformation));
using var mem = new SafeCoTaskMemStruct<T>(pConfigInformation);
using SafeCoTaskMemStruct<T> mem = pConfigInformation;
return HttpDeleteServiceConfiguration(default, ConfigId, mem, mem.Size, default);
}
@ -1245,7 +1245,7 @@ public static partial class HttpApi
// https://docs.microsoft.com/en-us/windows/win32/api/http/nf-http-httpprepareurl HTTPAPI_LINKAGE ULONG HttpPrepareUrl( PVOID Reserved,
// ULONG Flags, [in] PCWSTR Url, [out] PWSTR *PreparedUrl );
[PInvokeData("http.h", MSDNShortId = "NF:http.HttpPrepareUrl")]
public static Win32Error HttpPrepareUrl(string Url, out string PreparedUrl)
public static Win32Error HttpPrepareUrl(string Url, out string? PreparedUrl)
{
var err = HttpPrepareUrl(default, default, Url, out var pUrl);
PreparedUrl = err.Succeeded ? pUrl.ToString(-1, CharSet.Unicode) : null;
@ -2883,7 +2883,7 @@ public static partial class HttpApi
/// </para>
/// </remarks>
public static Win32Error HttpReceiveHttpRequest(HREQQUEUEv1 RequestQueueHandle, [In] HTTP_REQUEST_ID RequestId,
[In] HTTP_RECEIVE_REQUEST_FLAG Flags, out HTTP_REQUEST RequestBuffer)
[In] HTTP_RECEIVE_REQUEST_FLAG Flags, out HTTP_REQUEST? RequestBuffer)
{
RequestBuffer = new();
var err = HttpReceiveHttpRequest(RequestQueueHandle, RequestId, Flags, RequestBuffer.Ptr, RequestBuffer.Ptr.Size, out var sz, default);
@ -3002,7 +3002,7 @@ public static partial class HttpApi
[DllImport(Lib_Httpapi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("http.h", MSDNShortId = "NF:http.HttpReceiveRequestEntityBody")]
public static extern Win32Error HttpReceiveRequestEntityBody([In] HREQQUEUEv1 RequestQueueHandle, [In] HTTP_REQUEST_ID RequestId,
[In] HTTP_RECEIVE_REQUEST_ENTITY_BODY_FLAG Flags, [Out] IntPtr EntityBuffer, [In] uint EntityBufferLength, out uint BytesReturned,
[In] HTTP_RECEIVE_REQUEST_ENTITY_BODY_FLAG Flags, [Out] IntPtr EntityBuffer, [In] uint EntityBufferLength, [In, Optional] IntPtr BytesReturned,
in NativeOverlapped Overlapped);
/// <summary>The <c>HttpReceiveRequestEntityBody</c> function receives additional entity body data for a specified HTTP request.</summary>
@ -3224,7 +3224,7 @@ public static partial class HttpApi
// HttpRemoveUrlFromUrlGroup( [in] HTTP_URL_GROUP_ID UrlGroupId, [in] PCWSTR pFullyQualifiedUrl, [in] ULONG Flags );
[DllImport(Lib_Httpapi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("http.h", MSDNShortId = "NF:http.HttpRemoveUrlFromUrlGroup")]
public static extern Win32Error HttpRemoveUrlFromUrlGroup([In] HTTP_URL_GROUP_ID UrlGroupId, [MarshalAs(UnmanagedType.LPWStr)] string pFullyQualifiedUrl,
public static extern Win32Error HttpRemoveUrlFromUrlGroup([In] HTTP_URL_GROUP_ID UrlGroupId, [MarshalAs(UnmanagedType.LPWStr)] string? pFullyQualifiedUrl,
[In, Optional] HTTP_URL_FLAG Flags);
/// <summary>The <c>HttpSendHttpResponse</c> function sends an HTTP response to the specified HTTP request.</summary>
@ -3380,7 +3380,7 @@ public static partial class HttpApi
[DllImport(Lib_Httpapi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("http.h", MSDNShortId = "NF:http.HttpSendHttpResponse")]
public static extern Win32Error HttpSendHttpResponse([In] HREQQUEUEv1 RequestQueueHandle, [In] HTTP_REQUEST_ID RequestId, [In] HTTP_SEND_RESPONSE_FLAG Flags,
in HTTP_RESPONSE_V1 HttpResponse, in HTTP_CACHE_POLICY CachePolicy, out uint BytesSent, [In, Optional] IntPtr Reserved1, [In, Optional] uint Reserved2,
in HTTP_RESPONSE_V1 HttpResponse, in HTTP_CACHE_POLICY CachePolicy, [Optional] IntPtr BytesSent, [In, Optional] IntPtr Reserved1, [In, Optional] uint Reserved2,
in NativeOverlapped Overlapped, in HTTP_LOG_DATA LogData);
/// <summary>The <c>HttpSendHttpResponse</c> function sends an HTTP response to the specified HTTP request.</summary>
@ -3692,7 +3692,7 @@ public static partial class HttpApi
[DllImport(Lib_Httpapi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("http.h", MSDNShortId = "NF:http.HttpSendHttpResponse")]
public static extern Win32Error HttpSendHttpResponse([In] HREQQUEUEv1 RequestQueueHandle, [In] HTTP_REQUEST_ID RequestId, [In] HTTP_SEND_RESPONSE_FLAG Flags,
in HTTP_RESPONSE_V2 HttpResponse, in HTTP_CACHE_POLICY CachePolicy, out uint BytesSent, [In, Optional] IntPtr Reserved1, [In, Optional] uint Reserved2,
in HTTP_RESPONSE_V2 HttpResponse, in HTTP_CACHE_POLICY CachePolicy, [Optional] IntPtr BytesSent, [In, Optional] IntPtr Reserved1, [In, Optional] uint Reserved2,
in NativeOverlapped Overlapped, in HTTP_LOG_DATA LogData);
/// <summary>The <c>HttpSendHttpResponse</c> function sends an HTTP response to the specified HTTP request.</summary>
@ -3851,6 +3851,162 @@ public static partial class HttpApi
in HTTP_RESPONSE_V2 HttpResponse, [In, Optional] IntPtr CachePolicy, out uint BytesSent, [In, Optional] IntPtr Reserved1, [In, Optional] uint Reserved2,
[In, Optional] IntPtr Overlapped, [In, Optional] IntPtr LogData);
/// <summary>The <c>HttpSendHttpResponse</c> function sends an HTTP response to the specified HTTP request.</summary>
/// <param name="RequestQueueHandle">
/// <para>
/// A handle to the request queue from which the specified request was retrieved. A request queue is created and its handle returned by a
/// call to the HttpCreateRequestQueue function.
/// </para>
/// <para>
/// <c>Windows Server 2003 with SP1 and Windows XP with SP2:</c> The handle to the request queue is created by the HttpCreateHttpHandle function.
/// </para>
/// </param>
/// <param name="RequestId">
/// An identifier of the HTTP request to which this response corresponds. This value is returned in the <c>RequestId</c> member of the
/// HTTP_REQUEST structure by a call to the HttpReceiveHttpRequest function. This value cannot be <c>HTTP_NULL_ID</c>.
/// </param>
/// <param name="Flags">
/// <para>This parameter can be a combination of some of the following flag values. Those that are mutually exclusive are marked accordingly.</para>
/// <list type="table">
/// <listheader>
/// <term>Flags</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term><c>HTTP_SEND_RESPONSE_FLAG_DISCONNECT</c></term>
/// <term>
/// The network connection should be disconnected after sending this response, overriding any persistent connection features associated
/// with the version of HTTP in use.
/// </term>
/// </item>
/// <item>
/// <term><c>HTTP_SEND_RESPONSE_FLAG_MORE_DATA</c></term>
/// <term>
/// Additional entity body data for this response is sent by the application through one or more subsequent calls to
/// HttpSendResponseEntityBody. The last call sending entity-body data then sets this flag to zero.
/// </term>
/// </item>
/// <item>
/// <term><c>HTTP_SEND_RESPONSE_FLAG_BUFFER_DATA</c></term>
/// <term>
/// This flag enables buffering of data in the kernel on a per-response basis. It should be used by an application doing synchronous I/O
/// or by an application doing asynchronous I/O with no more than one outstanding send at a time. Applications that use asynchronous I/O
/// and that may have more than one send outstanding at a time should not use this flag. When this flag is set, it should also be used
/// consistently in calls to the HttpSendResponseEntityBody function. <c>Windows Server 2003:</c> This flag is not supported. This flag
/// is new for Windows Server 2003 with SP1.
/// </term>
/// </item>
/// <item>
/// <term><c>HTTP_SEND_RESPONSE_FLAG_ENABLE_NAGLING</c></term>
/// <term>
/// Enables the TCP nagling algorithm for this send only. <c>Windows Server 2003 with SP1 and Windows XP with SP2:</c> This flag is not supported.
/// </term>
/// </item>
/// <item>
/// <term><c>HTTP_SEND_RESPONSE_FLAG_PROCESS_RANGES</c></term>
/// <term>
/// Specifies that for a range request, the full response content is passed and the caller wants the HTTP API to process ranges
/// appropriately. Windows Server 2008 R2 and Windows 7 or later. <c>Note</c> This flag is supported.
/// </term>
/// </item>
/// <item>
/// <term><c>HTTP_SEND_RESPONSE_FLAG_OPAQUE</c></term>
/// <term>
/// Specifies that the request/response is not HTTP compliant and all subsequent bytes should be treated as entity-body. Applications
/// specify this flag when it is accepting a Web Socket upgrade request and informing HTTP.sys to treat the connection data as opaque
/// data. This flag is only allowed when the <c>StatusCode</c> member of <c>pHttpResponse</c> is <c>101</c>, switching protocols.
/// <c>HttpSendHttpResponse</c> returns <c>ERROR_INVALID_PARAMETER</c> for all other HTTP response types if this flag is used. <c>Windows
/// 8 and later:</c> This flag is supported.
/// </term>
/// </item>
/// </list>
/// </param>
/// <param name="HttpResponse">A pointer to an HTTP_RESPONSE structure that defines the HTTP response.</param>
/// <param name="CachePolicy">
/// <para>A pointer to the HTTP_CACHE_POLICY structure used to cache the response.</para>
/// <para><c>Windows Server 2003 with SP1 and Windows XP with SP2:</c> This parameter is reserved and must be <c>NULL</c>.</para>
/// </param>
/// <param name="BytesSent">
/// <para>Optional. A pointer to a variable that receives the number, in bytes, sent if the function operates synchronously.</para>
/// <para>
/// When making an asynchronous call using <c>pOverlapped</c>, set <c>pBytesSent</c> to <c>NULL</c>. Otherwise, when <c>pOverlapped</c>
/// is set to <c>NULL</c>, <c>pBytesSent</c> must contain a valid memory address and not be set to <c>NULL</c>.
/// </para>
/// </param>
/// <param name="Reserved1">This parameter is reserved and must be <c>NULL</c>.</param>
/// <param name="Reserved2">This parameter is reserved and must be zero.</param>
/// <param name="Overlapped">
/// <para>For asynchronous calls, set <c>pOverlapped</c> to point to an OVERLAPPED structure; for synchronous calls, set to <c>NULL</c>.</para>
/// <para>
/// A synchronous call blocks until all response data specified in the <c>pHttpResponse</c> parameter is sent, whereas an asynchronous
/// call immediately returns <c>ERROR_IO_PENDING</c> and the calling application then uses GetOverlappedResult or I/O completion ports to
/// determine when the operation is completed. For more information about using OVERLAPPED structures for synchronization, see
/// Synchronization and Overlapped Input and Output.
/// </para>
/// </param>
/// <param name="LogData">
/// <para>
/// A pointer to the HTTP_LOG_DATA structure used to log the response. Pass a pointer to the HTTP_LOG_FIELDS_DATA structure and cast it
/// to <c>PHTTP_LOG_DATA</c>.
/// </para>
/// <para>
/// Be aware that even when logging is enabled on a URL Group, or server session, the response will not be logged unless the application
/// supplies the log fields data structure.
/// </para>
/// <para><c>Windows Server 2003 and Windows XP with SP2:</c> This parameter is reserved and must be <c>NULL</c>.</para>
/// <para><c>Windows Vista and Windows Server 2008:</c> This parameter is new for Windows Vista, and Windows Server 2008</para>
/// </param>
/// <returns>
/// <para>If the function succeeds, the function returns <c>NO_ERROR</c>.</para>
/// <para>
/// If the function is used asynchronously, a return value of <c>ERROR_IO_PENDING</c> indicates that the next request is not yet ready
/// and is retrieved later through normal overlapped I/O completion mechanisms.
/// </para>
/// <para>If the function fails, it returns one of the following error codes.</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term><c>ERROR_INVALID_PARAMETER</c></term>
/// <term>One or more of the supplied parameters is in an unusable form.</term>
/// </item>
/// <item>
/// <term><c>Other</c></term>
/// <term>A system error code defined in WinError.h.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>
/// The <c>HttpSendHttpResponse</c> function is used to create and send a response header, and the HttpSendResponseEntityBody function
/// can be used to send entity-body data as required.
/// </para>
/// <para>
/// If neither a content-length header nor a transfer-encoding header is included with the response, the application must indicate the
/// end of the response by explicitly closing the connection by using the <c>HTTP_SEND_RESPONSE_DISCONNECT</c> flag.
/// </para>
/// <para>
/// If an application specifies a "Server:" header in a response, using the <c>HttpHeaderServer</c> identifier in the HTTP_KNOWN_HEADER
/// structure, that specified value is placed as the first part of the header, followed by a space and then "Microsoft-HTTPAPI/1.0". If
/// no server header is specified, <c>HttpSendHttpResponse</c> supplies "Microsoft-HTTPAPI/1.0" as the server header.
/// </para>
/// <para>
/// <c>Note</c> The <c>HttpSendHttpResponse</c> and HttpSendResponseEntityBody function must not be called simultaneously from different
/// threads on the same <c>RequestId</c>.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/http/nf-http-httpsendhttpresponse HTTPAPI_LINKAGE ULONG HttpSendHttpResponse( [in]
// HANDLE RequestQueueHandle, [in] HTTP_REQUEST_ID RequestId, [in] ULONG Flags, [in] PHTTP_RESPONSE HttpResponse, [in, optional]
// PHTTP_CACHE_POLICY CachePolicy, [out] PULONG BytesSent, [in] PVOID Reserved1, [in] ULONG Reserved2, [in] LPOVERLAPPED Overlapped, [in,
// optional] PHTTP_LOG_DATA LogData );
[DllImport(Lib_Httpapi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("http.h", MSDNShortId = "NF:http.HttpSendHttpResponse")]
public static unsafe extern Win32Error HttpSendHttpResponse([In] HREQQUEUEv1 RequestQueueHandle, [In] HTTP_REQUEST_ID RequestId, [In] HTTP_SEND_RESPONSE_FLAG Flags,
[In] IntPtr HttpResponse, [In] HTTP_CACHE_POLICY* CachePolicy, [Optional] uint* BytesSent, [In, Optional] IntPtr Reserved1, [In, Optional] uint Reserved2,
[In, Optional] NativeOverlapped* Overlapped, [In, Optional] HTTP_LOG_DATA* LogData);
/// <summary>The <c>HttpSendResponseEntityBody</c> function sends entity-body data associated with an HTTP response.</summary>
/// <param name="RequestQueueHandle">
/// <para>
@ -3998,7 +4154,7 @@ public static partial class HttpApi
[DllImport(Lib_Httpapi, SetLastError = false, ExactSpelling = true)]
[PInvokeData("http.h", MSDNShortId = "NF:http.HttpSendResponseEntityBody")]
public static extern Win32Error HttpSendResponseEntityBody([In] HREQQUEUEv1 RequestQueueHandle, [In] HTTP_REQUEST_ID RequestId, [In] HTTP_SEND_RESPONSE_FLAG Flags,
[In] ushort EntityChunkCount, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] HTTP_DATA_CHUNK[] EntityChunks, out uint BytesSent,
[In] ushort EntityChunkCount, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] HTTP_DATA_CHUNK[] EntityChunks, [Optional] IntPtr BytesSent,
[In, Optional] IntPtr Reserved1, [In, Optional] uint Reserved2, in NativeOverlapped Overlapped, in HTTP_LOG_DATA LogData);
/// <summary>The <c>HttpSendResponseEntityBody</c> function sends entity-body data associated with an HTTP response.</summary>

View File

@ -1,3 +1,5 @@
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
using System.Collections.Generic;
namespace Vanara.PInvoke;
@ -260,7 +262,7 @@ public static partial class HttpApi
/// <summary>Pointer to the first question mark (?) in the string, or <c>NULL</c> if there is none.</summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string pQueryString;
public string? pQueryString;
}
/// <summary>Properties that can be passed down with IOCTL_HTTP_CREATE_REQUEST_QUEUE_EX.</summary>
@ -295,42 +297,29 @@ public static partial class HttpApi
/// <summary>Initializes a new instance of the <see cref="HTTP_DATA_CHUNK"/> struct for <c>HttpDataChunkFromMemory</c>.</summary>
/// <param name="mem">The memory.</param>
public HTTP_DATA_CHUNK(SafeAllocatedMemoryHandleBase mem) : this(HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory)
{
FromMemory = new(mem);
}
public HTTP_DATA_CHUNK(SafeAllocatedMemoryHandleBase mem) : this(HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromMemory) => FromMemory = new(mem);
/// <summary>Initializes a new instance of the <see cref="HTTP_DATA_CHUNK"/> struct for <c>HttpDataChunkFromFileHandle</c>.</summary>
/// <param name="hFile">The file handle.</param>
/// <param name="startingOffset">The starting offset.</param>
/// <param name="length">The length.</param>
public HTTP_DATA_CHUNK(HFILE hFile, ulong startingOffset = 0, ulong length = HTTP_BYTE_RANGE_TO_EOF) : this(HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromFileHandle)
{
public HTTP_DATA_CHUNK(HFILE hFile, ulong startingOffset = 0, ulong length = HTTP_BYTE_RANGE_TO_EOF) : this(HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromFileHandle) =>
FromFileHandle = new() { FileHandle = hFile, ByteRange = new() { StartingOffset = startingOffset, Length = length } };
}
/// <summary>Initializes a new instance of the <see cref="HTTP_DATA_CHUNK"/> struct for <c>HttpDataChunkFromFragmentCache</c>.</summary>
/// <param name="fragmentName">Name of the fragment.</param>
public HTTP_DATA_CHUNK(SafeLPWSTR fragmentName) : this(HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromFragmentCache)
{
FromFragmentCache = new(fragmentName);
}
public HTTP_DATA_CHUNK(SafeLPWSTR fragmentName) : this(HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromFragmentCache) => FromFragmentCache = new(fragmentName);
/// <summary>Initializes a new instance of the <see cref="HTTP_DATA_CHUNK"/> struct for <c>HttpDataChunkFromFragmentCacheEx</c>.</summary>
/// <param name="fragmentName">Name of the fragment.</param>
/// <param name="startingOffset">The starting offset.</param>
/// <param name="length">The length.</param>
public HTTP_DATA_CHUNK(SafeLPWSTR fragmentName, ulong startingOffset = 0, ulong length = HTTP_BYTE_RANGE_TO_EOF) : this(HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromFragmentCacheEx)
{
public HTTP_DATA_CHUNK(SafeLPWSTR fragmentName, ulong startingOffset = 0, ulong length = HTTP_BYTE_RANGE_TO_EOF) : this(HTTP_DATA_CHUNK_TYPE.HttpDataChunkFromFragmentCacheEx) =>
FromFragmentCacheEx = new() { pFragmentName = fragmentName, ByteRange = new() { StartingOffset = startingOffset, Length = length } };
}
/// <summary>Initializes a new instance of the <see cref="HTTP_DATA_CHUNK"/> struct for <c>HttpDataChunkTrailers</c>.</summary>
/// <param name="headers">The headers.</param>
public HTTP_DATA_CHUNK(SafeNativeArray<HTTP_UNKNOWN_HEADER> headers) : this(HTTP_DATA_CHUNK_TYPE.HttpDataChunkTrailers)
{
Trailers = new() { TrailerCount = (ushort)(headers?.Count ?? 0), pTrailers = headers };
}
public HTTP_DATA_CHUNK(SafeNativeArray<HTTP_UNKNOWN_HEADER> headers) : this(HTTP_DATA_CHUNK_TYPE.HttpDataChunkTrailers) => Trailers = new() { TrailerCount = (ushort)headers.Count, pTrailers = headers };
/// <summary>Type of data store. This member can be one of the values from the <c>HTTP_DATA_CHUNK_TYPE</c> enumeration.</summary>
public HTTP_DATA_CHUNK_TYPE DataChunkType;
@ -338,6 +327,7 @@ public static partial class HttpApi
/// <summary/>
private UNION union;
/// <summary/>
public FROMMEMORY FromMemory { get => union.FromMemory; set => union.FromMemory = value; }
/// <summary/>
@ -387,7 +377,7 @@ public static partial class HttpApi
/// <summary>Length, in bytes, of the data block.</summary>
public uint BufferLength;
internal FROMMEMORY(SafeAllocatedMemoryHandleBase mem) { pBuffer = mem ?? default; BufferLength = mem?.Size ?? 0; }
internal FROMMEMORY(SafeAllocatedMemoryHandleBase mem) { pBuffer = mem; BufferLength = mem.Size; }
}
/// <summary/>
@ -921,7 +911,7 @@ public static partial class HttpApi
/// is <c>NULL</c>, the HTTP Server API logs a default string.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string SoftwareName;
public string? SoftwareName;
/// <summary>
/// <para>The length, in bytes, of the software name. The length cannot be greater than <c>MAX_PATH</c>.</para>
@ -1450,7 +1440,7 @@ public static partial class HttpApi
/// An array of HTTP_UNKNOWN_HEADER structures. This array contains one structure for each of the unknown headers sent
/// in the HTTP request.
/// </summary>
public HTTP_UNKNOWN_HEADER[] UnknownHeaders => pUnknownHeaders.ToArray<HTTP_UNKNOWN_HEADER>(UnknownHeaderCount);
public HTTP_UNKNOWN_HEADER[] UnknownHeaders => pUnknownHeaders.ToArray<HTTP_UNKNOWN_HEADER>(UnknownHeaderCount) ?? new HTTP_UNKNOWN_HEADER[0];
}
/// <summary>The <c>HTTP_REQUEST_INFO</c> structure extends the HTTP_REQUEST structure with additional information about the request.</summary>
@ -1891,7 +1881,7 @@ public static partial class HttpApi
/// An array of <see cref="HTTP_DATA_CHUNK"/> structures that contains the data blocks making up the entity body.
/// HttpReceiveHttpRequest does not copy the entity body unless called with the HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY flag set.
/// </summary>
public HTTP_DATA_CHUNK[] EntityChunks => Ptr.AsRef().pEntityChunks.ToArray<HTTP_DATA_CHUNK>(Ptr.AsRef().EntityChunkCount);
public HTTP_DATA_CHUNK[] EntityChunks => Ptr.AsRef().pEntityChunks.ToArray<HTTP_DATA_CHUNK>(Ptr.AsRef().EntityChunkCount) ?? new HTTP_DATA_CHUNK[0];
/// <summary>Raw connection ID for an Secure Sockets Layer (SSL) request.</summary>
public HTTP_RAW_CONNECTION_ID RawConnectionId => Ptr.AsRef().RawConnectionId;
@ -1905,7 +1895,7 @@ public static partial class HttpApi
/// <summary>
/// An array of <see cref="HTTP_REQUEST_INFO"/> structures that contains additional information about the request.
/// </summary>
public HTTP_REQUEST_INFO[] RequestInfo => Ptr.AsRef().pRequestInfo.ToArray<HTTP_REQUEST_INFO>(Ptr.AsRef().RequestInfoCount);
public HTTP_REQUEST_INFO[] RequestInfo => Ptr.AsRef().pRequestInfo.ToArray<HTTP_REQUEST_INFO>(Ptr.AsRef().RequestInfoCount) ?? new HTTP_REQUEST_INFO[0];
internal SafeCoTaskMemStruct<HTTP_REQUEST_V2> Ptr { get; private set; }
}
@ -2150,7 +2140,7 @@ public static partial class HttpApi
/// <para>If <c>NULL</c>, the client assumes the protection space consists of all the URIs under the responding server.</para>
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string DomainName;
public string? DomainName;
/// <summary>The length, in bytes, of the <c>Realm</c> member.</summary>
public ushort RealmLength;
@ -2635,7 +2625,7 @@ public static partial class HttpApi
/// store location.
/// </summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string pSslCertStoreName;
public string? pSslCertStoreName;
/// <summary>
/// <para>Determines how client certificates are checked. This member can be one of the following values.</para>
@ -3126,7 +3116,7 @@ public static partial class HttpApi
[MarshalAs(UnmanagedType.U1)] public bool CertDeniedByMapper;
/// <summary>The actual certificate.</summary>
public byte[] CertEncoded => pCertEncoded.ToByteArray((int)CertEncodedSize);
public byte[] CertEncoded => pCertEncoded.ToByteArray((int)CertEncodedSize) ?? new byte[0];
}
/// <summary>

View File

@ -1,9 +1,4 @@
global using System;
global using System.Collections.Generic;
global using System.Runtime.InteropServices;
global using Vanara.Extensions;
global using Vanara.InteropServices;
global using static Vanara.PInvoke.Ws2_32;
global using static Vanara.PInvoke.Ws2_32;
global using HTTP_SERVICE_CONFIG_SETTING_PARAM = System.UInt32;
global using HTTP_CONNECTION_ID = System.UInt64;
global using HTTP_OPAQUE_ID = System.UInt64;

View File

@ -7,7 +7,9 @@ namespace Vanara.PInvoke.Tests;
[TestFixture]
public class HttpApiTests
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
SafeHttpInitialize init;
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
[OneTimeSetUp]
public void _Setup()