@@ -63,14 +63,13 @@ void main() {
63
63
});
64
64
65
65
test ('Request is populated correctly' , () async {
66
- var path = '/foo/bar?qs=value' ;
66
+ late Uri uri ;
67
67
68
68
await _scheduleServer ((request) {
69
69
expect (request.contentLength, 0 );
70
70
expect (request.method, 'GET' );
71
71
72
- var expectedUrl = 'http://localhost:$_serverPort $path ' ;
73
- expect (request.requestedUri, Uri .parse (expectedUrl));
72
+ expect (request.requestedUri, uri);
74
73
75
74
expect (request.url.path, 'foo/bar' );
76
75
expect (request.url.pathSegments, ['foo' , 'bar' ]);
@@ -81,7 +80,9 @@ void main() {
81
80
return syncHandler (request);
82
81
});
83
82
84
- var response = await http.get ('http://localhost:$_serverPort $path ' );
83
+ uri = Uri .http ('localhost:$_serverPort ' , '/foo/bar' , {'qs' : 'value' });
84
+ var response = await http.get (uri);
85
+
85
86
expect (response.statusCode, HttpStatus .ok);
86
87
expect (response.body, 'Hello from /foo/bar' );
87
88
});
@@ -108,8 +109,8 @@ void main() {
108
109
return Response .ok (null );
109
110
}));
110
111
111
- var request = http. StreamedRequest (
112
- 'POST' , Uri .parse ( 'http:// localhost:$_serverPort ' ));
112
+ var request =
113
+ http. StreamedRequest ( 'POST' , Uri .http ( ' localhost:$_serverPort ' , ' ' ));
113
114
request.sink.add ([1 , 2 , 3 , 4 ]);
114
115
request.sink.close ();
115
116
@@ -256,7 +257,7 @@ void main() {
256
257
return syncHandler (request);
257
258
}, 'localhost' , 0 );
258
259
259
- var response = await http.get (' http:// localhost:${server .port }' );
260
+ var response = await http.get (Uri . http ( ' localhost:${server .port }', '/' ) );
260
261
expect (response.statusCode, HttpStatus .ok);
261
262
expect (response.body, 'Hello from /' );
262
263
await server.close ();
@@ -273,7 +274,7 @@ void main() {
273
274
}, 'localhost' , 0 );
274
275
275
276
try {
276
- return await http.get (' http:// localhost:${server .port }' );
277
+ return await http.get (Uri . http ( ' localhost:${server .port }', '/' ) );
277
278
} finally {
278
279
await server.close ();
279
280
}
@@ -472,8 +473,7 @@ void main() {
472
473
context: {'shelf.io.buffer_output' : false });
473
474
});
474
475
475
- var request =
476
- http.Request ('GET' , Uri .parse ('http://localhost:$_serverPort /' ));
476
+ var request = http.Request ('GET' , Uri .http ('localhost:$_serverPort ' , '' ));
477
477
478
478
var response = await request.send ();
479
479
var stream = StreamQueue (utf8.decoder.bind (response.stream));
@@ -516,7 +516,7 @@ void main() {
516
516
var sslClient = HttpClient (context: securityContext);
517
517
518
518
Future <HttpClientRequest > _scheduleSecureGet () =>
519
- sslClient.getUrl (Uri .parse ( 'https:// localhost:${_server !.port }/ ' ));
519
+ sslClient.getUrl (Uri .https ( ' localhost:${_server !.port }' , ' ' ));
520
520
521
521
test ('secure sync handler returns a value to the client' , () async {
522
522
await _scheduleServer (syncHandler, securityContext: securityContext);
@@ -565,8 +565,7 @@ Future<http.Response> _get({
565
565
// TODO: use http.Client once it supports sending and receiving multiple headers.
566
566
final client = HttpClient ();
567
567
try {
568
- final rq =
569
- await client.getUrl (Uri .parse ('http://localhost:$_serverPort /$path ' ));
568
+ final rq = await client.getUrl (Uri .http ('localhost:$_serverPort ' , path));
570
569
headers? .forEach ((key, value) {
571
570
rq.headers.add (key, value);
572
571
});
@@ -587,8 +586,7 @@ Future<http.Response> _get({
587
586
588
587
Future <http.StreamedResponse > _post (
589
588
{Map <String , String >? headers, String ? body}) {
590
- var request =
591
- http.Request ('POST' , Uri .parse ('http://localhost:$_serverPort /' ));
589
+ var request = http.Request ('POST' , Uri .http ('localhost:$_serverPort ' , '' ));
592
590
593
591
if (headers != null ) request.headers.addAll (headers);
594
592
if (body != null ) request.body = body;
0 commit comments