Skip to content

Commit dcca94f

Browse files
author
FERNAN OVIEDO CANDELARESI
committed
Add remark about timeout scope on HttpCompletionOptions enum
1 parent bc434e6 commit dcca94f

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

xml/System.Net.Http/HttpCompletionOption.xml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,27 @@
3636
</Base>
3737
<Docs>
3838
<summary>Indicates if <see cref="T:System.Net.Http.HttpClient" /> operations should be considered completed either as soon as a response is available, or after reading the entire response message including the content.</summary>
39-
<remarks>To be added.</remarks>
39+
<remarks>
40+
<format type="text/markdown"><![CDATA[
41+
42+
## Remarks
43+
The <xref:HttpCompletionOption> value effectively affects the scope of the timeout specified in the <see cref="T:System.Net.Http.HttpClient" /> operation options when reading a response. The timeout on the <see cref="T:System.Net.Http.HttpClient" /> always applies on the relevant invoked methods up until the point where those methods complete/return. Crucially, when using the <see cref="F:System.Net.Http.HttpCompletionOptions.ResponseHeadersRead" /> option, the timeout applies only up to where the headers end and the content starts. The content reading operation needs to be timed out separately. Below is an example illustrating this point:
44+
45+
```csharp
46+
var httpClient = new HttpClient();
47+
httpClient.Timeout = TimeSpan.FromSeconds(30);
48+
using (var response = await httpClient.GetAsync("http://localhost:12345/", HttpCompletionOption.ResponseHeadersRead)) // 30-second timeout but ONLY up until past the headers
49+
{
50+
// Do other stuff that doesn't rely on the content first, like status code validation
51+
// ...
52+
53+
var content = await response.Content.ReadAsStringAsync(); // NO TIMEOUT
54+
}
55+
```
56+
57+
]]>
58+
</format>
59+
</remarks>
4060
</Docs>
4161
<Members>
4262
<Member MemberName="ResponseContentRead">

0 commit comments

Comments
 (0)