5
5
using System . Text ;
6
6
using System . Threading ;
7
7
using System . Threading . Tasks ;
8
+ using Microsoft . AspNetCore . Http ;
8
9
using Microsoft . AspNetCore . Testing ;
9
10
using Xunit ;
10
11
@@ -67,9 +68,8 @@ public async Task ResponsesAreNotChunkedAutomaticallyForHttp10Requests(TestServi
67
68
{
68
69
using ( var server = new TestServer ( async httpContext =>
69
70
{
70
- var response = httpContext . Response ;
71
- await response . Body . WriteAsync ( Encoding . ASCII . GetBytes ( "Hello " ) , 0 , 6 ) ;
72
- await response . Body . WriteAsync ( Encoding . ASCII . GetBytes ( "World!" ) , 0 , 6 ) ;
71
+ await httpContext . Response . WriteAsync ( "Hello " ) ;
72
+ await httpContext . Response . WriteAsync ( "World!" ) ;
73
73
} , testContext ) )
74
74
{
75
75
using ( var connection = server . CreateConnection ( ) )
@@ -89,13 +89,14 @@ await connection.ReceiveEnd(
89
89
}
90
90
}
91
91
92
- public async Task ResponsesAreNotChunkedAutomaticallyForHttp11NonKeepAliveRequests ( TestServiceContext testContext )
92
+ [ Theory ]
93
+ [ MemberData ( nameof ( ConnectionFilterData ) ) ]
94
+ public async Task ResponsesAreChunkedAutomaticallyForHttp11NonKeepAliveRequests ( TestServiceContext testContext )
93
95
{
94
96
using ( var server = new TestServer ( async httpContext =>
95
97
{
96
- var response = httpContext . Response ;
97
- await response . Body . WriteAsync ( Encoding . ASCII . GetBytes ( "Hello " ) , 0 , 6 ) ;
98
- await response . Body . WriteAsync ( Encoding . ASCII . GetBytes ( "World!" ) , 0 , 6 ) ;
98
+ await httpContext . Response . WriteAsync ( "Hello " ) ;
99
+ await httpContext . Response . WriteAsync ( "World!" ) ;
99
100
} , testContext ) )
100
101
{
101
102
using ( var connection = server . CreateConnection ( ) )
@@ -109,22 +110,28 @@ await connection.ReceiveEnd(
109
110
"HTTP/1.1 200 OK" ,
110
111
"Connection: close" ,
111
112
$ "Date: { testContext . DateHeaderValue } ",
113
+ "Transfer-Encoding: chunked" ,
112
114
"" ,
113
- "Hello World!" ) ;
115
+ "6" ,
116
+ "Hello " ,
117
+ "6" ,
118
+ "World!" ,
119
+ "0" ,
120
+ "" ,
121
+ "" ) ;
114
122
}
115
123
}
116
124
}
117
125
118
126
[ Theory ]
119
127
[ MemberData ( nameof ( ConnectionFilterData ) ) ]
120
- public async Task SettingConnectionCloseHeaderInAppDisablesChunking ( TestServiceContext testContext )
128
+ public async Task SettingConnectionCloseHeaderInAppDoesNotDisableChunking ( TestServiceContext testContext )
121
129
{
122
130
using ( var server = new TestServer ( async httpContext =>
123
131
{
124
- var response = httpContext . Response ;
125
- response . Headers [ "Connection" ] = "close" ;
126
- await response . Body . WriteAsync ( Encoding . ASCII . GetBytes ( "Hello " ) , 0 , 6 ) ;
127
- await response . Body . WriteAsync ( Encoding . ASCII . GetBytes ( "World!" ) , 0 , 6 ) ;
132
+ httpContext . Response . Headers [ "Connection" ] = "close" ;
133
+ await httpContext . Response . WriteAsync ( "Hello " ) ;
134
+ await httpContext . Response . WriteAsync ( "World!" ) ;
128
135
} , testContext ) )
129
136
{
130
137
using ( var connection = server . CreateConnection ( ) )
@@ -137,8 +144,15 @@ await connection.ReceiveEnd(
137
144
"HTTP/1.1 200 OK" ,
138
145
"Connection: close" ,
139
146
$ "Date: { testContext . DateHeaderValue } ",
147
+ "Transfer-Encoding: chunked" ,
140
148
"" ,
141
- "Hello World!" ) ;
149
+ "6" ,
150
+ "Hello " ,
151
+ "6" ,
152
+ "World!" ,
153
+ "0" ,
154
+ "" ,
155
+ "" ) ;
142
156
}
143
157
}
144
158
}
0 commit comments