Provides extension methods for types implementing IHttpContext.
InheritanceHttpContextExtensions
Namespace: EmbedIO Syntaxpublic static class HttpContextExtensions
Methods GetImplementation(IHttpContext)
Gets the underlying IHttpContextImpl interface of an IHttpContext.
This API mainly supports the EmbedIO infrastructure; it is not intended to be used directly from your code, unless to fulfill very specific needs in the development of plug-ins (modules, etc.) for EmbedIO.
Declarationpublic static IHttpContextImpl GetImplementation(this IHttpContext this)
Parameters Returns GetItem<T>(IHttpContext, Object)
Gets the item associated with the specified key.
Declarationpublic static T GetItem<T>(this IHttpContext this, object key)
Parameters Returns Type Description T
The item associated with the specified key, if the key is found in Items and the associated value is of type T
; otherwise, the default value for T
.
The desired type of the item.
GetRequestBodyAsByteArrayAsync(IHttpContext)Asynchronously retrieves the request body as an array of langword_csharp_bytes.
Declarationpublic static Task<byte[]> GetRequestBodyAsByteArrayAsync(this IHttpContext this)
Parameters Returns Type Description Task<Byte[]>
A Task , representing the ongoing operation, whose result will be an array of Bytes containing the request body.
GetRequestBodyAsMemoryStreamAsync(IHttpContext)Asynchronously buffers the request body into a read-only .
Declarationpublic static Task<MemoryStream> GetRequestBodyAsMemoryStreamAsync(this IHttpContext this)
Parameters Returns Type Description Task<MemoryStream>
A Task , representing the ongoing operation, whose result will be a read-only containing the request body.
GetRequestBodyAsStringAsync(IHttpContext)Asynchronously retrieves the request body as a string.
Declarationpublic static Task<string> GetRequestBodyAsStringAsync(this IHttpContext this)
Parameters Returns Type Description Task<String>
A Task , representing the ongoing operation, whose result will be a langword_csharp_string representation of the request body.
GetRequestDataAsync<TData>(IHttpContext)Asynchronously deserializes a request body, using the default request deserializer.
As of EmbedIO version 3.0, the default response serializer has the same behavior of JSON request parsing methods of version 2.
Declarationpublic static Task<TData> GetRequestDataAsync<TData>(this IHttpContext this)
Parameters Returns Type Description Task<TData>
A Task , representing the ongoing operation, whose result will be the deserialized data.
Type Parameters Name Description TDataThe expected type of the deserialized data.
GetRequestDataAsync<TData>(IHttpContext, RequestDeserializerCallback<TData>)Asynchronously deserializes a request body, using the specified request deserializer.
Declarationpublic static Task<TData> GetRequestDataAsync<TData>(this IHttpContext this, RequestDeserializerCallback<TData> deserializer)
Parameters Returns Type Description Task<TData>
A Task , representing the ongoing operation, whose result will be the deserialized data.
Type Parameters Name Description TDataThe expected type of the deserialized data.
GetRequestFormDataAsync(IHttpContext)Asynchronously parses a request body in application/x-www-form-urlencoded
format.
public static Task<NameValueCollection> GetRequestFormDataAsync(this IHttpContext this)
Parameters Returns Type Description Task<NameValueCollection>
A Task , representing the ongoing operation, whose result will be a read-only of form field names and values.
GetRequestQueryData(IHttpContext)Parses a request URL query. Note that this is different from getting the QueryString property, in that fields without an equal sign are treated as if they have an empty value, instead of their keys being grouped as values of the null
key.
public static NameValueCollection GetRequestQueryData(this IHttpContext this)
Parameters Returns Type Description NameValueCollection
A read-only .
OpenRequestStream(IHttpContext)Wraps the request input stream and returns a that can be used directly.
Decompression of compressed request bodies is implemented if specified in the web server's options.
Declarationpublic static Stream OpenRequestStream(this IHttpContext this)
Parameters Returns Type Description Stream
A that can be used to write response data.
This stream MUST be disposed when finished writing.
See Also OpenRequestText(IHttpContext)Wraps the request input stream and returns a that can be used directly.
Decompression of compressed request bodies is implemented if specified in the web server's options.
If the request does not specify a content encoding, UTF-8 is used by default.
Declarationpublic static TextReader OpenRequestText(this IHttpContext this)
Parameters Returns Type Description TextReader
A that can be used to read the request body as text.
This reader MUST be disposed when finished reading.
See Also OpenResponseStream(IHttpContext, Boolean, Boolean)Wraps the response output stream and returns a that can be used directly.
Optional buffering is applied, so that the response may be sent as one (thereby properly setting the Content-Length
header) instead of using chunked transfer.
Proactive negotiation is performed to select the best compression method supported by the client.
Declarationpublic static Stream OpenResponseStream(this IHttpContext this, bool buffered = false, bool preferCompression = true)
Parameters Type Name Description IHttpContext this
The IHttpContext on which this method is called.
Boolean bufferedIf set to true, the data to send will be collected in memory and sent all at once when the returned is disposed, setting the Content-Length
response header; if set to false (the default), chunked transfer will be used.
true if sending compressed data is preferred over sending non-compressed data; otherwise, false.
Returns Type Description StreamA that can be used to write response data.
This stream MUST be disposed when finished writing.
See Also OpenResponseText(IHttpContext, Nullable<Encoding>, Boolean, Boolean)Wraps the response output stream and returns a that can be used directly.
Optional buffering is applied, so that the response may be sent as one (thereby properly setting the Content-Length
header) instead of using chunked transfer.
Proactive negotiation is performed to select the best compression method supported by the client.
Declarationpublic static TextWriter OpenResponseText(this IHttpContext this, Encoding? encoding = default(Encoding? ), bool buffered = false, bool preferCompression = true)
Parameters Type Name Description IHttpContext this
The IHttpContext on which this method is called.
Nullable<Encoding> encodingThe to use to convert text to data bytes. By default, UTF-8 is used.
Boolean bufferedIf set to true, sent data is collected in a and sent all at once when the returned is disposed; if set to false (the default), chunked transfer will be used.
Boolean preferCompressiontrue if sending compressed data is preferred over sending non-compressed data; otherwise, false.
Returns Type Description TextWriterA that can be used to write response data.
This writer MUST be disposed when finished writing.
See Also Redirect(IHttpContext, String, Int32)Sets a redirection status code and adds a Location
header to the response.
public static void Redirect(this IHttpContext this, string location, int statusCode = default(int))
Parameters Type Name Description IHttpContext this
The IHttpContext interface on which this method is called.
String locationThe URL to which the user agent should be redirected.
Int32 statusCodeThe status code to set on the response.
SendDataAsync(IHttpContext, ResponseSerializerCallback, Object)Asynchronously sends serialized data as a response, using the specified response serializer.
As of EmbedIO version 3.0, the default response serializer has the same behavior of JSON response methods of version 2.
Declarationpublic static Task SendDataAsync(this IHttpContext this, ResponseSerializerCallback serializer, object data)
Parameters Returns Type Description Task
A representing the ongoing operation.
See Also SendDataAsync(IHttpContext, Object)Asynchronously sends serialized data as a response, using the default response serializer.
As of EmbedIO version 3.0, the default response serializer has the same behavior of JSON response methods of version 2.
Declarationpublic static Task SendDataAsync(this IHttpContext this, object data)
Parameters Returns Type Description Task
A representing the ongoing operation.
See Also SendStandardHtmlAsync(IHttpContext, Int32)Asynchronously sends a standard HTML response for the specified status code.
Declarationpublic static Task SendStandardHtmlAsync(this IHttpContext this, int statusCode)
Parameters Type Name Description IHttpContext this
The IHttpContext interface on which this method is called.
Int32 statusCodeThe HTTP status code of the response.
Returns Type Description TaskA representing the ongoing operation.
SendStandardHtmlAsync(IHttpContext, Int32, Nullable<Action<TextWriter>>)Asynchronously sends a standard HTML response for the specified status code.
Declarationpublic static Task SendStandardHtmlAsync(this IHttpContext this, int statusCode, Action<TextWriter>? writeAdditionalHtml)
Parameters Type Name Description IHttpContext this
The IHttpContext interface on which this method is called.
Int32 statusCodeThe HTTP status code of the response.
Nullable<Action<TextWriter>> writeAdditionalHtmlA callback function that may write additional HTML code to a representing the response output. If not null, the callback is called immediately before closing the HTML body
tag.
A representing the ongoing operation.
See Also SendStringAsync(IHttpContext, String, String, Encoding)Asynchronously sends a string as response.
Declarationpublic static Task SendStringAsync(this IHttpContext this, string content, string contentType, Encoding encoding)
Parameters Type Name Description IHttpContext this
The IHttpResponse interface on which this method is called.
String contentThe response content.
String contentTypeThe MIME type of the content. If null, the content type will not be set.
Encoding encodingThe to use.
Returns Type Description TaskA representing the ongoing operation.
TryGetItem<T>(IHttpContext, Object, out T)Gets the item associated with the specified key.
Declarationpublic static bool TryGetItem<T>(this IHttpContext this, object key, out T value)
Parameters Type Name Description IHttpContext this
The IHttpContext on which this method is called.
Object keyThe key whose value to get from the Items dictionary.
T valueWhen this method returns, the item associated with the specified key, if the key is found in Items and the associated value is of type T
; otherwise, the default value for T
.
This parameter is passed uninitialized.
Returns Type Description Booleantrue if the item is found and is of type T
; otherwise, false.
The desired type of the item.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4