forked from aspnet/AspNetWebStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOwinBufferPolicySelector.cs
More file actions
58 lines (50 loc) · 1.88 KB
/
Copy pathOwinBufferPolicySelector.cs
File metadata and controls
58 lines (50 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Net.Http;
using System.Web.Http.Hosting;
namespace System.Web.Http.Owin
{
/// <summary>
/// Provides the default implementation of <see cref="IHostBufferPolicySelector"/> used by the OWIN Web API adapter.
/// </summary>
public class OwinBufferPolicySelector : IHostBufferPolicySelector
{
/// <inheritdoc />
public bool UseBufferedInputStream(object hostContext)
{
return false;
}
/// <inheritdoc />
public bool UseBufferedOutputStream(HttpResponseMessage response)
{
if (response == null)
{
throw Error.ArgumentNull("response");
}
HttpContent content = response.Content;
if (content == null)
{
return false;
}
// Any HttpContent that knows its length is presumably already buffered internally.
long? contentLength = content.Headers.ContentLength;
if (contentLength.HasValue && contentLength.Value >= 0)
{
return false;
}
// If the response is meant to use chunked transfer encoding, don't buffer.
bool? transferEncodingChunked = response.Headers.TransferEncodingChunked;
if (transferEncodingChunked.HasValue && transferEncodingChunked.Value)
{
return false;
}
// Content length is null or -1 (meaning not known).
// Buffer any HttpContent except StreamContent and PushStreamContent
if (content is StreamContent || content is PushStreamContent)
{
return false;
}
return true;
}
}
}