Interface IRequestContext
An abstraction used by Handler implementations to hide the details of the underlying HTTP server framework.
Namespace: LaunchDarkly.TestHelpers.HttpTest
Assembly: LaunchDarkly.TestHelpers.dll
Syntax
public interface IRequestContext
Properties
CancellationToken
A CancellationToken that will be cancelled if the client closes the request or if the server is stopped.
Declaration
CancellationToken CancellationToken { get; }
Property Value
Type | Description |
---|---|
System.Threading.CancellationToken |
RequestInfo
The properties of the request.
Declaration
RequestInfo RequestInfo { get; }
Property Value
Type | Description |
---|---|
RequestInfo |
Methods
AddHeader(String, String)
Adds a response header, allowing multiple values.
Declaration
void AddHeader(string name, string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | the case-insensitive header name |
System.String | value | the header value |
GetPathParam(Int32)
Returns a path parameter, if any path parameters were captured.
Declaration
string GetPathParam(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | a zero-based index |
Returns
Type | Description |
---|---|
System.String | the path parameter string; null if there were no path parameters, or if the index is out of range |
Remarks
By default, this will always return null. It is non-null only if you used SimpleRouter and matched a regex pattern that was added with AddRegex(HttpMethod, String, Handler), and the pattern contained capture groups. For instance, if the pattern was
/a/([^/]*)/c/(.*)
and the request path was /a/b/c/d/e
,
GetPathParam(0)
would return "b"
and
GetPathParam(1)
would return "d/e"
.
SetHeader(String, String)
Sets a response header.
Declaration
void SetHeader(string name, string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | the case-insensitive header name |
System.String | value | the header value |
SetStatus(Int32)
Sets the response status.
Declaration
void SetStatus(int statusCode)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | statusCode | the HTTP status |
Remarks
This should be done before sending body content; otherwise the result is undefined.
WithPathParams(String[])
Returns a copy of this context with path parameter information added.
Declaration
IRequestContext WithPathParams(string[] pathParams)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | pathParams | an array of positional parameters |
Returns
Type | Description |
---|---|
IRequestContext | a transformed context |
WriteChunkedDataAsync(Byte[])
Writes a chunk of data in a chunked response.
Declaration
Task WriteChunkedDataAsync(byte[] data)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | the data to write; if null or zero-length, it will only turn on chunked mode and not write any data |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | an asynchronous task |
Remarks
Currently, this is only available in .NET Standard-compatible platforms. The
WireMock.Net
implementation that is used in .NET Framework 4.5.x does not
support streaming responses.
If non-chunked data has already been written with WriteFullResponseAsync(String, Byte[]), the result is undefined.
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | if called in .NET Framework 4.5.x |
WriteFullResponseAsync(String, Byte[])
Writes a complete response body.
Declaration
Task WriteFullResponseAsync(string contentType, byte[] data)
Parameters
Type | Name | Description |
---|---|---|
System.String | contentType | the Content-Type header value |
System.Byte[] | data | the data |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | an asynchronous task |
Remarks
This can only be called once per response. If chunked data has already been written with WriteChunkedDataAsync(Byte[]), the result is undefined.