Response Headers
HttpBuildR provides a set of methods to modify the headers of an HttpResponseMessage object in a fluent manner.
WithHeader Method
The WithHeader method adds a header to the response.
Usage:
HttpResponseMessage response = new HttpResponseMessage();
response = response.WithHeader("headerName", "headerValue");
| Name | Value |
|---|---|
| headerName | headerValue |
WithAge Method
The WithAge method adds an Age header to the response.
Usage:
HttpResponseMessage response = new HttpResponseMessage();
response = response.WithAge(TimeSpan.FromMinutes(5));
| Name | Value |
|---|---|
| Age | 300 |
WithETag Method
The WithETag method adds an ETag header to the response.
Usage:
HttpResponseMessage response = new HttpResponseMessage();
response = response.WithETag(new EntityTagHeaderValue("\"tag\""));
| Name | Value |
|---|---|
| ETag | "tag" |
WithLocation Method
The WithLocation method adds a Location header to the response.
Usage:
HttpResponseMessage response = new HttpResponseMessage();
response = response.WithLocation(new Uri("https://example.com"));
| Name | Value |
|---|---|
| Location | https://example.com/ |
WithRetryAfter Method
The WithRetryAfter method adds a Retry-After header to the response.
Usage:
HttpResponseMessage response = new HttpResponseMessage();
response = response.WithRetryAfter(
new DateTimeOffset(2021, 1, 1, 0, 0, 0, TimeSpan.Zero).AddHours(1)
);
| Name | Value |
|---|---|
| Retry-After | Fri, 01 Jan 2021 01:00:00 GMT |
WithCacheControl Method
The WithCacheControl method adds a Cache-Control header to the response.
Usage:
HttpResponseMessage response = new HttpResponseMessage();
response = response.WithCacheControl(
new CacheControlHeaderValue { MaxAge = TimeSpan.FromHours(2) }
);
| Name | Value |
|---|---|
| Cache-Control | max-age=7200 |
WithConnectionClose Method
The WithConnectionClose method adds a Connection-Close header to the response.
Usage:
HttpResponseMessage response = new HttpResponseMessage();
response = response.WithConnectionClose(true);
| Name | Value |
|---|---|
| Connection | close |
WithDate Method
The WithDate method adds a Date header to the response.
Usage:
HttpResponseMessage response = new HttpResponseMessage();
response = response.WithDate(new DateTimeOffset(2021, 1, 1, 0, 0, 0, TimeSpan.Zero));
| Name | Value |
|---|---|
| Date | Fri, 01 Jan 2021 00:00:00 GMT |
WithTransferEncodingChunked Method
The WithTransferEncodingChunked method adds a Transfer-Encoding header to the response.
Usage:
HttpResponseMessage response = new HttpResponseMessage();
response = response.WithTransferEncodingChunked(true);
| Name | Value |
|---|---|
| Transfer-Encoding | chunked |