Skip to content

Commit

Permalink
Adding back missing Request and Response fields
Browse files Browse the repository at this point in the history
  • Loading branch information
donny-dont committed Apr 14, 2017
1 parent e9dbebd commit 73cfddb
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 20 deletions.
118 changes: 100 additions & 18 deletions lib/src/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ class Request extends Message {
/// The URL to which the request will be sent.
final Uri url;

/// Whether a persistent connection should be maintained with the server.
/// Defaults to true.
final bool persistentConnection;

/// Whether the client should follow redirects while resolving this request.
/// Defaults to true.
final bool followRedirects;

/// The maximum number of redirects to follow when [followRedirects] is true.
/// If this number is exceeded the [Response] future will signal a
/// [RedirectException]. Defaults to 5.
final int maxRedirects;

/// Creates a new [Request] for [url], which can be a [Uri] or a [String],
/// using [method].
///
Expand All @@ -35,8 +48,12 @@ class Request extends Message {
{body,
Encoding encoding,
Map<String, String> headers,
Map<String, Object> context})
: this._(method, getUrl(url), body, encoding, headers, context);
Map<String, Object> context,
bool persistentConnection,
bool followRedirects,
int maxRedirects})
: this._(method, getUrl(url), body, encoding, headers, context,
persistentConnection, followRedirects, maxRedirects);

/// Creates a new HEAD [Request] to [url], which can be a [Uri] or a [String].
///
Expand All @@ -46,8 +63,17 @@ class Request extends Message {
/// Extra [context] can be used to pass information between inner middleware
/// and handlers.
Request.head(url,
{Map<String, String> headers, Map<String, Object> context})
: this('HEAD', url, headers: headers, context: context);
{Map<String, String> headers,
Map<String, Object> context,
bool persistentConnection,
bool followRedirects,
int maxRedirects})
: this('HEAD', url,
headers: headers,
context: context,
persistentConnection: persistentConnection,
followRedirects: followRedirects,
maxRedirects: maxRedirects);

/// Creates a new GET [Request] to [url], which can be a [Uri] or a [String].
///
Expand All @@ -57,8 +83,17 @@ class Request extends Message {
/// Extra [context] can be used to pass information between inner middleware
/// and handlers.
Request.get(url,
{Map<String, String> headers, Map<String, Object> context})
: this('GET', url, headers: headers, context: context);
{Map<String, String> headers,
Map<String, Object> context,
bool persistentConnection,
bool followRedirects,
int maxRedirects})
: this('GET', url,
headers: headers,
context: context,
persistentConnection: persistentConnection,
followRedirects: followRedirects,
maxRedirects: maxRedirects);

/// Creates a new POST [Request] to [url], which can be a [Uri] or a [String].
///
Expand All @@ -75,9 +110,18 @@ class Request extends Message {
Request.post(url, body,
{Encoding encoding,
Map<String, String> headers,
Map<String, Object> context})
Map<String, Object> context,
bool persistentConnection,
bool followRedirects,
int maxRedirects})
: this('POST', url,
body: body, encoding: encoding, headers: headers, context: context);
body: body,
encoding: encoding,
headers: headers,
context: context,
persistentConnection: persistentConnection,
followRedirects: followRedirects,
maxRedirects: maxRedirects);

/// Creates a new PUT [Request] to [url], which can be a [Uri] or a [String].
///
Expand All @@ -94,9 +138,18 @@ class Request extends Message {
Request.put(url, body,
{Encoding encoding,
Map<String, String> headers,
Map<String, Object> context})
Map<String, Object> context,
bool persistentConnection,
bool followRedirects,
int maxRedirects})
: this('PUT', url,
body: body, encoding: encoding, headers: headers, context: context);
body: body,
encoding: encoding,
headers: headers,
context: context,
persistentConnection: persistentConnection,
followRedirects: followRedirects,
maxRedirects: maxRedirects);

/// Creates a new PATCH [Request] to [url], which can be a [Uri] or a
/// [String].
Expand All @@ -114,9 +167,18 @@ class Request extends Message {
Request.patch(url, body,
{Encoding encoding,
Map<String, String> headers,
Map<String, Object> context})
Map<String, Object> context,
bool persistentConnection,
bool followRedirects,
int maxRedirects})
: this('PATCH', url,
body: body, encoding: encoding, headers: headers, context: context);
body: body,
encoding: encoding,
headers: headers,
context: context,
persistentConnection: persistentConnection,
followRedirects: followRedirects,
maxRedirects: maxRedirects);

/// Creates a new DELETE [Request] to [url], which can be a [Uri] or a
/// [String].
Expand All @@ -127,15 +189,32 @@ class Request extends Message {
/// Extra [context] can be used to pass information between inner middleware
/// and handlers.
Request.delete(url,
{Map<String, String> headers, Map<String, Object> context})
: this('DELETE', url, headers: headers, context: context);
{Map<String, String> headers,
Map<String, Object> context,
bool persistentConnection,
bool followRedirects,
int maxRedirects})
: this('DELETE', url,
headers: headers,
context: context,
persistentConnection: persistentConnection,
followRedirects: followRedirects,
maxRedirects: maxRedirects);

Request._(this.method, this.url,
Request._(
this.method,
this.url,
body,
Encoding encoding,
Map<String, String> headers,
Map<String, Object> context)
: super(body, encoding: encoding, headers: headers, context: context);
Map<String, Object> context,
bool persistentConnection,
bool followRedirects,
int maxRedirects)
: persistentConnection = persistentConnection ?? true,
followRedirects = followRedirects ?? true,
maxRedirects = maxRedirects ?? 5,
super(body, encoding: encoding, headers: headers, context: context);

/// Creates a new [Request] by copying existing values and applying specified
/// changes.
Expand All @@ -161,6 +240,9 @@ class Request extends Message {
body ?? getBody(this),
this.encoding,
updatedHeaders,
updatedContext);
updatedContext,
this.persistentConnection,
this.followRedirects,
this.maxRedirects);
}
}
19 changes: 17 additions & 2 deletions lib/src/response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ class Response extends Message {
/// The status code of the response.
final int statusCode;

/// The reason phrase associated with the status code.
final String reasonPhrase;

/// Whether this response is a redirect.
final bool isRedirect;

/// Whether the server requested that a persistent connection be maintained.
final bool persistentConnection;

/// Creates a new HTTP response with the given [statusCode].
///
/// [body] is the request body. It may be either a [String], a [List<int>], a
Expand All @@ -30,7 +39,10 @@ class Response extends Message {
{body,
Encoding encoding,
Map<String, String> headers,
Map<String, Object> context})
Map<String, Object> context,
this.reasonPhrase,
this.isRedirect: false,
this.persistentConnection: true})
: super(body, encoding: encoding, headers: headers, context: context);

/// Creates a new [Response] by copying existing values and applying specified
Expand Down Expand Up @@ -58,7 +70,10 @@ class Response extends Message {
return new Response(this.statusCode,
body: body ?? getBody(this),
headers: updatedHeaders,
context: updatedContext);
context: updatedContext,
reasonPhrase: reasonPhrase,
isRedirect: isRedirect,
persistentConnection: persistentConnection);
}

/// The date and time after which the response's data should be considered
Expand Down

0 comments on commit 73cfddb

Please sign in to comment.