36 private static readonly
int[]
s_noResponseBody =
new int[5] { 100, 101, 204, 205, 304 };
54 foreach (
string name
in allKeys)
67 return Headers[
"Content-Type"];
72 if (
string.IsNullOrEmpty(
value))
74 Headers.Remove(
"Content-Type");
78 Headers.Set(
"Content-Type",
value);
185 if (
string.IsNullOrEmpty(
value))
187 Headers.Remove(
"Location");
191 Headers.Set(
"Location",
value);
217 for (
int i = 0; i <
value.Length; i++)
220 if ((c <=
'\u001f' && c !=
'\t') || c ==
'\u007f')
242 _nativeResponse.StatusCode = (ushort)
value;
263 _nativeResponse.Version.MajorVersion = (ushort)
value.Major;
264 _nativeResponse.Version.MinorVersion = (ushort)
value.Minor;
294 Headers.Set(name,
value);
303 Headers.Add(name,
value);
339 if (
cookie.IsRfc2965Variant())
349 if (!
string.IsNullOrEmpty(
text2))
351 Headers.Set(
"Set-Cookie",
text2);
352 if (
string.IsNullOrEmpty(
text))
354 Headers.
Remove(
"Set-Cookie2");
357 if (!
string.IsNullOrEmpty(
text))
359 Headers.Set(
"Set-Cookie2",
text);
360 if (
string.IsNullOrEmpty(
text2))
362 Headers.Remove(
"Set-Cookie");
429 _nativeResponse.StatusCode = 200;
430 _nativeResponse.Version.MajorVersion = 1;
431 _nativeResponse.Version.MinorVersion = 1;
457 _nativeResponse.Version.MajorVersion =
templateResponse._nativeResponse.Version.MajorVersion;
458 _nativeResponse.Version.MinorVersion =
templateResponse._nativeResponse.Version.MinorVersion;
490 System.
Net.
NetEventSource.
Info(
this,
$"ResponseState:{_responseState}, BoundaryType:{_boundaryType}, ContentLength:{_contentLength}",
"Close");
567 for (
int i = 0; i < Headers.Count; i++)
587 _nativeResponse.EntityChunkCount = 1;
592 _nativeResponse.EntityChunkCount =
asyncResult.dataChunkCount;
593 _nativeResponse.pEntityChunks =
asyncResult.pDataChunks;
597 _nativeResponse.EntityChunkCount = 0;
598 _nativeResponse.pEntityChunks =
null;
610 _nativeResponse.ReasonLength = (ushort)
array.Length;
612 _nativeResponse.pReason = (sbyte*)pReason;
648 global::Interop.HttpApi.HTTP_FLAGS
hTTP_FLAGS = global::Interop.HttpApi.HTTP_FLAGS.NONE;
657 System.
Net.
NetEventSource.
Info(
this,
$"flags: {hTTP_FLAGS} _boundaryType: {_boundaryType} _contentLength: {_contentLength} _keepAlive: {_keepAlive}",
"ComputeHeaders");
680 System.
Net.
NetEventSource.
Info(
this,
$"flags:{hTTP_FLAGS} _BoundaryType:{_boundaryType} _contentLength:{_contentLength} _keepAlive: {_keepAlive}",
"ComputeHeaders");
687 hTTP_FLAGS = global::Interop.HttpApi.HTTP_FLAGS.NONE;
696 hTTP_FLAGS = global::Interop.HttpApi.HTTP_FLAGS.NONE;
705 if (
hTTP_FLAGS == global::Interop.HttpApi.HTTP_FLAGS.NONE)
707 hTTP_FLAGS = global::Interop.HttpApi.HTTP_FLAGS.HTTP_RECEIVE_REQUEST_FLAG_COPY_BODY;
716 System.
Net.
NetEventSource.
Info(
this,
$"flags:{hTTP_FLAGS} _BoundaryType:{_boundaryType} _contentLength:{_contentLength} _keepAlive: {_keepAlive}",
"ComputeHeaders");
732 global::Interop.HttpApi.HTTP_UNKNOWN_HEADER[]
array =
null;
737 if (Headers.Count == 0)
744 for (
int i = 0; i < Headers.Count; i++)
746 string key = Headers.GetKey(i);
747 int num2 = global::Interop.HttpApi.HTTP_RESPONSE_HEADER_ID.IndexOfKnownHeader(
key);
754 string[]
values = Headers.GetValues(i);
760 fixed (global::Interop.HttpApi.HTTP_KNOWN_HEADER*
ptr = &
headers.KnownHeaders)
762 for (
int j = 0;
j < Headers.
Count;
j++)
764 string key = Headers.GetKey(
j);
765 string text = Headers.Get(
j);
766 int num2 = global::Interop.HttpApi.HTTP_RESPONSE_HEADER_ID.IndexOfKnownHeader(
key);
773 System.
Net.
NetEventSource.
Info(
this,
$"index={j},headers.count={Headers.Count},headerName:{key},lookup:{num2} headerValue:{text}",
"SerializeHeaders");
779 array =
new global::Interop.HttpApi.HTTP_UNKNOWN_HEADER[num];
782 headers.pUnknownHeaders = (global::Interop.HttpApi.HTTP_UNKNOWN_HEADER*)(
void*)
item.AddrOfPinnedObject();
784 string[]
values2 = Headers.GetValues(
j);
792 array[
headers.UnknownHeaderCount].pName = (sbyte*)(
void*)
item.AddrOfPinnedObject();
799 array[
headers.UnknownHeaderCount].pRawValue = (sbyte*)(
void*)
item.AddrOfPinnedObject();
819 ptr[
num2].pRawValue = (sbyte*)(
void*)
item.AddrOfPinnedObject();
822 System.
Net.
NetEventSource.
Info(
this,
$"pRawValue:{(IntPtr)ptr[num2].pRawValue} RawValueLength:{ptr[num2].RawValueLength} lookup: {num2}",
"SerializeHeaders");
static readonly Microsoft.Win32.SafeHandles.SafeLocalAllocHandle Zero
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
int InternalAdd(Cookie cookie, bool isStrict)
HttpListenerResponse Response
string? MutualAuthentication
void SetAuthenticationHeaders()
SafeHandle RequestQueueHandle
HttpListenerRequest Request
void CopyFrom(HttpListenerResponse templateResponse)
Encoding? ContentEncoding
static bool CanSendResponseBody(int responseCode)
ResponseState _responseState
void FreePinnedHeaders(List< GCHandle > pinnedHeaders)
void EnsureResponseStream()
void NonBlockingCloseCallback(IAsyncResult asyncResult)
void IDisposable. Dispose()
readonly HttpListenerContext _httpContext
string _statusDescription
BoundaryType _boundaryType
CookieCollection _cookies
void Close(byte[] responseEntity, bool willBlock)
global::Interop.HttpApi.HTTP_FLAGS ComputeHeaders()
void Redirect(string url)
void AddHeader(string name, string value)
void ComputeCoreHeaders()
WebHeaderCollection _webHeaders
HttpResponseStream _responseStream
HttpListenerResponse(HttpListenerContext httpContext)
void AppendCookie(Cookie cookie)
void AppendHeader(string name, string value)
global::Interop.HttpApi.HTTP_RESPONSE _nativeResponse
void CancelLastWrite(SafeHandle requestQueueHandle)
BoundaryType BoundaryType
unsafe uint SendHeaders(global::Interop.HttpApi.HTTP_DATA_CHUNK *pDataChunk, HttpResponseStreamAsyncResult asyncResult, global::Interop.HttpApi.HTTP_FLAGS flags, bool isWebSocketHandshake)
unsafe List< GCHandle > SerializeHeaders(ref global::Interop.HttpApi.HTTP_RESPONSE_HEADERS headers, bool isWebSocketHandshake)
static readonly int[] s_noResponseBody
void SetCookie(Cookie cookie)
static readonly bool SkipIOCPCallbackOnSuccess
override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
override void Write(byte[] buffer, int offset, int count)
unsafe void CancelLastWrite(SafeHandle requestQueueHandle)
override void EndWrite(IAsyncResult asyncResult)
static string Get(HttpStatusCode code)
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
static void Associate(object first, object second, [CallerMemberName] string memberName=null)
static string net_invalidstatus
static string net_cookie_exists
static string net_clsmall
static string net_rspsubmitted
static string net_WebHeaderInvalidControlChars
static string net_nochunkuploadonhttp10
static string net_wrongversion
static GCHandle Alloc(object? value)