Skip to content

Fixes #293, added property url to BaseResponse. #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/src/base_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ abstract class BaseRequest {
contentLength: response.contentLength,
request: response.request,
headers: response.headers,
url: response.url,
isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase);
Expand Down
4 changes: 4 additions & 0 deletions lib/src/base_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ abstract class BaseResponse {
// TODO(nweiz): make this a HttpHeaders object.
final Map<String, String> headers;

/// The url of the final response(possibly after redirections).
final String url;

final bool isRedirect;

/// Whether the server requested that a persistent connection be maintained.
Expand All @@ -37,6 +40,7 @@ abstract class BaseResponse {
{this.contentLength,
this.request,
this.headers = const {},
this.url,
this.isRedirect = false,
this.persistentConnection = true,
this.reasonPhrase}) {
Expand Down
1 change: 1 addition & 0 deletions lib/src/browser_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class BrowserClient extends BaseClient {
contentLength: body.length,
request: request,
headers: xhr.responseHeaders,
url: xhr.responseUrl,
reasonPhrase: xhr.statusText));
});

Expand Down
3 changes: 3 additions & 0 deletions lib/src/io_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class IOClient extends BaseClient {
response.contentLength == -1 ? null : response.contentLength,
request: request,
headers: headers,
url: response.redirects.isEmpty
? request.url.toString()
: response.redirects.last.location.toString(),
isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase);
Expand Down
5 changes: 5 additions & 0 deletions lib/src/response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ class Response extends BaseResponse {
Response(String body, int statusCode,
{BaseRequest request,
Map<String, String> headers = const {},
String url,
bool isRedirect = false,
bool persistentConnection = true,
String reasonPhrase})
: this.bytes(_encodingForHeaders(headers).encode(body), statusCode,
request: request,
headers: headers,
url: url,
isRedirect: isRedirect,
persistentConnection: persistentConnection,
reasonPhrase: reasonPhrase);
Expand All @@ -46,6 +48,7 @@ class Response extends BaseResponse {
Response.bytes(List<int> bodyBytes, int statusCode,
{BaseRequest request,
Map<String, String> headers = const {},
String url,
bool isRedirect = false,
bool persistentConnection = true,
String reasonPhrase})
Expand All @@ -54,6 +57,7 @@ class Response extends BaseResponse {
contentLength: bodyBytes.length,
request: request,
headers: headers,
url: url,
isRedirect: isRedirect,
persistentConnection: persistentConnection,
reasonPhrase: reasonPhrase);
Expand All @@ -65,6 +69,7 @@ class Response extends BaseResponse {
return Response.bytes(body, response.statusCode,
request: response.request,
headers: response.headers,
url: response.url,
isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
reasonPhrase: response.reasonPhrase);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/streamed_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class StreamedResponse extends BaseResponse {
{int contentLength,
BaseRequest request,
Map<String, String> headers = const {},
String url,
bool isRedirect = false,
bool persistentConnection = true,
String reasonPhrase})
Expand All @@ -32,6 +33,7 @@ class StreamedResponse extends BaseResponse {
contentLength: contentLength,
request: request,
headers: headers,
url: url,
isRedirect: isRedirect,
persistentConnection: persistentConnection,
reasonPhrase: reasonPhrase);
Expand Down
3 changes: 3 additions & 0 deletions test/io/request_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void main() {
final response = await request.send();

expect(response.statusCode, equals(200));
expect(response.url, equals(serverUrl.toString()));
final bytesString = await response.stream.bytesToString();
expect(
bytesString,
Expand All @@ -44,13 +45,15 @@ void main() {
final response = await request.send();

expect(response.statusCode, equals(302));
expect(response.url, equals(serverUrl.resolve('/redirect').toString()));
});

test('with redirects', () async {
final request = http.Request('GET', serverUrl.resolve('/redirect'));
final response = await request.send();

expect(response.statusCode, equals(200));
expect(response.url, equals(serverUrl.resolve('/').toString()));
final bytesString = await response.stream.bytesToString();
expect(bytesString, parse(containsPair('path', '/')));
});
Expand Down