@@ -312,6 +312,62 @@ internal unsafe bool TryGetTlsClientHelloMessageBytes(
312312 throw new HttpSysException ( ( int ) statusCode ) ;
313313 }
314314
315+ /// <summary>
316+ /// Generic synchronous wrapper around <c>HttpQueryRequestProperty</c>.
317+ /// Returns true on success, false if <paramref name="output"/> is too small (with the required size in <paramref name="bytesReturned"/>),
318+ /// and throws for any other failure.
319+ /// </summary>
320+ internal unsafe bool TryGetRequestPropertyCore (
321+ HTTP_REQUEST_PROPERTY propertyId ,
322+ ReadOnlySpan < byte > qualifier ,
323+ Span < byte > output ,
324+ out int bytesReturned )
325+ {
326+ bytesReturned = default ;
327+ if ( ! HttpApi . HttpGetRequestPropertySupported )
328+ {
329+ throw new InvalidOperationException ( "Windows HTTP Server API does not support HttpQueryRequestProperty." ) ;
330+ }
331+
332+ uint statusCode ;
333+ var requestId = PinsReleased ? Request . RequestId : RequestId ;
334+
335+ uint bytesReturnedValue = 0 ;
336+ uint * bytesReturnedPointer = & bytesReturnedValue ;
337+
338+ // `fixed` on an empty span yields a null pointer, which is what HttpQueryRequestProperty
339+ // requires for unused qualifier/output parameters.
340+ fixed ( byte * pQualifier = qualifier )
341+ fixed ( byte * pOutput = output )
342+ {
343+ statusCode = HttpApi . HttpGetRequestProperty (
344+ requestQueueHandle : Server . RequestQueue . Handle ,
345+ requestId ,
346+ propertyId : propertyId ,
347+ qualifier : pQualifier ,
348+ qualifierSize : ( uint ) qualifier . Length ,
349+ output : pOutput ,
350+ outputSize : ( uint ) output . Length ,
351+ bytesReturned : ( IntPtr ) bytesReturnedPointer ,
352+ overlapped : IntPtr . Zero ) ;
353+
354+ bytesReturned = checked ( ( int ) bytesReturnedValue ) ;
355+
356+ if ( statusCode is ErrorCodes . ERROR_SUCCESS )
357+ {
358+ return true ;
359+ }
360+
361+ if ( statusCode is ErrorCodes . ERROR_MORE_DATA or ErrorCodes . ERROR_INSUFFICIENT_BUFFER )
362+ {
363+ return false ;
364+ }
365+ }
366+
367+ Log . QueryRequestPropertyError ( Logger , requestId , statusCode ) ;
368+ throw new HttpSysException ( ( int ) statusCode ) ;
369+ }
370+
315371 internal unsafe HTTP_REQUEST_PROPERTY_SNI GetClientSni ( )
316372 {
317373 if ( ! HttpApi . HttpGetRequestPropertySupported )
0 commit comments