3
3
4
4
using System ;
5
5
using System . IO ;
6
- using System . IO . Pipelines ;
7
6
using System . Threading . Tasks ;
8
- using Microsoft . AspNetCore . Connections ;
9
7
using Microsoft . AspNetCore . Connections . Features ;
8
+ using Microsoft . AspNetCore . Http ;
10
9
using Microsoft . AspNetCore . Http . Features ;
11
10
using Microsoft . AspNetCore . Server . Kestrel . Core ;
12
11
using Microsoft . AspNetCore . Server . Kestrel . Core . Internal . Infrastructure ;
13
12
using Microsoft . AspNetCore . Server . Kestrel . InMemory . FunctionalTests . TestTransport ;
14
13
using Microsoft . AspNetCore . Server . Kestrel . Tests ;
15
14
using Microsoft . AspNetCore . Testing ;
16
15
using Microsoft . Extensions . Logging . Testing ;
16
+ using Microsoft . Net . Http . Headers ;
17
17
using Xunit ;
18
18
19
19
namespace Microsoft . AspNetCore . Server . Kestrel . InMemory . FunctionalTests
@@ -154,9 +154,24 @@ await connection.Receive("HTTP/1.1 101 Switching Protocols",
154
154
}
155
155
156
156
[ Fact ]
157
- public async Task RejectsRequestWithContentLengthAndUpgrade ( )
157
+ public async Task AcceptsRequestWithContentLengthAndUpgrade ( )
158
158
{
159
- await using ( var server = new TestServer ( context => Task . CompletedTask , new TestServiceContext ( LoggerFactory ) ) )
159
+ await using ( var server = new TestServer ( async context =>
160
+ {
161
+ var feature = context . Features . Get < IHttpUpgradeFeature > ( ) ;
162
+
163
+ if ( HttpMethods . IsPost ( context . Request . Method ) )
164
+ {
165
+ Assert . False ( feature . IsUpgradableRequest ) ;
166
+ Assert . Equal ( 1 , context . Request . ContentLength ) ;
167
+ Assert . Equal ( 1 , await context . Request . Body . ReadAsync ( new byte [ 10 ] , 0 , 10 ) ) ;
168
+ }
169
+ else
170
+ {
171
+ Assert . True ( feature . IsUpgradableRequest ) ;
172
+ }
173
+ } ,
174
+ new TestServiceContext ( LoggerFactory ) ) )
160
175
{
161
176
using ( var connection = server . CreateConnection ( ) )
162
177
{
@@ -165,23 +180,28 @@ await connection.Send("POST / HTTP/1.1",
165
180
"Content-Length: 1" ,
166
181
"Connection: Upgrade" ,
167
182
"" ,
168
- "" ) ;
183
+ "A " ) ;
169
184
170
- await connection . ReceiveEnd (
171
- "HTTP/1.1 400 Bad Request" ,
172
- "Connection: close" ,
173
- $ "Date: { server . Context . DateHeaderValue } ",
174
- "Content-Length: 0" ,
175
- "" ,
176
- "" ) ;
185
+ await connection . Receive ( "HTTP/1.1 200 OK" ) ;
177
186
}
178
187
}
179
188
}
180
189
181
190
[ Fact ]
182
191
public async Task AcceptsRequestWithNoContentLengthAndUpgrade ( )
183
192
{
184
- await using ( var server = new TestServer ( context => Task . CompletedTask , new TestServiceContext ( LoggerFactory ) ) )
193
+ await using ( var server = new TestServer ( async context =>
194
+ {
195
+ var feature = context . Features . Get < IHttpUpgradeFeature > ( ) ;
196
+ Assert . True ( feature . IsUpgradableRequest ) ;
197
+
198
+ if ( HttpMethods . IsPost ( context . Request . Method ) )
199
+ {
200
+ Assert . Equal ( 0 , context . Request . ContentLength ) ;
201
+ }
202
+ Assert . Equal ( 0 , await context . Request . Body . ReadAsync ( new byte [ 10 ] , 0 , 10 ) ) ;
203
+ } ,
204
+ new TestServiceContext ( LoggerFactory ) ) )
185
205
{
186
206
using ( var connection = server . CreateConnection ( ) )
187
207
{
@@ -203,9 +223,26 @@ await connection.Send("POST / HTTP/1.1",
203
223
}
204
224
205
225
[ Fact ]
206
- public async Task RejectsRequestWithChunkedEncodingAndUpgrade ( )
226
+ public async Task AcceptsRequestWithChunkedEncodingAndUpgrade ( )
207
227
{
208
- await using ( var server = new TestServer ( context => Task . CompletedTask , new TestServiceContext ( LoggerFactory ) ) )
228
+ await using ( var server = new TestServer ( async context =>
229
+ {
230
+ var feature = context . Features . Get < IHttpUpgradeFeature > ( ) ;
231
+
232
+ Assert . Null ( context . Request . ContentLength ) ;
233
+
234
+ if ( HttpMethods . IsPost ( context . Request . Method ) )
235
+ {
236
+ Assert . False ( feature . IsUpgradableRequest ) ;
237
+ Assert . Equal ( "chunked" , context . Request . Headers [ HeaderNames . TransferEncoding ] ) ;
238
+ Assert . Equal ( 11 , await context . Request . Body . ReadAsync ( new byte [ 12 ] , 0 , 12 ) ) ;
239
+ }
240
+ else
241
+ {
242
+ Assert . True ( feature . IsUpgradableRequest ) ;
243
+ }
244
+ } ,
245
+ new TestServiceContext ( LoggerFactory ) ) )
209
246
{
210
247
using ( var connection = server . CreateConnection ( ) )
211
248
{
@@ -214,14 +251,11 @@ await connection.Send("POST / HTTP/1.1",
214
251
"Transfer-Encoding: chunked" ,
215
252
"Connection: Upgrade" ,
216
253
"" ,
217
- "" ) ;
218
- await connection . ReceiveEnd (
219
- "HTTP/1.1 400 Bad Request" ,
220
- "Connection: close" ,
221
- $ "Date: { server . Context . DateHeaderValue } ",
222
- "Content-Length: 0" ,
254
+ "B" , "Hello World" ,
255
+ "0" ,
223
256
"" ,
224
257
"" ) ;
258
+ await connection . Receive ( "HTTP/1.1 200 OK" ) ;
225
259
}
226
260
}
227
261
}
0 commit comments