[dart:_http] Adds Dart-styled constants

Change-Id: I42e0c02b3aac7f952c5346bbcddd50293bf2b5b8
Reviewed-on: https://dart-review.googlesource.com/58620
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
This commit is contained in:
Zach Anderson 2018-06-07 16:18:33 +00:00 committed by commit-bot@chromium.org
parent a73ff63fd5
commit 87b5112d5b
39 changed files with 900 additions and 622 deletions

View file

@ -20,6 +20,15 @@
#### Other Tools
### Core library changes
* `dart:io`
* Dart-styled constants have been added for `HttpStatus`, `HttpHeaders`,
`ContentType`, `HttpClient`, `WebSocketStatus`, `CompressionOptions`,
and `WebSocket`. The `SCREAMING_CAPS` constants are marked deprecated.
Note that `HttpStatus.CONTINUE` is now `HttpStatus.continue_`, and that
e.g. `HttpHeaders.FIELD_NAME` is now `HttpHeaders.fieldNameHeader`.
## 2.0.0-dev.60.0
### Core library changes

View file

@ -34,50 +34,138 @@ part 'websocket_impl.dart';
* HTTP status codes.
*/
abstract class HttpStatus {
static const int CONTINUE = 100;
static const int SWITCHING_PROTOCOLS = 101;
static const int OK = 200;
static const int CREATED = 201;
static const int ACCEPTED = 202;
static const int NON_AUTHORITATIVE_INFORMATION = 203;
static const int NO_CONTENT = 204;
static const int RESET_CONTENT = 205;
static const int PARTIAL_CONTENT = 206;
static const int MULTIPLE_CHOICES = 300;
static const int MOVED_PERMANENTLY = 301;
static const int FOUND = 302;
static const int MOVED_TEMPORARILY = 302; // Common alias for FOUND.
static const int SEE_OTHER = 303;
static const int NOT_MODIFIED = 304;
static const int USE_PROXY = 305;
static const int TEMPORARY_REDIRECT = 307;
static const int BAD_REQUEST = 400;
static const int UNAUTHORIZED = 401;
static const int PAYMENT_REQUIRED = 402;
static const int FORBIDDEN = 403;
static const int NOT_FOUND = 404;
static const int METHOD_NOT_ALLOWED = 405;
static const int NOT_ACCEPTABLE = 406;
static const int PROXY_AUTHENTICATION_REQUIRED = 407;
static const int REQUEST_TIMEOUT = 408;
static const int CONFLICT = 409;
static const int GONE = 410;
static const int LENGTH_REQUIRED = 411;
static const int PRECONDITION_FAILED = 412;
static const int REQUEST_ENTITY_TOO_LARGE = 413;
static const int REQUEST_URI_TOO_LONG = 414;
static const int UNSUPPORTED_MEDIA_TYPE = 415;
static const int REQUESTED_RANGE_NOT_SATISFIABLE = 416;
static const int EXPECTATION_FAILED = 417;
static const int UPGRADE_REQUIRED = 426;
static const int INTERNAL_SERVER_ERROR = 500;
static const int NOT_IMPLEMENTED = 501;
static const int BAD_GATEWAY = 502;
static const int SERVICE_UNAVAILABLE = 503;
static const int GATEWAY_TIMEOUT = 504;
static const int HTTP_VERSION_NOT_SUPPORTED = 505;
static const int continue_ = 100;
static const int switchingProtocols = 101;
static const int ok = 200;
static const int created = 201;
static const int accepted = 202;
static const int nonAuthoritativeInformation = 203;
static const int noContent = 204;
static const int resetContent = 205;
static const int partialContent = 206;
static const int multipleChoices = 300;
static const int movedPermanently = 301;
static const int found = 302;
static const int movedTemporarily = 302; // Common alias for found.
static const int seeOther = 303;
static const int notModified = 304;
static const int useProxy = 305;
static const int temporaryRedirect = 307;
static const int badRequest = 400;
static const int unauthorized = 401;
static const int paymentRequired = 402;
static const int forbidden = 403;
static const int notFound = 404;
static const int methodNotAllowed = 405;
static const int notAcceptable = 406;
static const int proxyAuthenticationRequired = 407;
static const int requestTimeout = 408;
static const int conflict = 409;
static const int gone = 410;
static const int lengthRequired = 411;
static const int preconditionFailed = 412;
static const int requestEntityTooLarge = 413;
static const int requestUriTooLong = 414;
static const int unsupportedMediaType = 415;
static const int requestedRangeNotSatisfiable = 416;
static const int expectationFailed = 417;
static const int upgradeRequired = 426;
static const int internalServerError = 500;
static const int notImplemented = 501;
static const int badGateway = 502;
static const int serviceUnavailable = 503;
static const int gatewayTimeout = 504;
static const int httpVersionNotSupported = 505;
// Client generated status code.
static const int NETWORK_CONNECT_TIMEOUT_ERROR = 599;
static const int networkConnectTimeoutError = 599;
@Deprecated("Use continue_ instead")
static const int CONTINUE = continue_;
@Deprecated("Use switchingProtocols instead")
static const int SWITCHING_PROTOCOLS = switchingProtocols;
@Deprecated("Use ok instead")
static const int OK = ok;
@Deprecated("Use created instead")
static const int CREATED = created;
@Deprecated("Use accepted instead")
static const int ACCEPTED = accepted;
@Deprecated("Use nonAuthoritativeInformation instead")
static const int NON_AUTHORITATIVE_INFORMATION = nonAuthoritativeInformation;
@Deprecated("Use noContent instead")
static const int NO_CONTENT = noContent;
@Deprecated("Use resetContent instead")
static const int RESET_CONTENT = resetContent;
@Deprecated("Use partialContent instead")
static const int PARTIAL_CONTENT = partialContent;
@Deprecated("Use multipleChoices instead")
static const int MULTIPLE_CHOICES = multipleChoices;
@Deprecated("Use movedPermanently instead")
static const int MOVED_PERMANENTLY = movedPermanently;
@Deprecated("Use found instead")
static const int FOUND = found;
@Deprecated("Use movedTemporarily instead")
static const int MOVED_TEMPORARILY = movedTemporarily;
@Deprecated("Use seeOther instead")
static const int SEE_OTHER = seeOther;
@Deprecated("Use notModified instead")
static const int NOT_MODIFIED = notModified;
@Deprecated("Use useProxy instead")
static const int USE_PROXY = useProxy;
@Deprecated("Use temporaryRedirect instead")
static const int TEMPORARY_REDIRECT = temporaryRedirect;
@Deprecated("Use badRequest instead")
static const int BAD_REQUEST = badRequest;
@Deprecated("Use unauthorized instead")
static const int UNAUTHORIZED = unauthorized;
@Deprecated("Use paymentRequired instead")
static const int PAYMENT_REQUIRED = paymentRequired;
@Deprecated("Use forbidden instead")
static const int FORBIDDEN = forbidden;
@Deprecated("Use notFound instead")
static const int NOT_FOUND = notFound;
@Deprecated("Use methodNotAllowed instead")
static const int METHOD_NOT_ALLOWED = methodNotAllowed;
@Deprecated("Use notAcceptable instead")
static const int NOT_ACCEPTABLE = notAcceptable;
@Deprecated("Use proxyAuthenticationRequired instead")
static const int PROXY_AUTHENTICATION_REQUIRED = proxyAuthenticationRequired;
@Deprecated("Use requestTimeout instead")
static const int REQUEST_TIMEOUT = requestTimeout;
@Deprecated("Use conflict instead")
static const int CONFLICT = conflict;
@Deprecated("Use gone instead")
static const int GONE = gone;
@Deprecated("Use lengthRequired instead")
static const int LENGTH_REQUIRED = lengthRequired;
@Deprecated("Use preconditionFailed instead")
static const int PRECONDITION_FAILED = preconditionFailed;
@Deprecated("Use requestEntityTooLarge instead")
static const int REQUEST_ENTITY_TOO_LARGE = requestEntityTooLarge;
@Deprecated("Use requestUriTooLong instead")
static const int REQUEST_URI_TOO_LONG = requestUriTooLong;
@Deprecated("Use unsupportedMediaType instead")
static const int UNSUPPORTED_MEDIA_TYPE = unsupportedMediaType;
@Deprecated("Use requestedRangeNotSatisfiable instead")
static const int REQUESTED_RANGE_NOT_SATISFIABLE =
requestedRangeNotSatisfiable;
@Deprecated("Use expectationFailed instead")
static const int EXPECTATION_FAILED = expectationFailed;
@Deprecated("Use upgradeRequired instead")
static const int UPGRADE_REQUIRED = upgradeRequired;
@Deprecated("Use internalServerError instead")
static const int INTERNAL_SERVER_ERROR = internalServerError;
@Deprecated("Use notImplemented instead")
static const int NOT_IMPLEMENTED = notImplemented;
@Deprecated("Use badGateway instead")
static const int BAD_GATEWAY = badGateway;
@Deprecated("Use serviceUnavailable instead")
static const int SERVICE_UNAVAILABLE = serviceUnavailable;
@Deprecated("Use gatewayTimeout instead")
static const int GATEWAY_TIMEOUT = gatewayTimeout;
@Deprecated("Use httpVersionNotSupported instead")
static const int HTTP_VERSION_NOT_SUPPORTED = httpVersionNotSupported;
@Deprecated("Use networkConnectTimeoutError instead")
static const int NETWORK_CONNECT_TIMEOUT_ERROR = networkConnectTimeoutError;
}
/**
@ -97,7 +185,7 @@ abstract class HttpStatus {
*
* main() {
* HttpServer
* .bind(InternetAddress.ANY_IP_V6, 80)
* .bind(InternetAddress.anyIPv6, 80)
* .then((server) {
* server.listen((HttpRequest request) {
* request.response.write('Hello, world!');
@ -138,7 +226,7 @@ abstract class HttpStatus {
* context.usePrivateKey(key, password: 'dartdart');
*
* HttpServer
* .bindSecure(InternetAddress.ANY_IP_V6,
* .bindSecure(InternetAddress.anyIPv6,
* 443,
* context)
* .then((server) {
@ -160,7 +248,7 @@ abstract class HttpStatus {
* import 'dart:io';
*
* main() {
* ServerSocket.bind(InternetAddress.ANY_IP_V6, 80)
* ServerSocket.bind(InternetAddress.anyIPv6, 80)
* .then((serverSocket) {
* HttpServer httpserver = new HttpServer.listenOn(serverSocket);
* serverSocket.listen((Socket socket) {
@ -242,17 +330,17 @@ abstract class HttpServer implements Stream<HttpRequest> {
* perform a [InternetAddress.lookup] and use the first value in the
* list. To listen on the loopback adapter, which will allow only
* incoming connections from the local host, use the value
* [InternetAddress.LOOPBACK_IP_V4] or
* [InternetAddress.LOOPBACK_IP_V6]. To allow for incoming
* [InternetAddress.loopbackIPv4] or
* [InternetAddress.loopbackIPv6]. To allow for incoming
* connection from the network use either one of the values
* [InternetAddress.ANY_IP_V4] or [InternetAddress.ANY_IP_V6] to
* [InternetAddress.anyIPv4] or [InternetAddress.anyIPv6] to
* bind to all interfaces or the IP address of a specific interface.
*
* If an IP version 6 (IPv6) address is used, both IP version 6
* (IPv6) and version 4 (IPv4) connections will be accepted. To
* restrict this to version 6 (IPv6) only, use [v6Only] to set
* version 6 only. However, if the address is
* [InternetAddress.LOOPBACK_IP_V6], only IP version 6 (IPv6) connections
* [InternetAddress.loopbackIPv6], only IP version 6 (IPv6) connections
* will be accepted.
*
* If [port] has the value [:0:] an ephemeral port will be chosen by
@ -281,10 +369,10 @@ abstract class HttpServer implements Stream<HttpRequest> {
* perform a [InternetAddress.lookup] and use the first value in the
* list. To listen on the loopback adapter, which will allow only
* incoming connections from the local host, use the value
* [InternetAddress.LOOPBACK_IP_V4] or
* [InternetAddress.LOOPBACK_IP_V6]. To allow for incoming
* [InternetAddress.loopbackIPv4] or
* [InternetAddress.loopbackIPv6]. To allow for incoming
* connection from the network use either one of the values
* [InternetAddress.ANY_IP_V4] or [InternetAddress.ANY_IP_V6] to
* [InternetAddress.anyIPv4] or [InternetAddress.anyIPv6] to
* bind to all interfaces or the IP address of a specific interface.
*
* If an IP version 6 (IPv6) address is used, both IP version 6
@ -415,12 +503,12 @@ class HttpConnectionsInfo {
*
* To set the value of a header use the `set()` method:
*
* request.headers.set(HttpHeaders.CACHE_CONTROL,
* request.headers.set(HttpHeaders.cacheControlHeader,
* 'max-age=3600, must-revalidate');
*
* To retrieve the value of a header use the `value()` method:
*
* print(request.headers.value(HttpHeaders.USER_AGENT));
* print(request.headers.value(HttpHeaders.userAgentHeader));
*
* An HttpHeaders object holds a list of values for each name
* as the standard allows. In most cases a name holds only a single value,
@ -428,117 +516,229 @@ class HttpConnectionsInfo {
* and `value()` for retrieving a value.
*/
abstract class HttpHeaders {
static const ACCEPT = "accept";
static const ACCEPT_CHARSET = "accept-charset";
static const ACCEPT_ENCODING = "accept-encoding";
static const ACCEPT_LANGUAGE = "accept-language";
static const ACCEPT_RANGES = "accept-ranges";
static const AGE = "age";
static const ALLOW = "allow";
static const AUTHORIZATION = "authorization";
static const CACHE_CONTROL = "cache-control";
static const CONNECTION = "connection";
static const CONTENT_ENCODING = "content-encoding";
static const CONTENT_LANGUAGE = "content-language";
static const CONTENT_LENGTH = "content-length";
static const CONTENT_LOCATION = "content-location";
static const CONTENT_MD5 = "content-md5";
static const CONTENT_RANGE = "content-range";
static const CONTENT_TYPE = "content-type";
static const DATE = "date";
static const ETAG = "etag";
static const EXPECT = "expect";
static const EXPIRES = "expires";
static const FROM = "from";
static const HOST = "host";
static const IF_MATCH = "if-match";
static const IF_MODIFIED_SINCE = "if-modified-since";
static const IF_NONE_MATCH = "if-none-match";
static const IF_RANGE = "if-range";
static const IF_UNMODIFIED_SINCE = "if-unmodified-since";
static const LAST_MODIFIED = "last-modified";
static const LOCATION = "location";
static const MAX_FORWARDS = "max-forwards";
static const PRAGMA = "pragma";
static const PROXY_AUTHENTICATE = "proxy-authenticate";
static const PROXY_AUTHORIZATION = "proxy-authorization";
static const RANGE = "range";
static const REFERER = "referer";
static const RETRY_AFTER = "retry-after";
static const SERVER = "server";
static const TE = "te";
static const TRAILER = "trailer";
static const TRANSFER_ENCODING = "transfer-encoding";
static const UPGRADE = "upgrade";
static const USER_AGENT = "user-agent";
static const VARY = "vary";
static const VIA = "via";
static const WARNING = "warning";
static const WWW_AUTHENTICATE = "www-authenticate";
static const acceptHeader = "accept";
static const acceptCharsetHeader = "accept-charset";
static const acceptEncodingHeader = "accept-encoding";
static const acceptLanguageHeader = "accept-language";
static const acceptRangesHeader = "accept-ranges";
static const ageHeader = "age";
static const allowHeader = "allow";
static const authorizationHeader = "authorization";
static const cacheControlHeader = "cache-control";
static const connectionHeader = "connection";
static const contentEncodingHeader = "content-encoding";
static const contentLanguageHeader = "content-language";
static const contentLengthHeader = "content-length";
static const contentLocationHeader = "content-location";
static const contentMD5Header = "content-md5";
static const contentRangeHeader = "content-range";
static const contentTypeHeader = "content-type";
static const dateHeader = "date";
static const etagHeader = "etag";
static const expectHeader = "expect";
static const expiresHeader = "expires";
static const fromHeader = "from";
static const hostHeader = "host";
static const ifMatchHeader = "if-match";
static const ifModifiedSinceHeader = "if-modified-since";
static const ifNoneMatchHeader = "if-none-match";
static const ifRangeHeader = "if-range";
static const ifUnmodifiedSinceHeader = "if-unmodified-since";
static const lastModifiedHeader = "last-modified";
static const locationHeader = "location";
static const maxForwardsHeader = "max-forwards";
static const pragmaHeader = "pragma";
static const proxyAuthenticateHeader = "proxy-authenticate";
static const proxyAuthorizationHeader = "proxy-authorization";
static const rangeHeader = "range";
static const refererHeader = "referer";
static const retryAfterHeader = "retry-after";
static const serverHeader = "server";
static const teHeader = "te";
static const trailerHeader = "trailer";
static const transferEncodingHeader = "transfer-encoding";
static const upgradeHeader = "upgrade";
static const userAgentHeader = "user-agent";
static const varyHeader = "vary";
static const viaHeader = "via";
static const warningHeader = "warning";
static const wwwAuthenticateHeader = "www-authenticate";
@Deprecated("Use acceptHeader instead")
static const ACCEPT = acceptHeader;
@Deprecated("Use acceptCharsetHeader instead")
static const ACCEPT_CHARSET = acceptCharsetHeader;
@Deprecated("Use acceptEncodingHeader instead")
static const ACCEPT_ENCODING = acceptEncodingHeader;
@Deprecated("Use acceptLanguageHeader instead")
static const ACCEPT_LANGUAGE = acceptLanguageHeader;
@Deprecated("Use acceptRangesHeader instead")
static const ACCEPT_RANGES = acceptRangesHeader;
@Deprecated("Use ageHeader instead")
static const AGE = ageHeader;
@Deprecated("Use allowHeader instead")
static const ALLOW = allowHeader;
@Deprecated("Use authorizationHeader instead")
static const AUTHORIZATION = authorizationHeader;
@Deprecated("Use cacheControlHeader instead")
static const CACHE_CONTROL = cacheControlHeader;
@Deprecated("Use connectionHeader instead")
static const CONNECTION = connectionHeader;
@Deprecated("Use contentEncodingHeader instead")
static const CONTENT_ENCODING = contentEncodingHeader;
@Deprecated("Use contentLanguageHeader instead")
static const CONTENT_LANGUAGE = contentLanguageHeader;
@Deprecated("Use contentLengthHeader instead")
static const CONTENT_LENGTH = contentLengthHeader;
@Deprecated("Use contentLocationHeader instead")
static const CONTENT_LOCATION = contentLocationHeader;
@Deprecated("Use contentMD5Header instead")
static const CONTENT_MD5 = contentMD5Header;
@Deprecated("Use contentRangeHeader instead")
static const CONTENT_RANGE = contentRangeHeader;
@Deprecated("Use contentTypeHeader instead")
static const CONTENT_TYPE = contentTypeHeader;
@Deprecated("Use dateHeader instead")
static const DATE = dateHeader;
@Deprecated("Use etagHeader instead")
static const ETAG = etagHeader;
@Deprecated("Use expectHeader instead")
static const EXPECT = expectHeader;
@Deprecated("Use expiresHeader instead")
static const EXPIRES = expiresHeader;
@Deprecated("Use fromHeader instead")
static const FROM = fromHeader;
@Deprecated("Use hostHeader instead")
static const HOST = hostHeader;
@Deprecated("Use ifMatchHeader instead")
static const IF_MATCH = ifMatchHeader;
@Deprecated("Use ifModifiedSinceHeader instead")
static const IF_MODIFIED_SINCE = ifModifiedSinceHeader;
@Deprecated("Use ifNoneMatchHeader instead")
static const IF_NONE_MATCH = ifNoneMatchHeader;
@Deprecated("Use ifRangeHeader instead")
static const IF_RANGE = ifRangeHeader;
@Deprecated("Use ifUnmodifiedSinceHeader instead")
static const IF_UNMODIFIED_SINCE = ifUnmodifiedSinceHeader;
@Deprecated("Use lastModifiedHeader instead")
static const LAST_MODIFIED = lastModifiedHeader;
@Deprecated("Use locationHeader instead")
static const LOCATION = locationHeader;
@Deprecated("Use maxForwardsHeader instead")
static const MAX_FORWARDS = maxForwardsHeader;
@Deprecated("Use pragmaHeader instead")
static const PRAGMA = pragmaHeader;
@Deprecated("Use proxyAuthenticateHeader instead")
static const PROXY_AUTHENTICATE = proxyAuthenticateHeader;
@Deprecated("Use proxyAuthorizationHeader instead")
static const PROXY_AUTHORIZATION = proxyAuthorizationHeader;
@Deprecated("Use rangeHeader instead")
static const RANGE = rangeHeader;
@Deprecated("Use refererHeader instead")
static const REFERER = refererHeader;
@Deprecated("Use retryAfterHeader instead")
static const RETRY_AFTER = retryAfterHeader;
@Deprecated("Use serverHeader instead")
static const SERVER = serverHeader;
@Deprecated("Use teHeader instead")
static const TE = teHeader;
@Deprecated("Use trailerHeader instead")
static const TRAILER = trailerHeader;
@Deprecated("Use transferEncodingHeader instead")
static const TRANSFER_ENCODING = transferEncodingHeader;
@Deprecated("Use upgradeHeader instead")
static const UPGRADE = upgradeHeader;
@Deprecated("Use userAgentHeader instead")
static const USER_AGENT = userAgentHeader;
@Deprecated("Use varyHeader instead")
static const VARY = varyHeader;
@Deprecated("Use viaHeader instead")
static const VIA = viaHeader;
@Deprecated("Use warningHeader instead")
static const WARNING = warningHeader;
@Deprecated("Use wwwAuthenticateHeader instead")
static const WWW_AUTHENTICATE = wwwAuthenticateHeader;
// Cookie headers from RFC 6265.
static const COOKIE = "cookie";
static const SET_COOKIE = "set-cookie";
static const cookieHeader = "cookie";
static const setCookieHeader = "set-cookie";
static const GENERAL_HEADERS = const [
CACHE_CONTROL,
CONNECTION,
DATE,
PRAGMA,
TRAILER,
TRANSFER_ENCODING,
UPGRADE,
VIA,
WARNING
@Deprecated("Use cookieHeader instead")
static const COOKIE = cookieHeader;
@Deprecated("Use setCookieHeader instead")
static const SET_COOKIE = setCookieHeader;
static const generalHeaders = const [
cacheControlHeader,
connectionHeader,
dateHeader,
pragmaHeader,
trailerHeader,
transferEncodingHeader,
upgradeHeader,
viaHeader,
warningHeader
];
static const ENTITY_HEADERS = const [
ALLOW,
CONTENT_ENCODING,
CONTENT_LANGUAGE,
CONTENT_LENGTH,
CONTENT_LOCATION,
CONTENT_MD5,
CONTENT_RANGE,
CONTENT_TYPE,
EXPIRES,
LAST_MODIFIED
@Deprecated("Use generalHeaders instead")
static const GENERAL_HEADERS = generalHeaders;
static const entityHeaders = const [
allowHeader,
contentEncodingHeader,
contentLanguageHeader,
contentLengthHeader,
contentLocationHeader,
contentMD5Header,
contentRangeHeader,
contentTypeHeader,
expiresHeader,
lastModifiedHeader
];
static const RESPONSE_HEADERS = const [
ACCEPT_RANGES,
AGE,
ETAG,
LOCATION,
PROXY_AUTHENTICATE,
RETRY_AFTER,
SERVER,
VARY,
WWW_AUTHENTICATE
@Deprecated("Use entityHeaders instead")
static const ENTITY_HEADERS = entityHeaders;
static const responseHeaders = const [
acceptRangesHeader,
ageHeader,
etagHeader,
locationHeader,
proxyAuthenticateHeader,
retryAfterHeader,
serverHeader,
varyHeader,
wwwAuthenticateHeader
];
static const REQUEST_HEADERS = const [
ACCEPT,
ACCEPT_CHARSET,
ACCEPT_ENCODING,
ACCEPT_LANGUAGE,
AUTHORIZATION,
EXPECT,
FROM,
HOST,
IF_MATCH,
IF_MODIFIED_SINCE,
IF_NONE_MATCH,
IF_RANGE,
IF_UNMODIFIED_SINCE,
MAX_FORWARDS,
PROXY_AUTHORIZATION,
RANGE,
REFERER,
TE,
USER_AGENT
@Deprecated("Use responseHeaders instead")
static const RESPONSE_HEADERS = responseHeaders;
static const requestHeaders = const [
acceptHeader,
acceptCharsetHeader,
acceptEncodingHeader,
acceptLanguageHeader,
authorizationHeader,
expectHeader,
fromHeader,
hostHeader,
ifMatchHeader,
ifModifiedSinceHeader,
ifNoneMatchHeader,
ifRangeHeader,
ifUnmodifiedSinceHeader,
maxForwardsHeader,
proxyAuthorizationHeader,
rangeHeader,
refererHeader,
teHeader,
userAgentHeader
];
@Deprecated("Use requestHeaders instead")
static const REQUEST_HEADERS = requestHeaders;
/**
* Gets and sets the date. The value of this property will
* reflect the 'date' header.
@ -677,13 +877,13 @@ abstract class HttpHeaders {
*
* HttpClientRequest request = ...;
* var v = new HeaderValue("text/plain", {"q": "0.3"});
* request.headers.add(HttpHeaders.ACCEPT, v);
* request.headers.add(HttpHeaders.ACCEPT, "text/html");
* request.headers.add(HttpHeaders.acceptHeader, v);
* request.headers.add(HttpHeaders.acceptHeader, "text/html");
*
* To parse the header values use the [:parse:] static method.
*
* HttpRequest request = ...;
* List<String> values = request.headers[HttpHeaders.ACCEPT];
* List<String> values = request.headers[HttpHeaders.acceptHeader];
* values.forEach((value) {
* HeaderValue v = HeaderValue.parse(value);
* // Use v.value and v.parameters
@ -767,28 +967,36 @@ abstract class ContentType implements HeaderValue {
*
* text/plain; charset=utf-8
*/
static final TEXT = new ContentType("text", "plain", charset: "utf-8");
static final text = new ContentType("text", "plain", charset: "utf-8");
@Deprecated("Use text instead")
static final TEXT = text;
/**
* Content type for HTML using UTF-8 encoding.
*
* text/html; charset=utf-8
*/
static final HTML = new ContentType("text", "html", charset: "utf-8");
static final html = new ContentType("text", "html", charset: "utf-8");
@Deprecated("Use html instead")
static final HTML = html;
/**
* Content type for JSON using UTF-8 encoding.
*
* application/json; charset=utf-8
*/
static final JSON = new ContentType("application", "json", charset: "utf-8");
static final json = new ContentType("application", "json", charset: "utf-8");
@Deprecated("Use json instead")
static final JSON = json;
/**
* Content type for binary data.
*
* application/octet-stream
*/
static final BINARY = new ContentType("application", "octet-stream");
static final binary = new ContentType("application", "octet-stream");
@Deprecated("Use binary instead")
static final BINARY = binary;
/**
* Creates a new content type object setting the primary type and
@ -935,7 +1143,7 @@ abstract class Cookie {
* for HTTP requests. When the server receives a request,
* it uses the HttpRequest object's `method` property to dispatch requests.
*
* final HOST = InternetAddress.LOOPBACK_IP_V4;
* final HOST = InternetAddress.loopbackIPv4;
* final PORT = 80;
*
* HttpServer.bind(HOST, PORT).then((_server) {
@ -1101,7 +1309,7 @@ abstract class HttpRequest implements Stream<List<int>> {
* be used.
*
* HttpResponse response = ...
* response.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain");
* response.headers.add(HttpHeaders.contentTypeHeader, "text/plain");
* response.write(...); // Strings written will be ISO-8859-1 encoded.
*
* An exception is thrown if you use the `write()` method
@ -1120,7 +1328,7 @@ abstract class HttpResponse implements IOSink {
* Gets and sets the status code. Any integer value is accepted. For
* the official HTTP status codes use the fields from
* [HttpStatus]. If no status code is explicitly set the default
* value [HttpStatus.OK] is used.
* value [HttpStatus.ok] is used.
*
* The status code must be set before the body is written
* to. Setting the status code after writing to the response body or
@ -1186,14 +1394,14 @@ abstract class HttpResponse implements IOSink {
* The URI in [location] should be absolute, but there are no checks
* to enforce that.
*
* By default the HTTP status code `HttpStatus.MOVED_TEMPORARILY`
* By default the HTTP status code `HttpStatus.movedTemporarily`
* (`302`) is used for the redirect, but an alternative one can be
* specified using the [status] argument.
*
* This method will also call `close`, and the returned future is
* the future returned by `close`.
*/
Future redirect(Uri location, {int status: HttpStatus.MOVED_TEMPORARILY});
Future redirect(Uri location, {int status: HttpStatus.movedTemporarily});
/**
* Detaches the underlying socket from the HTTP server. When the
@ -1283,7 +1491,7 @@ abstract class HttpResponse implements IOSink {
* `Accept-Encoding` header to something else.
* To turn off gzip compression of the response, clear this header:
*
* request.headers.removeAll(HttpHeaders.ACCEPT_ENCODING)
* request.headers.removeAll(HttpHeaders.acceptEncodingHeader)
*
* ## Closing the HttpClient
*
@ -1305,8 +1513,13 @@ abstract class HttpResponse implements IOSink {
* client.findProxy = null;
*/
abstract class HttpClient {
static const int DEFAULT_HTTP_PORT = 80;
static const int DEFAULT_HTTPS_PORT = 443;
static const int defaultHttpPort = 80;
@Deprecated("Use defaultHttpPort instead")
static const int DEFAULT_HTTP_PORT = defaultHttpPort;
static const int defaultHttpsPort = 443;
@Deprecated("Use defaultHttpsPort instead")
static const int DEFAULT_HTTPS_PORT = defaultHttpsPort;
/// Gets and sets the idle timeout of non-active persistent (keep-alive)
/// connections.
@ -1722,7 +1935,7 @@ abstract class HttpClient {
* be used.
*
* HttpClientRequest request = ...
* request.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain");
* request.headers.add(HttpHeaders.contentTypeHeader, "text/plain");
* request.write(...); // Strings written will be ISO-8859-1 encoded.
*
* An exception is thrown if you use an unsupported encoding and the
@ -1741,12 +1954,12 @@ abstract class HttpClientRequest implements IOSink {
* automatically follow redirects. The default is [:true:].
*
* Automatic redirect will only happen for "GET" and "HEAD" requests
* and only for the status codes [:HttpStatus.MOVED_PERMANENTLY:]
* (301), [:HttpStatus.FOUND:] (302),
* [:HttpStatus.MOVED_TEMPORARILY:] (302, alias for
* [:HttpStatus.FOUND:]), [:HttpStatus.SEE_OTHER:] (303) and
* [:HttpStatus.TEMPORARY_REDIRECT:] (307). For
* [:HttpStatus.SEE_OTHER:] (303) automatic redirect will also happen
* and only for the status codes [:HttpStatus.movedPermanently:]
* (301), [:HttpStatus.found:] (302),
* [:HttpStatus.movedTemporarily:] (302, alias for
* [:HttpStatus.found:]), [:HttpStatus.seeOther:] (303) and
* [:HttpStatus.temporaryRedirect:] (307). For
* [:HttpStatus.seeOther:] (303) automatic redirect will also happen
* for "POST" requests with the method changed to "GET" when
* following the redirect.
*
@ -1878,9 +2091,9 @@ abstract class HttpClientResponse implements Stream<List<int>> {
/**
* Returns whether the status code is one of the normal redirect
* codes [HttpStatus.MOVED_PERMANENTLY], [HttpStatus.FOUND],
* [HttpStatus.MOVED_TEMPORARILY], [HttpStatus.SEE_OTHER] and
* [HttpStatus.TEMPORARY_REDIRECT].
* codes [HttpStatus.movedPermanently], [HttpStatus.found],
* [HttpStatus.movedTemporarily], [HttpStatus.seeOther] and
* [HttpStatus.temporaryRedirect].
*/
bool get isRedirect;
@ -1894,7 +2107,7 @@ abstract class HttpClientResponse implements Stream<List<int>> {
/**
* Redirects this connection to a new URL. The default value for
* [method] is the method for the current request. The default value
* for [url] is the value of the [HttpHeaders.LOCATION] header of
* for [url] is the value of the [HttpHeaders.locationHeader] header of
* the current response. All body data must have been read from the
* current response before calling [redirect].
*

View file

@ -20,7 +20,7 @@ class _HttpHeaders implements HttpHeaders {
final int _defaultPortForScheme;
_HttpHeaders(this.protocolVersion,
{int defaultPortForScheme: HttpClient.DEFAULT_HTTP_PORT,
{int defaultPortForScheme: HttpClient.defaultHttpPort,
_HttpHeaders initialHeaders})
: _headers = new HashMap<String, List<String>>(),
_defaultPortForScheme = defaultPortForScheme {
@ -70,7 +70,7 @@ class _HttpHeaders implements HttpHeaders {
_checkMutable();
name = _validateField(name);
_headers.remove(name);
if (name == HttpHeaders.TRANSFER_ENCODING) {
if (name == HttpHeaders.transferEncodingHeader) {
_chunkedTransferEncoding = false;
}
_addAll(name, value);
@ -88,7 +88,7 @@ class _HttpHeaders implements HttpHeaders {
}
if (values.length == 0) _headers.remove(name);
}
if (name == HttpHeaders.TRANSFER_ENCODING && value == "chunked") {
if (name == HttpHeaders.transferEncodingHeader && value == "chunked") {
_chunkedTransferEncoding = false;
}
}
@ -115,20 +115,20 @@ class _HttpHeaders implements HttpHeaders {
if (persistentConnection == _persistentConnection) return;
if (persistentConnection) {
if (protocolVersion == "1.1") {
remove(HttpHeaders.CONNECTION, "close");
remove(HttpHeaders.connectionHeader, "close");
} else {
if (_contentLength == -1) {
throw new HttpException(
"Trying to set 'Connection: Keep-Alive' on HTTP 1.0 headers with "
"no ContentLength");
}
add(HttpHeaders.CONNECTION, "keep-alive");
add(HttpHeaders.connectionHeader, "keep-alive");
}
} else {
if (protocolVersion == "1.1") {
add(HttpHeaders.CONNECTION, "close");
add(HttpHeaders.connectionHeader, "close");
} else {
remove(HttpHeaders.CONNECTION, "keep-alive");
remove(HttpHeaders.connectionHeader, "keep-alive");
}
}
_persistentConnection = persistentConnection;
@ -149,9 +149,9 @@ class _HttpHeaders implements HttpHeaders {
_contentLength = contentLength;
if (_contentLength >= 0) {
if (chunkedTransferEncoding) chunkedTransferEncoding = false;
_set(HttpHeaders.CONTENT_LENGTH, contentLength.toString());
_set(HttpHeaders.contentLengthHeader, contentLength.toString());
} else {
removeAll(HttpHeaders.CONTENT_LENGTH);
removeAll(HttpHeaders.contentLengthHeader);
if (protocolVersion == "1.1") {
chunkedTransferEncoding = true;
}
@ -168,15 +168,15 @@ class _HttpHeaders implements HttpHeaders {
}
if (chunkedTransferEncoding == _chunkedTransferEncoding) return;
if (chunkedTransferEncoding) {
List<String> values = _headers[HttpHeaders.TRANSFER_ENCODING];
List<String> values = _headers[HttpHeaders.transferEncodingHeader];
if ((values == null || values.last != "chunked")) {
// Headers does not specify chunked encoding - add it if set.
_addValue(HttpHeaders.TRANSFER_ENCODING, "chunked");
_addValue(HttpHeaders.transferEncodingHeader, "chunked");
}
contentLength = -1;
} else {
// Headers does specify chunked encoding - remove it if not set.
remove(HttpHeaders.TRANSFER_ENCODING, "chunked");
remove(HttpHeaders.transferEncodingHeader, "chunked");
}
_chunkedTransferEncoding = chunkedTransferEncoding;
}
@ -198,7 +198,7 @@ class _HttpHeaders implements HttpHeaders {
}
DateTime get ifModifiedSince {
List<String> values = _headers[HttpHeaders.IF_MODIFIED_SINCE];
List<String> values = _headers[HttpHeaders.ifModifiedSinceHeader];
if (values != null) {
try {
return HttpDate.parse(values[0]);
@ -213,11 +213,11 @@ class _HttpHeaders implements HttpHeaders {
_checkMutable();
// Format "ifModifiedSince" header with date in Greenwich Mean Time (GMT).
String formatted = HttpDate.format(ifModifiedSince.toUtc());
_set(HttpHeaders.IF_MODIFIED_SINCE, formatted);
_set(HttpHeaders.ifModifiedSinceHeader, formatted);
}
DateTime get date {
List<String> values = _headers[HttpHeaders.DATE];
List<String> values = _headers[HttpHeaders.dateHeader];
if (values != null) {
try {
return HttpDate.parse(values[0]);
@ -236,7 +236,7 @@ class _HttpHeaders implements HttpHeaders {
}
DateTime get expires {
List<String> values = _headers[HttpHeaders.EXPIRES];
List<String> values = _headers[HttpHeaders.expiresHeader];
if (values != null) {
try {
return HttpDate.parse(values[0]);
@ -251,7 +251,7 @@ class _HttpHeaders implements HttpHeaders {
_checkMutable();
// Format "Expires" header with date in Greenwich Mean Time (GMT).
String formatted = HttpDate.format(expires.toUtc());
_set(HttpHeaders.EXPIRES, formatted);
_set(HttpHeaders.expiresHeader, formatted);
}
ContentType get contentType {
@ -265,7 +265,7 @@ class _HttpHeaders implements HttpHeaders {
void set contentType(ContentType contentType) {
_checkMutable();
_set(HttpHeaders.CONTENT_TYPE, contentType.toString());
_set(HttpHeaders.contentTypeHeader, contentType.toString());
}
void clear() {
@ -285,45 +285,45 @@ class _HttpHeaders implements HttpHeaders {
// faster than computing hash and looking up in a hash-map.
switch (name.length) {
case 4:
if (HttpHeaders.DATE == name) {
if (HttpHeaders.dateHeader == name) {
_addDate(name, value);
return;
}
if (HttpHeaders.HOST == name) {
if (HttpHeaders.hostHeader == name) {
_addHost(name, value);
return;
}
break;
case 7:
if (HttpHeaders.EXPIRES == name) {
if (HttpHeaders.expiresHeader == name) {
_addExpires(name, value);
return;
}
break;
case 10:
if (HttpHeaders.CONNECTION == name) {
if (HttpHeaders.connectionHeader == name) {
_addConnection(name, value);
return;
}
break;
case 12:
if (HttpHeaders.CONTENT_TYPE == name) {
if (HttpHeaders.contentTypeHeader == name) {
_addContentType(name, value);
return;
}
break;
case 14:
if (HttpHeaders.CONTENT_LENGTH == name) {
if (HttpHeaders.contentLengthHeader == name) {
_addContentLength(name, value);
return;
}
break;
case 17:
if (HttpHeaders.TRANSFER_ENCODING == name) {
if (HttpHeaders.transferEncodingHeader == name) {
_addTransferEncoding(name, value);
return;
}
if (HttpHeaders.IF_MODIFIED_SINCE == name) {
if (HttpHeaders.ifModifiedSinceHeader == name) {
_addIfModifiedSince(name, value);
return;
}
@ -345,7 +345,7 @@ class _HttpHeaders implements HttpHeaders {
if (value == "chunked") {
chunkedTransferEncoding = true;
} else {
_addValue(HttpHeaders.TRANSFER_ENCODING, value);
_addValue(HttpHeaders.transferEncodingHeader, value);
}
}
@ -353,7 +353,7 @@ class _HttpHeaders implements HttpHeaders {
if (value is DateTime) {
date = value;
} else if (value is String) {
_set(HttpHeaders.DATE, value);
_set(HttpHeaders.dateHeader, value);
} else {
throw new HttpException("Unexpected type for header named $name");
}
@ -363,7 +363,7 @@ class _HttpHeaders implements HttpHeaders {
if (value is DateTime) {
expires = value;
} else if (value is String) {
_set(HttpHeaders.EXPIRES, value);
_set(HttpHeaders.expiresHeader, value);
} else {
throw new HttpException("Unexpected type for header named $name");
}
@ -373,7 +373,7 @@ class _HttpHeaders implements HttpHeaders {
if (value is DateTime) {
ifModifiedSince = value;
} else if (value is String) {
_set(HttpHeaders.IF_MODIFIED_SINCE, value);
_set(HttpHeaders.ifModifiedSinceHeader, value);
} else {
throw new HttpException("Unexpected type for header named $name");
}
@ -384,7 +384,7 @@ class _HttpHeaders implements HttpHeaders {
int pos = value.indexOf(":");
if (pos == -1) {
_host = value;
_port = HttpClient.DEFAULT_HTTP_PORT;
_port = HttpClient.defaultHttpPort;
} else {
if (pos > 0) {
_host = value.substring(0, pos);
@ -392,7 +392,7 @@ class _HttpHeaders implements HttpHeaders {
_host = null;
}
if (pos + 1 == value.length) {
_port = HttpClient.DEFAULT_HTTP_PORT;
_port = HttpClient.defaultHttpPort;
} else {
try {
_port = int.parse(value.substring(pos + 1));
@ -401,7 +401,7 @@ class _HttpHeaders implements HttpHeaders {
}
}
}
_set(HttpHeaders.HOST, value);
_set(HttpHeaders.hostHeader, value);
} else {
throw new HttpException("Unexpected type for header named $name");
}
@ -418,7 +418,7 @@ class _HttpHeaders implements HttpHeaders {
}
void _addContentType(String name, value) {
_set(HttpHeaders.CONTENT_TYPE, value);
_set(HttpHeaders.contentTypeHeader, value);
}
void _addValue(String name, Object value) {
@ -453,7 +453,7 @@ class _HttpHeaders implements HttpHeaders {
}
_foldHeader(String name) {
if (name == HttpHeaders.SET_COOKIE ||
if (name == HttpHeaders.setCookieHeader ||
(_noFoldingHeaders != null && _noFoldingHeaders.indexOf(name) != -1)) {
return false;
}
@ -577,7 +577,7 @@ class _HttpHeaders implements HttpHeaders {
}
}
List<String> values = _headers[HttpHeaders.COOKIE];
List<String> values = _headers[HttpHeaders.cookieHeader];
if (values != null) {
values.forEach((headerValue) => parseCookieString(headerValue));
}

View file

@ -311,7 +311,7 @@ class _HttpClientResponse extends _HttpInboundMessage
List<Cookie> get cookies {
if (_cookies != null) return _cookies;
_cookies = new List<Cookie>();
List<String> values = headers[HttpHeaders.SET_COOKIE];
List<String> values = headers[HttpHeaders.setCookieHeader];
if (values != null) {
values.forEach((value) {
_cookies.add(new Cookie.fromSetCookieValue(value));
@ -322,12 +322,12 @@ class _HttpClientResponse extends _HttpInboundMessage
bool get isRedirect {
if (_httpRequest.method == "GET" || _httpRequest.method == "HEAD") {
return statusCode == HttpStatus.MOVED_PERMANENTLY ||
statusCode == HttpStatus.FOUND ||
statusCode == HttpStatus.SEE_OTHER ||
statusCode == HttpStatus.TEMPORARY_REDIRECT;
return statusCode == HttpStatus.movedPermanently ||
statusCode == HttpStatus.found ||
statusCode == HttpStatus.seeOther ||
statusCode == HttpStatus.temporaryRedirect;
} else if (_httpRequest.method == "POST") {
return statusCode == HttpStatus.SEE_OTHER;
return statusCode == HttpStatus.seeOther;
}
return false;
}
@ -336,14 +336,14 @@ class _HttpClientResponse extends _HttpInboundMessage
[String method, Uri url, bool followLoops]) {
if (method == null) {
// Set method as defined by RFC 2616 section 10.3.4.
if (statusCode == HttpStatus.SEE_OTHER && _httpRequest.method == "POST") {
if (statusCode == HttpStatus.seeOther && _httpRequest.method == "POST") {
method = "GET";
} else {
method = _httpRequest.method;
}
}
if (url == null) {
String location = headers.value(HttpHeaders.LOCATION);
String location = headers.value(HttpHeaders.locationHeader);
if (location == null) {
throw new StateError("Response has no Location header for redirect");
}
@ -378,8 +378,8 @@ class _HttpClientResponse extends _HttpInboundMessage
}
Stream<List<int>> stream = _incoming;
if (_httpClient.autoUncompress &&
headers.value(HttpHeaders.CONTENT_ENCODING) == "gzip") {
stream = stream.transform(GZIP.decoder);
headers.value(HttpHeaders.contentEncodingHeader) == "gzip") {
stream = stream.transform(gzip.decoder);
}
return stream.listen(onData,
onError: onError, onDone: onDone, cancelOnError: cancelOnError);
@ -394,16 +394,16 @@ class _HttpClientResponse extends _HttpInboundMessage
bool get _shouldAuthenticateProxy {
// Only try to authenticate if there is a challenge in the response.
List<String> challenge = headers[HttpHeaders.PROXY_AUTHENTICATE];
return statusCode == HttpStatus.PROXY_AUTHENTICATION_REQUIRED &&
List<String> challenge = headers[HttpHeaders.proxyAuthenticateHeader];
return statusCode == HttpStatus.proxyAuthenticationRequired &&
challenge != null &&
challenge.length == 1;
}
bool get _shouldAuthenticate {
// Only try to authenticate if there is a challenge in the response.
List<String> challenge = headers[HttpHeaders.WWW_AUTHENTICATE];
return statusCode == HttpStatus.UNAUTHORIZED &&
List<String> challenge = headers[HttpHeaders.wwwAuthenticateHeader];
return statusCode == HttpStatus.unauthorized &&
challenge != null &&
challenge.length == 1;
}
@ -421,8 +421,8 @@ class _HttpClientResponse extends _HttpInboundMessage
List<String> authChallenge() {
return proxyAuth
? headers[HttpHeaders.PROXY_AUTHENTICATE]
: headers[HttpHeaders.WWW_AUTHENTICATE];
? headers[HttpHeaders.proxyAuthenticateHeader]
: headers[HttpHeaders.wwwAuthenticateHeader];
}
_Credentials findCredentials(_AuthenticationScheme scheme) {
@ -722,8 +722,8 @@ abstract class _HttpOutboundMessage<T> extends _IOSinkImpl {
: _uri = uri,
headers = new _HttpHeaders(protocolVersion,
defaultPortForScheme: uri.scheme == 'https'
? HttpClient.DEFAULT_HTTPS_PORT
: HttpClient.DEFAULT_HTTP_PORT,
? HttpClient.defaultHttpsPort
: HttpClient.defaultHttpPort,
initialHeaders: initialHeaders),
_outgoing = outgoing,
super(outgoing, null) {
@ -812,7 +812,7 @@ class _HttpResponse extends _HttpOutboundMessage<HttpResponse>
_reasonPhrase = reasonPhrase;
}
Future redirect(Uri location, {int status: HttpStatus.MOVED_TEMPORARILY}) {
Future redirect(Uri location, {int status: HttpStatus.movedTemporarily}) {
if (_outgoing.headersWritten) throw new StateError("Header already sent");
statusCode = status;
headers.set("location", location.toString());
@ -895,7 +895,7 @@ class _HttpResponse extends _HttpOutboundMessage<HttpResponse>
// Add all the cookies set to the headers.
if (_cookies != null) {
_cookies.forEach((cookie) {
headers.add(HttpHeaders.SET_COOKIE, cookie);
headers.add(HttpHeaders.setCookieHeader, cookie);
});
}
@ -915,85 +915,85 @@ class _HttpResponse extends _HttpOutboundMessage<HttpResponse>
}
switch (statusCode) {
case HttpStatus.CONTINUE:
case HttpStatus.continue_:
return "Continue";
case HttpStatus.SWITCHING_PROTOCOLS:
case HttpStatus.switchingProtocols:
return "Switching Protocols";
case HttpStatus.OK:
case HttpStatus.ok:
return "OK";
case HttpStatus.CREATED:
case HttpStatus.created:
return "Created";
case HttpStatus.ACCEPTED:
case HttpStatus.accepted:
return "Accepted";
case HttpStatus.NON_AUTHORITATIVE_INFORMATION:
case HttpStatus.nonAuthoritativeInformation:
return "Non-Authoritative Information";
case HttpStatus.NO_CONTENT:
case HttpStatus.noContent:
return "No Content";
case HttpStatus.RESET_CONTENT:
case HttpStatus.resetContent:
return "Reset Content";
case HttpStatus.PARTIAL_CONTENT:
case HttpStatus.partialContent:
return "Partial Content";
case HttpStatus.MULTIPLE_CHOICES:
case HttpStatus.multipleChoices:
return "Multiple Choices";
case HttpStatus.MOVED_PERMANENTLY:
case HttpStatus.movedPermanently:
return "Moved Permanently";
case HttpStatus.FOUND:
case HttpStatus.found:
return "Found";
case HttpStatus.SEE_OTHER:
case HttpStatus.seeOther:
return "See Other";
case HttpStatus.NOT_MODIFIED:
case HttpStatus.notModified:
return "Not Modified";
case HttpStatus.USE_PROXY:
case HttpStatus.useProxy:
return "Use Proxy";
case HttpStatus.TEMPORARY_REDIRECT:
case HttpStatus.temporaryRedirect:
return "Temporary Redirect";
case HttpStatus.BAD_REQUEST:
case HttpStatus.badRequest:
return "Bad Request";
case HttpStatus.UNAUTHORIZED:
case HttpStatus.unauthorized:
return "Unauthorized";
case HttpStatus.PAYMENT_REQUIRED:
case HttpStatus.paymentRequired:
return "Payment Required";
case HttpStatus.FORBIDDEN:
case HttpStatus.forbidden:
return "Forbidden";
case HttpStatus.NOT_FOUND:
case HttpStatus.notFound:
return "Not Found";
case HttpStatus.METHOD_NOT_ALLOWED:
case HttpStatus.methodNotAllowed:
return "Method Not Allowed";
case HttpStatus.NOT_ACCEPTABLE:
case HttpStatus.notAcceptable:
return "Not Acceptable";
case HttpStatus.PROXY_AUTHENTICATION_REQUIRED:
case HttpStatus.proxyAuthenticationRequired:
return "Proxy Authentication Required";
case HttpStatus.REQUEST_TIMEOUT:
case HttpStatus.requestTimeout:
return "Request Time-out";
case HttpStatus.CONFLICT:
case HttpStatus.conflict:
return "Conflict";
case HttpStatus.GONE:
case HttpStatus.gone:
return "Gone";
case HttpStatus.LENGTH_REQUIRED:
case HttpStatus.lengthRequired:
return "Length Required";
case HttpStatus.PRECONDITION_FAILED:
case HttpStatus.preconditionFailed:
return "Precondition Failed";
case HttpStatus.REQUEST_ENTITY_TOO_LARGE:
case HttpStatus.requestEntityTooLarge:
return "Request Entity Too Large";
case HttpStatus.REQUEST_URI_TOO_LONG:
return "Request-URI Too Large";
case HttpStatus.UNSUPPORTED_MEDIA_TYPE:
case HttpStatus.requestUriTooLong:
return "Request-URI Too Long";
case HttpStatus.unsupportedMediaType:
return "Unsupported Media Type";
case HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE:
case HttpStatus.requestedRangeNotSatisfiable:
return "Requested range not satisfiable";
case HttpStatus.EXPECTATION_FAILED:
case HttpStatus.expectationFailed:
return "Expectation Failed";
case HttpStatus.INTERNAL_SERVER_ERROR:
case HttpStatus.internalServerError:
return "Internal Server Error";
case HttpStatus.NOT_IMPLEMENTED:
case HttpStatus.notImplemented:
return "Not Implemented";
case HttpStatus.BAD_GATEWAY:
case HttpStatus.badGateway:
return "Bad Gateway";
case HttpStatus.SERVICE_UNAVAILABLE:
case HttpStatus.serviceUnavailable:
return "Service Unavailable";
case HttpStatus.GATEWAY_TIMEOUT:
case HttpStatus.gatewayTimeout:
return "Gateway Time-out";
case HttpStatus.HTTP_VERSION_NOT_SUPPORTED:
case HttpStatus.httpVersionNotSupported:
return "Http Version not supported";
default:
return "Status $statusCode";
@ -1146,7 +1146,7 @@ class _HttpClientRequest extends _HttpOutboundMessage<HttpClientResponse>
if (i > 0) sb.write("; ");
sb..write(cookies[i].name)..write("=")..write(cookies[i].value);
}
headers.add(HttpHeaders.COOKIE, sb.toString());
headers.add(HttpHeaders.cookieHeader, sb.toString());
}
headers._finalize();
@ -1253,14 +1253,14 @@ class _HttpOutgoing implements StreamConsumer<List<int>> {
outbound.bufferOutput &&
outbound.headers.chunkedTransferEncoding) {
List acceptEncodings =
response._httpRequest.headers[HttpHeaders.ACCEPT_ENCODING];
List contentEncoding = outbound.headers[HttpHeaders.CONTENT_ENCODING];
response._httpRequest.headers[HttpHeaders.acceptEncodingHeader];
List contentEncoding = outbound.headers[HttpHeaders.contentEncodingHeader];
if (acceptEncodings != null &&
acceptEncodings
.expand((list) => list.split(","))
.any((encoding) => encoding.trim().toLowerCase() == "gzip") &&
contentEncoding == null) {
outbound.headers.set(HttpHeaders.CONTENT_ENCODING, "gzip");
outbound.headers.set(HttpHeaders.contentEncodingHeader, "gzip");
gzip = true;
}
}
@ -1650,7 +1650,7 @@ class _HttpClientConnection {
request.headers
..host = host
..port = port
.._add(HttpHeaders.ACCEPT_ENCODING, "gzip");
.._add(HttpHeaders.acceptEncodingHeader, "gzip");
if (_httpClient.userAgent != null) {
request.headers._add('user-agent', _httpClient.userAgent);
}
@ -1659,7 +1659,7 @@ class _HttpClientConnection {
// for proxy basic authorization.
String auth = _CryptoUtils
.bytesToBase64(utf8.encode("${proxy.username}:${proxy.password}"));
request.headers.set(HttpHeaders.PROXY_AUTHORIZATION, "Basic $auth");
request.headers.set(HttpHeaders.proxyAuthorizationHeader, "Basic $auth");
} else if (!proxy.isDirect && _httpClient._proxyCredentials.length > 0) {
proxyCreds = _httpClient._findProxyCredentials(proxy);
if (proxyCreds != null) {
@ -1670,7 +1670,7 @@ class _HttpClientConnection {
// If the URL contains user information use that for basic
// authorization.
String auth = _CryptoUtils.bytesToBase64(utf8.encode(uri.userInfo));
request.headers.set(HttpHeaders.AUTHORIZATION, "Basic $auth");
request.headers.set(HttpHeaders.authorizationHeader, "Basic $auth");
} else {
// Look for credentials.
creds = _httpClient._findCredentials(uri);
@ -1779,10 +1779,10 @@ class _HttpClientConnection {
// for proxy basic authorization.
String auth = _CryptoUtils
.bytesToBase64(utf8.encode("${proxy.username}:${proxy.password}"));
request.headers.set(HttpHeaders.PROXY_AUTHORIZATION, "Basic $auth");
request.headers.set(HttpHeaders.proxyAuthorizationHeader, "Basic $auth");
}
return request.close().then((response) {
if (response.statusCode != HttpStatus.OK) {
if (response.statusCode != HttpStatus.ok) {
throw "Proxy failed to establish tunnel "
"(${response.statusCode} ${response.reasonPhrase})";
}
@ -1927,7 +1927,7 @@ class _ConnectionTarget {
_connecting++;
return socketFuture.then((socket) {
_connecting--;
socket.setOption(SocketOption.TCP_NODELAY, true);
socket.setOption(SocketOption.tcpNoDelay, true);
var connection =
new _HttpClientConnection(key, socket, client, false, context);
if (isSecure && !proxy.isDirect) {
@ -2101,8 +2101,8 @@ class _HttpClient implements HttpClient {
int port = uri.port;
if (port == 0) {
port = isSecure
? HttpClient.DEFAULT_HTTPS_PORT
: HttpClient.DEFAULT_HTTP_PORT;
? HttpClient.defaultHttpsPort
: HttpClient.defaultHttpPort;
}
// Check to see if a proxy server should be used for this connection.
var proxyConf = const _ProxyConfiguration.direct();
@ -2541,7 +2541,7 @@ class _HttpServer extends Stream<HttpRequest>
static HttpHeaders _initDefaultResponseHeaders() {
var defaultResponseHeaders = new _HttpHeaders('1.1');
defaultResponseHeaders.contentType = ContentType.TEXT;
defaultResponseHeaders.contentType = ContentType.text;
defaultResponseHeaders.set('X-Frame-Options', 'SAMEORIGIN');
defaultResponseHeaders.set('X-Content-Type-Options', 'nosniff');
defaultResponseHeaders.set('X-XSS-Protection', '1; mode=block');
@ -2572,7 +2572,7 @@ class _HttpServer extends Stream<HttpRequest>
StreamSubscription<HttpRequest> listen(void onData(HttpRequest event),
{Function onError, void onDone(), bool cancelOnError}) {
_serverSocket.listen((Socket socket) {
socket.setOption(SocketOption.TCP_NODELAY, true);
socket.setOption(SocketOption.tcpNoDelay, true);
// Accept the client connection.
_HttpConnection connection = new _HttpConnection(socket, this);
_idleConnections.add(connection);
@ -2974,8 +2974,8 @@ class _SiteCredentials extends _Credentials {
if (scheme != null && credentials.scheme != scheme) return false;
if (uri.host != this.uri.host) return false;
int thisPort =
this.uri.port == 0 ? HttpClient.DEFAULT_HTTP_PORT : this.uri.port;
int otherPort = uri.port == 0 ? HttpClient.DEFAULT_HTTP_PORT : uri.port;
this.uri.port == 0 ? HttpClient.defaultHttpPort: this.uri.port;
int otherPort = uri.port == 0 ? HttpClient.defaultHttpPort: uri.port;
if (otherPort != thisPort) return false;
return uri.path.startsWith(this.uri.path);
}
@ -3041,11 +3041,11 @@ class _HttpClientBasicCredentials extends _HttpClientCredentials
}
void authorize(_Credentials _, HttpClientRequest request) {
request.headers.set(HttpHeaders.AUTHORIZATION, authorization());
request.headers.set(HttpHeaders.authorizationHeader, authorization());
}
void authorizeProxy(_ProxyCredentials _, HttpClientRequest request) {
request.headers.set(HttpHeaders.PROXY_AUTHORIZATION, authorization());
request.headers.set(HttpHeaders.proxyAuthorizationHeader, authorization());
}
}
@ -3114,13 +3114,13 @@ class _HttpClientDigestCredentials extends _HttpClientCredentials
void authorize(_Credentials credentials, HttpClientRequest request) {
request.headers
.set(HttpHeaders.AUTHORIZATION, authorization(credentials, request));
.set(HttpHeaders.authorizationHeader, authorization(credentials, request));
}
void authorizeProxy(
_ProxyCredentials credentials, HttpClientRequest request) {
request.headers.set(
HttpHeaders.PROXY_AUTHORIZATION, authorization(credentials, request));
HttpHeaders.proxyAuthorizationHeader, authorization(credentials, request));
}
}

View file

@ -666,8 +666,8 @@ class _HttpParser extends Stream<_HttpIncoming> {
List<String> tokens = _tokenizeFieldValue(headerValue);
final bool isResponse = _messageType == _MessageType.RESPONSE;
final bool isUpgradeCode =
(_statusCode == HttpStatus.UPGRADE_REQUIRED) ||
(_statusCode == HttpStatus.SWITCHING_PROTOCOLS);
(_statusCode == HttpStatus.upgradeRequired) ||
(_statusCode == HttpStatus.switchingProtocols);
for (int i = 0; i < tokens.length; i++) {
final bool isUpgrade = _caseInsensitiveCompare(
"upgrade".codeUnits, tokens[i].codeUnits);

View file

@ -8,19 +8,46 @@ part of dart._http;
* WebSocket status codes used when closing a WebSocket connection.
*/
abstract class WebSocketStatus {
static const int NORMAL_CLOSURE = 1000;
static const int GOING_AWAY = 1001;
static const int PROTOCOL_ERROR = 1002;
static const int UNSUPPORTED_DATA = 1003;
static const int RESERVED_1004 = 1004;
static const int NO_STATUS_RECEIVED = 1005;
static const int ABNORMAL_CLOSURE = 1006;
static const int INVALID_FRAME_PAYLOAD_DATA = 1007;
static const int POLICY_VIOLATION = 1008;
static const int MESSAGE_TOO_BIG = 1009;
static const int MISSING_MANDATORY_EXTENSION = 1010;
static const int INTERNAL_SERVER_ERROR = 1011;
static const int RESERVED_1015 = 1015;
static const int normalClosure = 1000;
static const int goingAway = 1001;
static const int protocolError = 1002;
static const int unsupportedData = 1003;
static const int reserved1004 = 1004;
static const int noStatusReceived = 1005;
static const int abnormalClosure = 1006;
static const int invalidFramePayloadData = 1007;
static const int policyViolation = 1008;
static const int messageTooBig = 1009;
static const int missingMandatoryExtension = 1010;
static const int internalServerError = 1011;
static const int reserved1015 = 1015;
@Deprecated("Use normalClosure instead")
static const int NORMAL_CLOSURE = normalClosure;
@Deprecated("Use goingAway instead")
static const int GOING_AWAY = goingAway;
@Deprecated("Use protocolError instead")
static const int PROTOCOL_ERROR = protocolError;
@Deprecated("Use unsupportedData instead")
static const int UNSUPPORTED_DATA = unsupportedData;
@Deprecated("Use reserved1004 instead")
static const int RESERVED_1004 = reserved1004;
@Deprecated("Use noStatusReceived instead")
static const int NO_STATUS_RECEIVED = noStatusReceived;
@Deprecated("Use abnormalClosure instead")
static const int ABNORMAL_CLOSURE = abnormalClosure;
@Deprecated("Use invalidFramePayloadData instead")
static const int INVALID_FRAME_PAYLOAD_DATA = invalidFramePayloadData;
@Deprecated("Use policyViolation instead")
static const int POLICY_VIOLATION = policyViolation;
@Deprecated("Use messageTooBig instead")
static const int MESSAGE_TOO_BIG = messageTooBig;
@Deprecated("Use missingMandatoryExtension instead")
static const int MISSING_MANDATORY_EXTENSION = missingMandatoryExtension;
@Deprecated("Use internalServerError instead")
static const int INTERNAL_SERVER_ERROR = internalServerError;
@Deprecated("Use reserved1015 instead")
static const int RESERVED_1015 = reserved1015;
}
/**
@ -36,13 +63,18 @@ class CompressionOptions {
* clientMaxWindowBits: 15
* serverMaxWindowBits: 15
*/
static const CompressionOptions DEFAULT = const CompressionOptions();
static const CompressionOptions compressionDefault =
const CompressionOptions();
@Deprecated("Use compressionDefault instead")
static const CompressionOptions DEFAULT = compressionDefault;
/**
* Disables WebSocket Compression.
*/
static const CompressionOptions OFF =
static const CompressionOptions compressionOff =
const CompressionOptions(enabled: false);
@Deprecated("Use compressionOff instead")
static const CompressionOptions OFF = compressionOff;
/**
* Control whether the client will reuse it's compression instances.
@ -215,7 +247,7 @@ abstract class WebSocketTransformer
*/
factory WebSocketTransformer(
{/*String|Future<String>*/ protocolSelector(List<String> protocols),
CompressionOptions compression: CompressionOptions.DEFAULT}) {
CompressionOptions compression: CompressionOptions.compressionDefault}) {
return new _WebSocketTransformerImpl(protocolSelector, compression);
}
@ -238,7 +270,7 @@ abstract class WebSocketTransformer
*/
static Future<WebSocket> upgrade(HttpRequest request,
{protocolSelector(List<String> protocols),
CompressionOptions compression: CompressionOptions.DEFAULT}) {
CompressionOptions compression: CompressionOptions.compressionDefault}) {
return _WebSocketTransformerImpl._upgrade(
request, protocolSelector, compression);
}
@ -264,10 +296,19 @@ abstract class WebSocket
/**
* Possible states of the connection.
*/
static const int CONNECTING = 0;
static const int OPEN = 1;
static const int CLOSING = 2;
static const int CLOSED = 3;
static const int connecting = 0;
static const int open = 1;
static const int closing = 2;
static const int closed = 3;
@Deprecated("Use connecting instead")
static const int CONNECTING = connecting;
@Deprecated("Use open instead")
static const int OPEN = open;
@Deprecated("Use closing instead")
static const int CLOSING = closing;
@Deprecated("Use closed instead")
static const int CLOSED = closed;
/**
* Set and get the interval for sending ping signals. If a ping message is not
@ -315,7 +356,8 @@ abstract class WebSocket
static Future<WebSocket> connect(String url,
{Iterable<String> protocols,
Map<String, dynamic> headers,
CompressionOptions compression: CompressionOptions.DEFAULT}) =>
CompressionOptions compression:
CompressionOptions.compressionDefault}) =>
_WebSocketImpl.connect(url, protocols, headers, compression: compression);
@Deprecated('This constructor will be removed in Dart 2.0. Use `implements`'
@ -344,7 +386,7 @@ abstract class WebSocket
factory WebSocket.fromUpgradedSocket(Socket socket,
{String protocol,
bool serverSide,
CompressionOptions compression: CompressionOptions.DEFAULT}) {
CompressionOptions compression: CompressionOptions.compressionDefault}) {
if (serverSide == null) {
throw new ArgumentError("The serverSide argument must be passed "
"explicitly to WebSocket.fromUpgradedSocket.");

View file

@ -449,7 +449,7 @@ class _WebSocketTransformerImpl
if (!_isUpgradeRequest(request)) {
// Send error response.
response
..statusCode = HttpStatus.BAD_REQUEST
..statusCode = HttpStatus.badRequest
..close();
return new Future.error(
new WebSocketException("Invalid WebSocket upgrade request"));
@ -458,9 +458,9 @@ class _WebSocketTransformerImpl
Future<WebSocket> upgrade(String protocol) {
// Send the upgrade response.
response
..statusCode = HttpStatus.SWITCHING_PROTOCOLS
..headers.add(HttpHeaders.CONNECTION, "Upgrade")
..headers.add(HttpHeaders.UPGRADE, "websocket");
..statusCode = HttpStatus.switchingProtocols
..headers.add(HttpHeaders.connectionHeader, "Upgrade")
..headers.add(HttpHeaders.upgradeHeader, "websocket");
String key = request.headers.value("Sec-WebSocket-Key");
_SHA1 sha1 = new _SHA1();
sha1.add("$key$_webSocketGUID".codeUnits);
@ -493,7 +493,7 @@ class _WebSocketTransformerImpl
return protocol;
}).catchError((error) {
response
..statusCode = HttpStatus.INTERNAL_SERVER_ERROR
..statusCode = HttpStatus.internalServerError
..close();
throw error;
}).then<WebSocket>(upgrade);
@ -536,15 +536,15 @@ class _WebSocketTransformerImpl
if (request.method != "GET") {
return false;
}
if (request.headers[HttpHeaders.CONNECTION] == null) {
if (request.headers[HttpHeaders.connectionHeader] == null) {
return false;
}
bool isUpgrade = false;
request.headers[HttpHeaders.CONNECTION].forEach((String value) {
request.headers[HttpHeaders.connectionHeader].forEach((String value) {
if (value.toLowerCase() == "upgrade") isUpgrade = true;
});
if (!isUpgrade) return false;
String upgrade = request.headers.value(HttpHeaders.UPGRADE);
String upgrade = request.headers.value(HttpHeaders.upgradeHeader);
if (upgrade == null || upgrade.toLowerCase() != "websocket") {
return false;
}
@ -964,7 +964,7 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket {
final _socket;
final bool _serverSide;
int _readyState = WebSocket.CONNECTING;
int _readyState = WebSocket.connecting;
bool _writeClosed = false;
int _closeCode;
String _closeReason;
@ -981,7 +981,7 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket {
static Future<WebSocket> connect(
String url, Iterable<String> protocols, Map<String, dynamic> headers,
{CompressionOptions compression: CompressionOptions.DEFAULT}) {
{CompressionOptions compression: CompressionOptions.compressionDefault}) {
Uri uri = Uri.parse(url);
if (uri.scheme != "ws" && uri.scheme != "wss") {
throw new WebSocketException("Unsupported URL scheme '${uri.scheme}'");
@ -1008,15 +1008,15 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket {
// If the URL contains user information use that for basic
// authorization.
String auth = _CryptoUtils.bytesToBase64(utf8.encode(uri.userInfo));
request.headers.set(HttpHeaders.AUTHORIZATION, "Basic $auth");
request.headers.set(HttpHeaders.authorizationHeader, "Basic $auth");
}
if (headers != null) {
headers.forEach((field, value) => request.headers.add(field, value));
}
// Setup the initial handshake.
request.headers
..set(HttpHeaders.CONNECTION, "Upgrade")
..set(HttpHeaders.UPGRADE, "websocket")
..set(HttpHeaders.connectionHeader, "Upgrade")
..set(HttpHeaders.upgradeHeader, "websocket")
..set("Sec-WebSocket-Key", nonce)
..set("Cache-Control", "no-cache")
..set("Sec-WebSocket-Version", "13");
@ -1039,11 +1039,11 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket {
throw new WebSocketException(message);
}
if (response.statusCode != HttpStatus.SWITCHING_PROTOCOLS ||
response.headers[HttpHeaders.CONNECTION] == null ||
!response.headers[HttpHeaders.CONNECTION]
if (response.statusCode != HttpStatus.switchingProtocols ||
response.headers[HttpHeaders.connectionHeader] == null ||
!response.headers[HttpHeaders.connectionHeader]
.any((value) => value.toLowerCase() == "upgrade") ||
response.headers.value(HttpHeaders.UPGRADE).toLowerCase() !=
response.headers.value(HttpHeaders.upgradeHeader).toLowerCase() !=
"websocket") {
error("Connection to '$uri' was not upgraded to websocket");
}
@ -1114,7 +1114,7 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket {
[this._serverSide = false, _WebSocketPerMessageDeflate deflate]) {
_consumer = new _WebSocketConsumer(this, _socket);
_sink = new _StreamSinkImpl(_consumer);
_readyState = WebSocket.OPEN;
_readyState = WebSocket.open;
_deflate = deflate;
var transformer = new _WebSocketProtocolTransformer(_serverSide, _deflate);
@ -1140,14 +1140,14 @@ class _WebSocketImpl extends Stream with _ServiceObject implements WebSocket {
_controller.close();
}, onDone: () {
if (_closeTimer != null) _closeTimer.cancel();
if (_readyState == WebSocket.OPEN) {
_readyState = WebSocket.CLOSING;
if (_readyState == WebSocket.open) {
_readyState = WebSocket.closing;
if (!_isReservedStatusCode(transformer.closeCode)) {
_close(transformer.closeCode, transformer.closeReason);
} else {
_close();
}
_readyState = WebSocket.CLOSED;
_readyState = WebSocket.closed;
}
// Protocol close, use close code from transformer.
_closeCode = transformer.closeCode;

View file

@ -277,7 +277,7 @@ void testSimpleReadWrite(
client.writeEventsEnabled = true;
}
if (bytesWritten == data.length) {
client.shutdown(SocketDirection.SEND);
client.shutdown(SocketDirection.send);
}
break;
case RawSocketEvent.readClosed:

View file

@ -27,7 +27,7 @@ Uri pathOfData = Platform.script.resolve('http_launch_data/');
int port;
_sendNotFound(HttpResponse response) {
response.statusCode = HttpStatus.NOT_FOUND;
response.statusCode = HttpStatus.notFound;
response.close();
}
@ -94,5 +94,5 @@ checkResults(List<ProcessResult> results) {
}
main() {
HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0).then(serverRunning);
HttpServer.bind(InternetAddress.loopbackIPv4, 0).then(serverRunning);
}

View file

@ -185,7 +185,7 @@ testSameDVI(String tmpDirPath) {
var renewLMHashCmd = r"\renewcommand{\LMHash}[1]{\OriginalLMHash{xxxx}}";
new File(styPath)
.copySync(tmpStyPath)
.writeAsStringSync(renewLMHashCmd, mode: FileMode.APPEND);
.writeAsStringSync(renewLMHashCmd, mode: FileMode.append);
new File(specPath).copySync(tmpSpecPath);
checkAction(runAddHash(), "addlatexhash.dart failed");

View file

@ -106,7 +106,7 @@ class TestServer {
// Return a 404.
void _notFoundHandler(HttpRequest request) {
var response = request.response;
response.statusCode = HttpStatus.NOT_FOUND;
response.statusCode = HttpStatus.notFound;
response.headers.set("Content-Type", "text/html; charset=UTF-8");
response.write("Page not found");
response.close();
@ -119,7 +119,7 @@ class TestServer {
Expect.equals("www.dartlang.org:1234", request.headers["Host"][0]);
Expect.equals("www.dartlang.org", request.headers.host);
Expect.equals(1234, request.headers.port);
response.statusCode = HttpStatus.OK;
response.statusCode = HttpStatus.ok;
response.close();
}
@ -161,7 +161,7 @@ class TestServer {
Expect.equals("utf-8", request.headers.contentType.parameters["charset"]);
response.headers
.set(HttpHeaders.CONTENT_TYPE, "text/html; charset = utf-8");
.set(HttpHeaders.contentTypeHeader, "text/html; charset = utf-8");
response.close();
}
@ -260,21 +260,21 @@ Future testHost() {
request.headers.port = 1234;
Expect.equals("www.dartlang.com:1234", request.headers["host"][0]);
Expect.equals(1234, request.headers.port);
request.headers.port = HttpClient.DEFAULT_HTTP_PORT;
Expect.equals(HttpClient.DEFAULT_HTTP_PORT, request.headers.port);
request.headers.port = HttpClient.defaultHttpPort;
Expect.equals(HttpClient.defaultHttpPort, request.headers.port);
Expect.equals("www.dartlang.com", request.headers["host"][0]);
request.headers.set("Host", "www.dartlang.org");
Expect.equals("www.dartlang.org", request.headers.host);
Expect.equals(HttpClient.DEFAULT_HTTP_PORT, request.headers.port);
Expect.equals(HttpClient.defaultHttpPort, request.headers.port);
request.headers.set("Host", "www.dartlang.org:");
Expect.equals("www.dartlang.org", request.headers.host);
Expect.equals(HttpClient.DEFAULT_HTTP_PORT, request.headers.port);
Expect.equals(HttpClient.defaultHttpPort, request.headers.port);
request.headers.set("Host", "www.dartlang.org:1234");
Expect.equals("www.dartlang.org", request.headers.host);
Expect.equals(1234, request.headers.port);
return request.close();
}).then((response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
response.listen((_) {}, onDone: () {
httpClient.close();
server.shutdown();
@ -294,7 +294,7 @@ Future testExpires() {
HttpClient httpClient = new HttpClient();
void processResponse(HttpClientResponse response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
Expect.equals(
"Fri, 11 Jun 1999 18:46:53 GMT", response.headers["expires"][0]);
Expect.equals(new DateTime.utc(1999, DateTime.june, 11, 18, 46, 53, 0),
@ -330,7 +330,7 @@ Future testContentType() {
HttpClient httpClient = new HttpClient();
void processResponse(HttpClientResponse response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
Expect.equals(
"text/html; charset=utf-8", response.headers.contentType.toString());
Expect.equals("text/html", response.headers.contentType.value);
@ -356,7 +356,7 @@ Future testContentType() {
httpClient.get("127.0.0.1", port, "/contenttype2").then((request) {
request.headers
.set(HttpHeaders.CONTENT_TYPE, "text/html; charset = utf-8");
.set(HttpHeaders.contentTypeHeader, "text/html; charset = utf-8");
return request.close();
}).then(processResponse);
});

View file

@ -38,7 +38,7 @@ class Server {
server = s;
server.listen((HttpRequest request) {
sendUnauthorizedResponse(HttpResponse response, {stale: false}) {
response.statusCode = HttpStatus.UNAUTHORIZED;
response.statusCode = HttpStatus.unauthorized;
StringBuffer authHeader = new StringBuffer();
authHeader.write('Digest');
authHeader.write(', realm="$realm"');
@ -49,14 +49,16 @@ class Server {
}
authHeader.write(', domain="/digest/"');
if (serverQop != null) authHeader.write(', qop="$serverQop"');
response.headers.set(HttpHeaders.WWW_AUTHENTICATE, authHeader);
response.headers.set(HttpHeaders.wwwAuthenticateHeader, authHeader);
unauthCount++;
}
var response = request.response;
if (request.headers[HttpHeaders.AUTHORIZATION] != null) {
Expect.equals(1, request.headers[HttpHeaders.AUTHORIZATION].length);
String authorization = request.headers[HttpHeaders.AUTHORIZATION][0];
if (request.headers[HttpHeaders.authorizationHeader] != null) {
Expect.equals(
1, request.headers[HttpHeaders.authorizationHeader].length);
String authorization =
request.headers[HttpHeaders.authorizationHeader][0];
HeaderValue header =
HeaderValue.parse(authorization, parameterSeparator: ",");
if (header.value.toLowerCase() == "basic") {
@ -152,7 +154,7 @@ void testNoCredentials(String algorithm, String qop) {
.getUrl(url)
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) {
Expect.equals(HttpStatus.UNAUTHORIZED, response.statusCode);
Expect.equals(HttpStatus.unauthorized, response.statusCode);
return response.fold(null, (x, y) {});
});
}
@ -178,7 +180,7 @@ void testCredentials(String algorithm, String qop) {
.getUrl(url)
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
Expect.equals(1, response.headers["Authentication-Info"].length);
return response.fold(null, (x, y) {});
});
@ -224,7 +226,7 @@ void testAuthenticateCallback(String algorithm, String qop) {
.getUrl(url)
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
Expect.equals(1, response.headers["Authentication-Info"].length);
return response.fold(null, (x, y) {});
});
@ -251,7 +253,7 @@ void testStaleNonce() {
.getUrl(url)
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
Expect.equals(1, response.headers["Authentication-Info"].length);
return response.fold(null, (x, y) {});
});
@ -285,7 +287,7 @@ void testNextNonce() {
.getUrl(url)
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
Expect.equals(1, response.headers["Authentication-Info"].length);
return response.fold(null, (x, y) {});
});
@ -339,7 +341,7 @@ void testLocalServerDigest() {
.then((HttpClientResponse response) {
count++;
if (count % 100 == 0) print(count);
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
return response.fold(null, (x, y) {});
});
}

View file

@ -36,23 +36,25 @@ class Server {
password = request.uri.path.substring(1, 6);
}
if (passwordChanged) password = "${password}1";
if (request.headers[HttpHeaders.AUTHORIZATION] != null) {
Expect.equals(1, request.headers[HttpHeaders.AUTHORIZATION].length);
String authorization = request.headers[HttpHeaders.AUTHORIZATION][0];
if (request.headers[HttpHeaders.authorizationHeader] != null) {
Expect.equals(
1, request.headers[HttpHeaders.authorizationHeader].length);
String authorization =
request.headers[HttpHeaders.authorizationHeader][0];
List<String> tokens = authorization.split(" ");
Expect.equals("Basic", tokens[0]);
String auth = base64.encode(utf8.encode("$username:$password"));
if (passwordChanged && auth != tokens[1]) {
response.statusCode = HttpStatus.UNAUTHORIZED;
response.statusCode = HttpStatus.unauthorized;
response.headers
.set(HttpHeaders.WWW_AUTHENTICATE, "Basic, realm=realm");
.set(HttpHeaders.wwwAuthenticateHeader, "Basic, realm=realm");
} else {
Expect.equals(auth, tokens[1]);
}
} else {
response.statusCode = HttpStatus.UNAUTHORIZED;
response.statusCode = HttpStatus.unauthorized;
response.headers
.set(HttpHeaders.WWW_AUTHENTICATE, "Basic, realm=realm");
.set(HttpHeaders.wwwAuthenticateHeader, "Basic, realm=realm");
}
response.close();
});
@ -97,7 +99,7 @@ void testBasicNoCredentials() {
.getUrl(url)
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) {
Expect.equals(HttpStatus.UNAUTHORIZED, response.statusCode);
Expect.equals(HttpStatus.unauthorized, response.statusCode);
return response.fold(null, (x, y) {});
});
}
@ -125,7 +127,7 @@ void testBasicCredentials() {
.getUrl(url)
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
return response.fold(null, (x, y) {});
});
}
@ -174,7 +176,7 @@ void testBasicAuthenticateCallback() {
.getUrl(url)
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
return response.fold(null, (x, y) {});
});
}
@ -216,7 +218,7 @@ void testLocalServerBasic() {
.getUrl(Uri.parse("http://127.0.0.1/basic/test"))
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
response.fold(null, (x, y) {}).then((_) {
client.close();
});
@ -237,7 +239,7 @@ void testLocalServerDigest() {
.getUrl(Uri.parse("http://127.0.0.1/digest/test"))
.then((HttpClientRequest request) => request.close())
.then((HttpClientResponse response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
response.fold(null, (x, y) {}).then((_) {
client.close();
});

View file

@ -120,7 +120,7 @@ class TestServer {
// Return a 404.
void _notFoundHandler(HttpRequest request) {
var response = request.response;
response.statusCode = HttpStatus.NOT_FOUND;
response.statusCode = HttpStatus.notFound;
response.headers.set("Content-Type", "text/html; charset=UTF-8");
response.write("Page not found");
response.close();
@ -129,7 +129,7 @@ class TestServer {
// Return a 301 with a custom reason phrase.
void _reasonForMovingHandler(HttpRequest request) {
var response = request.response;
response.statusCode = HttpStatus.MOVED_PERMANENTLY;
response.statusCode = HttpStatus.movedPermanently;
response.reasonPhrase = "Don't come looking here any more";
response.close();
}
@ -141,7 +141,7 @@ class TestServer {
Expect.equals("www.dartlang.org:1234", request.headers["Host"][0]);
Expect.equals("www.dartlang.org", request.headers.host);
Expect.equals(1234, request.headers.port);
response.statusCode = HttpStatus.OK;
response.statusCode = HttpStatus.ok;
response.close();
}
@ -211,7 +211,7 @@ void testGET() {
.get("127.0.0.1", port, "/0123456789")
.then((request) => request.close())
.then((response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
StringBuffer body = new StringBuffer();
response.listen((data) => body.write(new String.fromCharCodes(data)),
onDone: () {
@ -244,7 +244,7 @@ void testPOST(bool chunkedEncoding) {
}
return request.close();
}).then((response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
StringBuffer body = new StringBuffer();
response.listen((data) => body.write(new String.fromCharCodes(data)),
onDone: () {
@ -275,7 +275,7 @@ void test404() {
.get("127.0.0.1", port, "/thisisnotfound")
.then((request) => request.close())
.then((response) {
Expect.equals(HttpStatus.NOT_FOUND, response.statusCode);
Expect.equals(HttpStatus.notFound, response.statusCode);
var body = new StringBuffer();
response.listen((data) => body.write(new String.fromCharCodes(data)),
onDone: () {
@ -296,7 +296,7 @@ void testReasonPhrase() {
request.followRedirects = false;
return request.close();
}).then((response) {
Expect.equals(HttpStatus.MOVED_PERMANENTLY, response.statusCode);
Expect.equals(HttpStatus.movedPermanently, response.statusCode);
Expect.equals("Don't come looking here any more", response.reasonPhrase);
response.listen((data) => Expect.fail("No data expected"), onDone: () {
httpClient.close();

View file

@ -22,11 +22,11 @@ void testServerCompress({bool clientAutoUncompress: true}) {
var client = new HttpClient();
client.autoUncompress = clientAutoUncompress;
client.get("127.0.0.1", server.port, "/").then((request) {
request.headers.set(HttpHeaders.ACCEPT_ENCODING, "gzip,deflate");
request.headers.set(HttpHeaders.acceptEncodingHeader, "gzip,deflate");
return request.close();
}).then((response) {
Expect.equals(
"gzip", response.headers.value(HttpHeaders.CONTENT_ENCODING));
"gzip", response.headers.value(HttpHeaders.contentEncodingHeader));
response.fold([], (list, b) {
list.addAll(b);
return list;
@ -34,7 +34,7 @@ void testServerCompress({bool clientAutoUncompress: true}) {
if (clientAutoUncompress) {
Expect.listEquals(data, list);
} else {
Expect.listEquals(data, GZIP.decode(list));
Expect.listEquals(data, gzip.decode(list));
}
server.close();
client.close();
@ -61,11 +61,13 @@ void testAcceptEncodingHeader() {
});
var client = new HttpClient();
client.get("127.0.0.1", server.port, "/").then((request) {
request.headers.set(HttpHeaders.ACCEPT_ENCODING, encoding);
request.headers.set(HttpHeaders.acceptEncodingHeader, encoding);
return request.close();
}).then((response) {
Expect.equals(valid,
("gzip" == response.headers.value(HttpHeaders.CONTENT_ENCODING)));
Expect.equals(
valid,
("gzip" ==
response.headers.value(HttpHeaders.contentEncodingHeader)));
response.listen((_) {}, onDone: () {
server.close();
client.close();
@ -92,7 +94,8 @@ void testDisableCompressTest() {
HttpServer.bind("127.0.0.1", 0).then((server) {
Expect.equals(false, server.autoCompress);
server.listen((request) {
Expect.equals('gzip', request.headers.value(HttpHeaders.ACCEPT_ENCODING));
Expect.equals(
'gzip', request.headers.value(HttpHeaders.acceptEncodingHeader));
request.response.write("data");
request.response.close();
});
@ -101,7 +104,8 @@ void testDisableCompressTest() {
.get("127.0.0.1", server.port, "/")
.then((request) => request.close())
.then((response) {
Expect.equals(null, response.headers.value(HttpHeaders.CONTENT_ENCODING));
Expect.equals(
null, response.headers.value(HttpHeaders.contentEncodingHeader));
response.listen((_) {}, onDone: () {
server.close();
client.close();

View file

@ -8,9 +8,9 @@ import "dart:isolate";
import "dart:io";
void setConnectionHeaders(HttpHeaders headers) {
headers.add(HttpHeaders.CONNECTION, "my-connection-header1");
headers.add(HttpHeaders.connectionHeader, "my-connection-header1");
headers.add("My-Connection-Header1", "some-value1");
headers.add(HttpHeaders.CONNECTION, "my-connection-header2");
headers.add(HttpHeaders.connectionHeader, "my-connection-header2");
headers.add("My-Connection-Header2", "some-value2");
}
@ -18,15 +18,15 @@ void checkExpectedConnectionHeaders(
HttpHeaders headers, bool persistentConnection) {
Expect.equals("some-value1", headers.value("My-Connection-Header1"));
Expect.equals("some-value2", headers.value("My-Connection-Header2"));
Expect.isTrue(headers[HttpHeaders.CONNECTION]
Expect.isTrue(headers[HttpHeaders.connectionHeader]
.any((value) => value.toLowerCase() == "my-connection-header1"));
Expect.isTrue(headers[HttpHeaders.CONNECTION]
Expect.isTrue(headers[HttpHeaders.connectionHeader]
.any((value) => value.toLowerCase() == "my-connection-header2"));
if (persistentConnection) {
Expect.equals(2, headers[HttpHeaders.CONNECTION].length);
Expect.equals(2, headers[HttpHeaders.connectionHeader].length);
} else {
Expect.equals(3, headers[HttpHeaders.CONNECTION].length);
Expect.isTrue(headers[HttpHeaders.CONNECTION]
Expect.equals(3, headers[HttpHeaders.connectionHeader].length);
Expect.isTrue(headers[HttpHeaders.connectionHeader]
.any((value) => value.toLowerCase() == "close"));
}
}

View file

@ -104,8 +104,8 @@ void testBody(int totalConnections, bool useHeader) {
if (useHeader) {
request.contentLength = 2;
} else {
request.headers.add(HttpHeaders.CONTENT_LENGTH, "7");
request.headers.add(HttpHeaders.CONTENT_LENGTH, "2");
request.headers.add(HttpHeaders.contentLengthHeader, "7");
request.headers.add(HttpHeaders.contentLengthHeader, "2");
}
request.write("x");
Expect.throws(
@ -165,8 +165,8 @@ void testBodyChunked(int totalConnections, bool useHeader) {
request.contentLength = 2;
request.headers.chunkedTransferEncoding = true;
} else {
request.headers.add(HttpHeaders.CONTENT_LENGTH, "2");
request.headers.set(HttpHeaders.TRANSFER_ENCODING, "chunked");
request.headers.add(HttpHeaders.contentLengthHeader, "2");
request.headers.set(HttpHeaders.transferEncodingHeader, "chunked");
}
request.write("x");
Expect.throws(() => request.headers.chunkedTransferEncoding = false,

View file

@ -25,7 +25,7 @@ void main(List<String> args) {
}
Future makeServer() {
return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) {
return HttpServer.bind(InternetAddress.loopbackIPv4, 0).then((server) {
server.listen((request) {
request.pipe(request.response);
});

View file

@ -23,39 +23,39 @@ part "../../../sdk/lib/_http/http_session.dart";
void testMultiValue() {
_HttpHeaders headers = new _HttpHeaders("1.1");
Expect.isNull(headers[HttpHeaders.PRAGMA]);
headers.add(HttpHeaders.PRAGMA, "pragma1");
Expect.equals(1, headers[HttpHeaders.PRAGMA].length);
Expect.isNull(headers[HttpHeaders.pragmaHeader]);
headers.add(HttpHeaders.pragmaHeader, "pragma1");
Expect.equals(1, headers[HttpHeaders.pragmaHeader].length);
Expect.equals(1, headers["pragma"].length);
Expect.equals(1, headers["Pragma"].length);
Expect.equals(1, headers["PRAGMA"].length);
Expect.equals("pragma1", headers.value(HttpHeaders.PRAGMA));
Expect.equals(1, headers["pragma"].length);
Expect.equals("pragma1", headers.value(HttpHeaders.pragmaHeader));
headers.add(HttpHeaders.PRAGMA, "pragma2");
Expect.equals(2, headers[HttpHeaders.PRAGMA].length);
headers.add(HttpHeaders.pragmaHeader, "pragma2");
Expect.equals(2, headers[HttpHeaders.pragmaHeader].length);
Expect.throws(
() => headers.value(HttpHeaders.PRAGMA), (e) => e is HttpException);
() => headers.value(HttpHeaders.pragmaHeader), (e) => e is HttpException);
headers.add(HttpHeaders.PRAGMA, ["pragma3", "pragma4"]);
headers.add(HttpHeaders.pragmaHeader, ["pragma3", "pragma4"]);
Expect.listEquals(["pragma1", "pragma2", "pragma3", "pragma4"],
headers[HttpHeaders.PRAGMA]);
headers[HttpHeaders.pragmaHeader]);
headers.remove(HttpHeaders.PRAGMA, "pragma3");
Expect.equals(3, headers[HttpHeaders.PRAGMA].length);
headers.remove(HttpHeaders.pragmaHeader, "pragma3");
Expect.equals(3, headers[HttpHeaders.pragmaHeader].length);
Expect.listEquals(
["pragma1", "pragma2", "pragma4"], headers[HttpHeaders.PRAGMA]);
["pragma1", "pragma2", "pragma4"], headers[HttpHeaders.pragmaHeader]);
headers.remove(HttpHeaders.PRAGMA, "pragma3");
Expect.equals(3, headers[HttpHeaders.PRAGMA].length);
headers.remove(HttpHeaders.pragmaHeader, "pragma3");
Expect.equals(3, headers[HttpHeaders.pragmaHeader].length);
headers.set(HttpHeaders.PRAGMA, "pragma5");
Expect.equals(1, headers[HttpHeaders.PRAGMA].length);
headers.set(HttpHeaders.pragmaHeader, "pragma5");
Expect.equals(1, headers[HttpHeaders.pragmaHeader].length);
headers.set(HttpHeaders.PRAGMA, ["pragma6", "pragma7"]);
Expect.equals(2, headers[HttpHeaders.PRAGMA].length);
headers.set(HttpHeaders.pragmaHeader, ["pragma6", "pragma7"]);
Expect.equals(2, headers[HttpHeaders.pragmaHeader].length);
headers.removeAll(HttpHeaders.PRAGMA);
Expect.isNull(headers[HttpHeaders.PRAGMA]);
headers.removeAll(HttpHeaders.pragmaHeader);
Expect.isNull(headers[HttpHeaders.pragmaHeader]);
}
void testDate() {
@ -68,19 +68,19 @@ void testDate() {
Expect.isNull(headers.date);
headers.date = date1;
Expect.equals(date1, headers.date);
Expect.equals(httpDate1, headers.value(HttpHeaders.DATE));
Expect.equals(1, headers[HttpHeaders.DATE].length);
headers.add(HttpHeaders.DATE, httpDate2);
Expect.equals(1, headers[HttpHeaders.DATE].length);
Expect.equals(httpDate1, headers.value(HttpHeaders.dateHeader));
Expect.equals(1, headers[HttpHeaders.dateHeader].length);
headers.add(HttpHeaders.dateHeader, httpDate2);
Expect.equals(1, headers[HttpHeaders.dateHeader].length);
Expect.equals(date2, headers.date);
Expect.equals(httpDate2, headers.value(HttpHeaders.DATE));
headers.set(HttpHeaders.DATE, httpDate1);
Expect.equals(1, headers[HttpHeaders.DATE].length);
Expect.equals(httpDate2, headers.value(HttpHeaders.dateHeader));
headers.set(HttpHeaders.dateHeader, httpDate1);
Expect.equals(1, headers[HttpHeaders.dateHeader].length);
Expect.equals(date1, headers.date);
Expect.equals(httpDate1, headers.value(HttpHeaders.DATE));
Expect.equals(httpDate1, headers.value(HttpHeaders.dateHeader));
headers.set(HttpHeaders.DATE, "xxx");
Expect.equals("xxx", headers.value(HttpHeaders.DATE));
headers.set(HttpHeaders.dateHeader, "xxx");
Expect.equals("xxx", headers.value(HttpHeaders.dateHeader));
Expect.equals(null, headers.date);
}
@ -94,19 +94,19 @@ void testExpires() {
Expect.isNull(headers.expires);
headers.expires = date1;
Expect.equals(date1, headers.expires);
Expect.equals(httpDate1, headers.value(HttpHeaders.EXPIRES));
Expect.equals(1, headers[HttpHeaders.EXPIRES].length);
headers.add(HttpHeaders.EXPIRES, httpDate2);
Expect.equals(1, headers[HttpHeaders.EXPIRES].length);
Expect.equals(httpDate1, headers.value(HttpHeaders.expiresHeader));
Expect.equals(1, headers[HttpHeaders.expiresHeader].length);
headers.add(HttpHeaders.expiresHeader, httpDate2);
Expect.equals(1, headers[HttpHeaders.expiresHeader].length);
Expect.equals(date2, headers.expires);
Expect.equals(httpDate2, headers.value(HttpHeaders.EXPIRES));
headers.set(HttpHeaders.EXPIRES, httpDate1);
Expect.equals(1, headers[HttpHeaders.EXPIRES].length);
Expect.equals(httpDate2, headers.value(HttpHeaders.expiresHeader));
headers.set(HttpHeaders.expiresHeader, httpDate1);
Expect.equals(1, headers[HttpHeaders.expiresHeader].length);
Expect.equals(date1, headers.expires);
Expect.equals(httpDate1, headers.value(HttpHeaders.EXPIRES));
Expect.equals(httpDate1, headers.value(HttpHeaders.expiresHeader));
headers.set(HttpHeaders.EXPIRES, "xxx");
Expect.equals("xxx", headers.value(HttpHeaders.EXPIRES));
headers.set(HttpHeaders.expiresHeader, "xxx");
Expect.equals("xxx", headers.value(HttpHeaders.expiresHeader));
Expect.equals(null, headers.expires);
}
@ -120,19 +120,19 @@ void testIfModifiedSince() {
Expect.isNull(headers.ifModifiedSince);
headers.ifModifiedSince = date1;
Expect.equals(date1, headers.ifModifiedSince);
Expect.equals(httpDate1, headers.value(HttpHeaders.IF_MODIFIED_SINCE));
Expect.equals(1, headers[HttpHeaders.IF_MODIFIED_SINCE].length);
headers.add(HttpHeaders.IF_MODIFIED_SINCE, httpDate2);
Expect.equals(1, headers[HttpHeaders.IF_MODIFIED_SINCE].length);
Expect.equals(httpDate1, headers.value(HttpHeaders.ifModifiedSinceHeader));
Expect.equals(1, headers[HttpHeaders.ifModifiedSinceHeader].length);
headers.add(HttpHeaders.ifModifiedSinceHeader, httpDate2);
Expect.equals(1, headers[HttpHeaders.ifModifiedSinceHeader].length);
Expect.equals(date2, headers.ifModifiedSince);
Expect.equals(httpDate2, headers.value(HttpHeaders.IF_MODIFIED_SINCE));
headers.set(HttpHeaders.IF_MODIFIED_SINCE, httpDate1);
Expect.equals(1, headers[HttpHeaders.IF_MODIFIED_SINCE].length);
Expect.equals(httpDate2, headers.value(HttpHeaders.ifModifiedSinceHeader));
headers.set(HttpHeaders.ifModifiedSinceHeader, httpDate1);
Expect.equals(1, headers[HttpHeaders.ifModifiedSinceHeader].length);
Expect.equals(date1, headers.ifModifiedSince);
Expect.equals(httpDate1, headers.value(HttpHeaders.IF_MODIFIED_SINCE));
Expect.equals(httpDate1, headers.value(HttpHeaders.ifModifiedSinceHeader));
headers.set(HttpHeaders.IF_MODIFIED_SINCE, "xxx");
Expect.equals("xxx", headers.value(HttpHeaders.IF_MODIFIED_SINCE));
headers.set(HttpHeaders.ifModifiedSinceHeader, "xxx");
Expect.equals("xxx", headers.value(HttpHeaders.ifModifiedSinceHeader));
Expect.equals(null, headers.ifModifiedSince);
}
@ -142,30 +142,30 @@ void testHost() {
Expect.isNull(headers.host);
Expect.isNull(headers.port);
headers.host = host;
Expect.equals(host, headers.value(HttpHeaders.HOST));
Expect.equals(host, headers.value(HttpHeaders.hostHeader));
headers.port = 1234;
Expect.equals("$host:1234", headers.value(HttpHeaders.HOST));
headers.port = HttpClient.DEFAULT_HTTP_PORT;
Expect.equals(host, headers.value(HttpHeaders.HOST));
Expect.equals("$host:1234", headers.value(HttpHeaders.hostHeader));
headers.port = HttpClient.defaultHttpPort;
Expect.equals(host, headers.value(HttpHeaders.hostHeader));
headers = new _HttpHeaders("1.1");
headers.add(HttpHeaders.HOST, host);
headers.add(HttpHeaders.hostHeader, host);
Expect.equals(host, headers.host);
Expect.equals(HttpClient.DEFAULT_HTTP_PORT, headers.port);
headers.add(HttpHeaders.HOST, "$host:4567");
Expect.equals(1, headers[HttpHeaders.HOST].length);
Expect.equals(HttpClient.defaultHttpPort, headers.port);
headers.add(HttpHeaders.hostHeader, "$host:4567");
Expect.equals(1, headers[HttpHeaders.hostHeader].length);
Expect.equals(host, headers.host);
Expect.equals(4567, headers.port);
headers = new _HttpHeaders("1.1");
headers.add(HttpHeaders.HOST, "$host:xxx");
Expect.equals("$host:xxx", headers.value(HttpHeaders.HOST));
headers.add(HttpHeaders.hostHeader, "$host:xxx");
Expect.equals("$host:xxx", headers.value(HttpHeaders.hostHeader));
Expect.equals(host, headers.host);
Expect.isNull(headers.port);
headers = new _HttpHeaders("1.1");
headers.add(HttpHeaders.HOST, ":1234");
Expect.equals(":1234", headers.value(HttpHeaders.HOST));
headers.add(HttpHeaders.hostHeader, ":1234");
Expect.equals(":1234", headers.value(HttpHeaders.hostHeader));
Expect.isNull(headers.host);
Expect.equals(1234, headers.port);
}
@ -218,7 +218,7 @@ void testTransferEncoding() {
void testEnumeration() {
_HttpHeaders headers = new _HttpHeaders("1.1");
Expect.isNull(headers[HttpHeaders.PRAGMA]);
Expect.isNull(headers[HttpHeaders.pragmaHeader]);
headers.add("My-Header-1", "value 1");
headers.add("My-Header-2", "value 2");
headers.add("My-Header-1", "value 3");
@ -355,10 +355,10 @@ void testContentType() {
check(contentType, "text", "html", {"charset": null});
// Test builtin content types.
check(ContentType.TEXT, "text", "plain", {"charset": "utf-8"});
check(ContentType.HTML, "text", "html", {"charset": "utf-8"});
check(ContentType.JSON, "application", "json", {"charset": "utf-8"});
check(ContentType.BINARY, "application", "octet-stream");
check(ContentType.text, "text", "plain", {"charset": "utf-8"});
check(ContentType.html, "text", "html", {"charset": "utf-8"});
check(ContentType.json, "application", "json", {"charset": "utf-8"});
check(ContentType.binary, "application", "octet-stream");
}
void testKnownContentTypes() {
@ -377,15 +377,15 @@ void testKnownContentTypes() {
void testContentTypeCache() {
_HttpHeaders headers = new _HttpHeaders("1.1");
headers.set(HttpHeaders.CONTENT_TYPE, "text/html");
headers.set(HttpHeaders.contentTypeHeader, "text/html");
Expect.equals("text", headers.contentType.primaryType);
Expect.equals("html", headers.contentType.subType);
Expect.equals("text/html", headers.contentType.value);
headers.set(HttpHeaders.CONTENT_TYPE, "text/plain; charset=utf-8");
headers.set(HttpHeaders.contentTypeHeader, "text/plain; charset=utf-8");
Expect.equals("text", headers.contentType.primaryType);
Expect.equals("plain", headers.contentType.subType);
Expect.equals("text/plain", headers.contentType.value);
headers.removeAll(HttpHeaders.CONTENT_TYPE);
headers.removeAll(HttpHeaders.contentTypeHeader);
Expect.isNull(headers.contentType);
}
@ -514,10 +514,10 @@ void testInvalidCookie() {
}
void testHeaderLists() {
HttpHeaders.GENERAL_HEADERS.forEach((x) => null);
HttpHeaders.ENTITY_HEADERS.forEach((x) => null);
HttpHeaders.RESPONSE_HEADERS.forEach((x) => null);
HttpHeaders.REQUEST_HEADERS.forEach((x) => null);
HttpHeaders.generalHeaders.forEach((x) => null);
HttpHeaders.entityHeaders.forEach((x) => null);
HttpHeaders.responseHeaders.forEach((x) => null);
HttpHeaders.requestHeaders.forEach((x) => null);
}
void testInvalidFieldName() {

View file

@ -32,7 +32,7 @@ void testHttpIPv6() {
.openUrl('GET', url)
.then((request) => request.close())
.then((response) {
Expect.equals(response.statusCode, HttpStatus.OK);
Expect.equals(response.statusCode, HttpStatus.ok);
}).whenComplete(() {
server.close();
client.close();

View file

@ -10,19 +10,18 @@ RawSocket client;
serverListen(RawSocket serverSide) {
serveData(RawSocketEvent event) {
serverSide.shutdown(SocketDirection.SEND);
serverSide.shutdown(SocketDirection.send);
}
serverSide.listen(serveData);
}
IPv4ToIPv6FailureTest() async {
server = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V6, 0);
server = await RawServerSocket.bind(InternetAddress.loopbackIPv6, 0);
server.listen(serverListen);
bool testFailure = false;
try {
client =
await RawSocket.connect(InternetAddress.LOOPBACK_IP_V4, server.port);
client = await RawSocket.connect(InternetAddress.loopbackIPv4, server.port);
await client.close();
testFailure = true;
} on SocketException catch (e) {
@ -37,12 +36,11 @@ IPv4ToIPv6FailureTest() async {
}
IPv6ToIPv4FailureTest() async {
server = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0);
server = await RawServerSocket.bind(InternetAddress.loopbackIPv4, 0);
server.listen(serverListen);
bool testFailure = false;
try {
client =
await RawSocket.connect(InternetAddress.LOOPBACK_IP_V6, server.port);
client = await RawSocket.connect(InternetAddress.loopbackIPv6, server.port);
await client.close();
testFailure = true;
} on SocketException catch (e) {
@ -74,6 +72,6 @@ loopbackSuccessTest(InternetAddress address) async {
main() async {
await IPv4ToIPv6FailureTest();
await IPv6ToIPv4FailureTest();
await loopbackSuccessTest(InternetAddress.LOOPBACK_IP_V4);
await loopbackSuccessTest(InternetAddress.LOOPBACK_IP_V6);
await loopbackSuccessTest(InternetAddress.loopbackIPv4);
await loopbackSuccessTest(InternetAddress.loopbackIPv6);
}

View file

@ -37,8 +37,8 @@ void missingReasonPhrase(int statusCode, bool includeSpace) {
}
void main() {
missingReasonPhrase(HttpStatus.OK, true);
missingReasonPhrase(HttpStatus.INTERNAL_SERVER_ERROR, true);
missingReasonPhrase(HttpStatus.OK, false);
missingReasonPhrase(HttpStatus.INTERNAL_SERVER_ERROR, false);
missingReasonPhrase(HttpStatus.ok, true);
missingReasonPhrase(HttpStatus.internalServerError, true);
missingReasonPhrase(HttpStatus.ok, false);
missingReasonPhrase(HttpStatus.internalServerError, false);
}

View file

@ -34,7 +34,7 @@ void testChunkedBufferSizeMsg() {
});
var client = new HttpClient();
client.get('127.0.0.1', server.port, '/').then((request) {
request.headers.set(HttpHeaders.ACCEPT_ENCODING, "");
request.headers.set(HttpHeaders.acceptEncodingHeader, "");
return request.close();
}).then((response) {
var buffer = [];

View file

@ -50,12 +50,12 @@ class Server {
bool direct = directRequestPaths.fold(
false, (prev, path) => prev ? prev : path == request.uri.path);
if (!secure && !direct && proxyHops > 0) {
Expect.isNotNull(request.headers[HttpHeaders.VIA]);
Expect.equals(1, request.headers[HttpHeaders.VIA].length);
Expect.equals(
proxyHops, request.headers[HttpHeaders.VIA][0].split(",").length);
Expect.isNotNull(request.headers[HttpHeaders.viaHeader]);
Expect.equals(1, request.headers[HttpHeaders.viaHeader].length);
Expect.equals(proxyHops,
request.headers[HttpHeaders.viaHeader][0].split(",").length);
} else {
Expect.isNull(request.headers[HttpHeaders.VIA]);
Expect.isNull(request.headers[HttpHeaders.viaHeader]);
}
var body = new StringBuffer();
onRequestComplete() {
@ -125,8 +125,8 @@ class ProxyServer {
request.fold(null, (x, y) {}).then((_) {
var response = request.response;
response.headers
.set(HttpHeaders.PROXY_AUTHENTICATE, "Basic, realm=$realm");
response.statusCode = HttpStatus.PROXY_AUTHENTICATION_REQUIRED;
.set(HttpHeaders.proxyAuthenticateHeader, "Basic, realm=$realm");
response.statusCode = HttpStatus.proxyAuthenticationRequired;
response.close();
});
}
@ -134,7 +134,7 @@ class ProxyServer {
digestAuthenticationRequired(request, {stale: false}) {
request.fold(null, (x, y) {}).then((_) {
var response = request.response;
response.statusCode = HttpStatus.PROXY_AUTHENTICATION_REQUIRED;
response.statusCode = HttpStatus.proxyAuthenticationRequired;
StringBuffer authHeader = new StringBuffer();
authHeader.write('Digest');
authHeader.write(', realm="$realm"');
@ -144,7 +144,7 @@ class ProxyServer {
authHeader.write(', algorithm=$serverAlgorithm');
}
if (serverQop != null) authHeader.write(', qop="$serverQop"');
response.headers.set(HttpHeaders.PROXY_AUTHENTICATE, authHeader);
response.headers.set(HttpHeaders.proxyAuthenticateHeader, authHeader);
response.close();
});
}
@ -158,7 +158,7 @@ class ProxyServer {
server.listen((HttpRequest request) {
requestCount++;
if (username != null && password != null) {
if (request.headers[HttpHeaders.PROXY_AUTHORIZATION] == null) {
if (request.headers[HttpHeaders.proxyAuthorizationHeader] == null) {
if (authScheme == "Digest") {
digestAuthenticationRequired(request);
} else {
@ -166,10 +166,10 @@ class ProxyServer {
}
return;
} else {
Expect.equals(
1, request.headers[HttpHeaders.PROXY_AUTHORIZATION].length);
Expect.equals(1,
request.headers[HttpHeaders.proxyAuthorizationHeader].length);
String authorization =
request.headers[HttpHeaders.PROXY_AUTHORIZATION][0];
request.headers[HttpHeaders.proxyAuthorizationHeader][0];
if (authScheme == "Basic") {
List<String> tokens = authorization.split(" ");
Expect.equals("Basic", tokens[0]);
@ -251,10 +251,10 @@ class ProxyServer {
});
// Special handling of Content-Length and Via.
clientRequest.contentLength = request.contentLength;
List<String> via = request.headers[HttpHeaders.VIA];
List<String> via = request.headers[HttpHeaders.viaHeader];
String viaPrefix = via == null ? "" : "${via[0]}, ";
clientRequest.headers
.add(HttpHeaders.VIA, "${viaPrefix}1.1 localhost:$port");
.add(HttpHeaders.viaHeader, "${viaPrefix}1.1 localhost:$port");
// Copy all content.
return request.pipe(clientRequest);
}).then((clientResponse) {
@ -460,7 +460,7 @@ Future testProxyAuthenticate(bool useDigestAuthentication) {
}).then((HttpClientResponse response) {
response.listen((_) {}, onDone: () {
testProxyAuthenticateCount++;
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
if (testProxyAuthenticateCount == loopCount * 2) {
Expect.equals(loopCount, server.requestCount);
Expect.equals(loopCount, secureServer.requestCount);
@ -502,7 +502,7 @@ Future testProxyAuthenticate(bool useDigestAuthentication) {
}).then((HttpClientResponse response) {
response.listen((_) {}, onDone: () {
testProxyAuthenticateCount++;
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
if (testProxyAuthenticateCount == loopCount * 2) {
Expect.equals(loopCount * 2, server.requestCount);
Expect.equals(loopCount * 2, secureServer.requestCount);

View file

@ -49,12 +49,12 @@ class Server {
bool direct = directRequestPaths.fold(
false, (prev, path) => prev ? prev : path == request.uri.path);
if (!secure && !direct && proxyHops > 0) {
Expect.isNotNull(request.headers[HttpHeaders.VIA]);
Expect.equals(1, request.headers[HttpHeaders.VIA].length);
Expect.equals(
proxyHops, request.headers[HttpHeaders.VIA][0].split(",").length);
Expect.isNotNull(request.headers[HttpHeaders.viaHeader]);
Expect.equals(1, request.headers[HttpHeaders.viaHeader].length);
Expect.equals(proxyHops,
request.headers[HttpHeaders.viaHeader][0].split(",").length);
} else {
Expect.isNull(request.headers[HttpHeaders.VIA]);
Expect.isNull(request.headers[HttpHeaders.viaHeader]);
}
var body = new StringBuffer();
onRequestComplete() {
@ -114,8 +114,8 @@ class ProxyServer {
request.fold(null, (x, y) {}).then((_) {
var response = request.response;
response.headers
.set(HttpHeaders.PROXY_AUTHENTICATE, "Basic, realm=$realm");
response.statusCode = HttpStatus.PROXY_AUTHENTICATION_REQUIRED;
.set(HttpHeaders.proxyAuthenticateHeader, "Basic, realm=$realm");
response.statusCode = HttpStatus.proxyAuthenticationRequired;
response.close();
});
}
@ -123,7 +123,7 @@ class ProxyServer {
digestAuthenticationRequired(request, {stale: false}) {
request.fold(null, (x, y) {}).then((_) {
var response = request.response;
response.statusCode = HttpStatus.PROXY_AUTHENTICATION_REQUIRED;
response.statusCode = HttpStatus.proxyAuthenticationRequired;
StringBuffer authHeader = new StringBuffer();
authHeader.write('Digest');
authHeader.write(', realm="$realm"');
@ -133,7 +133,7 @@ class ProxyServer {
authHeader.write(', algorithm=$serverAlgorithm');
}
if (serverQop != null) authHeader.write(', qop="$serverQop"');
response.headers.set(HttpHeaders.PROXY_AUTHENTICATE, authHeader);
response.headers.set(HttpHeaders.proxyAuthenticateHeader, authHeader);
response.close();
});
}
@ -147,7 +147,7 @@ class ProxyServer {
server.listen((HttpRequest request) {
requestCount++;
if (username != null && password != null) {
if (request.headers[HttpHeaders.PROXY_AUTHORIZATION] == null) {
if (request.headers[HttpHeaders.proxyAuthorizationHeader] == null) {
if (authScheme == "Digest") {
digestAuthenticationRequired(request);
} else {
@ -155,10 +155,10 @@ class ProxyServer {
}
return;
} else {
Expect.equals(
1, request.headers[HttpHeaders.PROXY_AUTHORIZATION].length);
Expect.equals(1,
request.headers[HttpHeaders.proxyAuthorizationHeader].length);
String authorization =
request.headers[HttpHeaders.PROXY_AUTHORIZATION][0];
request.headers[HttpHeaders.proxyAuthorizationHeader][0];
if (authScheme == "Basic") {
List<String> tokens = authorization.split(" ");
Expect.equals("Basic", tokens[0]);
@ -239,10 +239,10 @@ class ProxyServer {
});
// Special handling of Content-Length and Via.
clientRequest.contentLength = request.contentLength;
List<String> via = request.headers[HttpHeaders.VIA];
List<String> via = request.headers[HttpHeaders.viaHeader];
String viaPrefix = via == null ? "" : "${via[0]}, ";
clientRequest.headers
.add(HttpHeaders.VIA, "${viaPrefix}1.1 localhost:$port");
.add(HttpHeaders.viaHeader, "${viaPrefix}1.1 localhost:$port");
// Copy all content.
return request.pipe(clientRequest);
}).then((clientResponse) {

View file

@ -113,7 +113,7 @@ class TestServer {
// Return a 404.
void _notFoundHandler(HttpRequest request) {
var response = request.response;
response.statusCode = HttpStatus.NOT_FOUND;
response.statusCode = HttpStatus.notFound;
response.headers.set("Content-Type", "text/html; charset=UTF-8");
response.write("Page not found");
response.close();
@ -186,7 +186,7 @@ void testRead(bool chunkedEncoding) {
}
return request.close();
}).then((response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
List<int> body = new List<int>();
response.listen(body.addAll, onDone: () {
Expect.equals(data, new String.fromCharCodes(body));

View file

@ -39,7 +39,7 @@ Future<HttpServer> setupServer() {
addRequestHandler("/redirect",
(HttpRequest request, HttpResponse response) {
response.redirect(Uri.parse("http://127.0.0.1:${server.port}/location"),
status: HttpStatus.MOVED_PERMANENTLY);
status: HttpStatus.movedPermanently);
});
addRequestHandler("/location",
(HttpRequest request, HttpResponse response) {
@ -49,15 +49,15 @@ Future<HttpServer> setupServer() {
// Setup redirects with relative url.
addRequestHandler("/redirectUrl",
(HttpRequest request, HttpResponse response) {
response.headers.set(HttpHeaders.LOCATION, "/some/relativeUrl");
response.statusCode = HttpStatus.MOVED_PERMANENTLY;
response.headers.set(HttpHeaders.locationHeader, "/some/relativeUrl");
response.statusCode = HttpStatus.movedPermanently;
response.close();
});
addRequestHandler("/some/redirectUrl",
(HttpRequest request, HttpResponse response) {
response.headers.set(HttpHeaders.LOCATION, "relativeUrl");
response.statusCode = HttpStatus.MOVED_PERMANENTLY;
response.headers.set(HttpHeaders.locationHeader, "relativeUrl");
response.statusCode = HttpStatus.movedPermanently;
response.close();
});
@ -68,68 +68,68 @@ Future<HttpServer> setupServer() {
addRequestHandler("/some/relativeToAbsolute",
(HttpRequest request, HttpResponse response) {
response.redirect(Uri.parse("xxx"), status: HttpStatus.SEE_OTHER);
response.redirect(Uri.parse("xxx"), status: HttpStatus.seeOther);
});
addRequestHandler("/redirectUrl2",
(HttpRequest request, HttpResponse response) {
response.headers.set(HttpHeaders.LOCATION, "location");
response.statusCode = HttpStatus.MOVED_PERMANENTLY;
response.headers.set(HttpHeaders.locationHeader, "location");
response.statusCode = HttpStatus.movedPermanently;
response.close();
});
addRequestHandler("/redirectUrl3",
(HttpRequest request, HttpResponse response) {
response.headers.set(HttpHeaders.LOCATION, "./location");
response.statusCode = HttpStatus.MOVED_PERMANENTLY;
response.headers.set(HttpHeaders.locationHeader, "./location");
response.statusCode = HttpStatus.movedPermanently;
response.close();
});
addRequestHandler("/redirectUrl4",
(HttpRequest request, HttpResponse response) {
response.headers.set(HttpHeaders.LOCATION, "./a/b/../../location");
response.statusCode = HttpStatus.MOVED_PERMANENTLY;
response.headers.set(HttpHeaders.locationHeader, "./a/b/../../location");
response.statusCode = HttpStatus.movedPermanently;
response.close();
});
addRequestHandler("/redirectUrl5",
(HttpRequest request, HttpResponse response) {
response.headers
.set(HttpHeaders.LOCATION, "//127.0.0.1:${server.port}/location");
response.statusCode = HttpStatus.MOVED_PERMANENTLY;
response.headers.set(
HttpHeaders.locationHeader, "//127.0.0.1:${server.port}/location");
response.statusCode = HttpStatus.movedPermanently;
response.close();
});
// Setup redirect chain.
int n = 1;
addRedirectHandler(n++, HttpStatus.MOVED_PERMANENTLY);
addRedirectHandler(n++, HttpStatus.MOVED_TEMPORARILY);
addRedirectHandler(n++, HttpStatus.SEE_OTHER);
addRedirectHandler(n++, HttpStatus.TEMPORARY_REDIRECT);
addRedirectHandler(n++, HttpStatus.movedPermanently);
addRedirectHandler(n++, HttpStatus.movedTemporarily);
addRedirectHandler(n++, HttpStatus.seeOther);
addRedirectHandler(n++, HttpStatus.temporaryRedirect);
for (int i = n; i < 10; i++) {
addRedirectHandler(i, HttpStatus.MOVED_PERMANENTLY);
addRedirectHandler(i, HttpStatus.movedPermanently);
}
// Setup redirect loop.
addRequestHandler("/A", (HttpRequest request, HttpResponse response) {
response.headers
.set(HttpHeaders.LOCATION, "http://127.0.0.1:${server.port}/B");
response.statusCode = HttpStatus.MOVED_PERMANENTLY;
.set(HttpHeaders.locationHeader, "http://127.0.0.1:${server.port}/B");
response.statusCode = HttpStatus.movedPermanently;
response.close();
});
addRequestHandler("/B", (HttpRequest request, HttpResponse response) {
response.headers
.set(HttpHeaders.LOCATION, "http://127.0.0.1:${server.port}/A");
response.statusCode = HttpStatus.MOVED_TEMPORARILY;
.set(HttpHeaders.locationHeader, "http://127.0.0.1:${server.port}/A");
response.statusCode = HttpStatus.movedTemporarily;
response.close();
});
// Setup redirect checking headers.
addRequestHandler("/src", (HttpRequest request, HttpResponse response) {
Expect.equals("value", request.headers.value("X-Request-Header"));
response.headers
.set(HttpHeaders.LOCATION, "http://127.0.0.1:${server.port}/target");
response.statusCode = HttpStatus.MOVED_PERMANENTLY;
response.headers.set(
HttpHeaders.locationHeader, "http://127.0.0.1:${server.port}/target");
response.statusCode = HttpStatus.movedPermanently;
response.close();
});
addRequestHandler("/target", (HttpRequest request, HttpResponse response) {
@ -141,9 +141,9 @@ Future<HttpServer> setupServer() {
addRequestHandler("/301src", (HttpRequest request, HttpResponse response) {
Expect.equals("POST", request.method);
request.listen((_) {}, onDone: () {
response.headers.set(
HttpHeaders.LOCATION, "http://127.0.0.1:${server.port}/301target");
response.statusCode = HttpStatus.MOVED_PERMANENTLY;
response.headers.set(HttpHeaders.locationHeader,
"http://127.0.0.1:${server.port}/301target");
response.statusCode = HttpStatus.movedPermanently;
response.close();
});
});
@ -156,9 +156,9 @@ Future<HttpServer> setupServer() {
addRequestHandler("/303src", (HttpRequest request, HttpResponse response) {
request.listen((_) {}, onDone: () {
Expect.equals("POST", request.method);
response.headers.set(
HttpHeaders.LOCATION, "http://127.0.0.1:${server.port}/303target");
response.statusCode = HttpStatus.SEE_OTHER;
response.headers.set(HttpHeaders.locationHeader,
"http://127.0.0.1:${server.port}/303target");
response.statusCode = HttpStatus.seeOther;
response.close();
});
});
@ -171,8 +171,8 @@ Future<HttpServer> setupServer() {
// Setup redirect where we close the connection.
addRequestHandler("/closing", (HttpRequest request, HttpResponse response) {
response.headers
.set(HttpHeaders.LOCATION, "http://127.0.0.1:${server.port}/");
response.statusCode = HttpStatus.FOUND;
.set(HttpHeaders.locationHeader, "http://127.0.0.1:${server.port}/");
response.statusCode = HttpStatus.found;
response.persistentConnection = false;
response.close();
});
@ -207,7 +207,7 @@ void testManualRedirect() {
checkRedirects(redirectCount, response);
response.redirect().then(handleResponse);
} else {
Expect.equals(HttpStatus.NOT_FOUND, response.statusCode);
Expect.equals(HttpStatus.notFound, response.statusCode);
server.close();
client.close();
}
@ -237,7 +237,7 @@ void testManualRedirectWithHeaders() {
Expect.isTrue(response.isRedirect);
response.redirect().then(handleResponse);
} else {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
server.close();
client.close();
}
@ -302,7 +302,7 @@ void testAutoRedirect301POST() {
.then((HttpClientRequest request) {
return request.close();
}).then((HttpClientResponse response) {
Expect.equals(HttpStatus.MOVED_PERMANENTLY, response.statusCode);
Expect.equals(HttpStatus.movedPermanently, response.statusCode);
response.listen((_) => Expect.fail("Response data not expected"),
onDone: () {
Expect.equals(0, response.redirects.length);
@ -322,7 +322,7 @@ void testAutoRedirect303POST() {
.then((HttpClientRequest request) {
return request.close();
}).then((HttpClientResponse response) {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
response.listen((_) => Expect.fail("Response data not expected"),
onDone: () {
Expect.equals(1, response.redirects.length);
@ -392,7 +392,7 @@ void testRedirectRelativeUrl() {
.then((request) => request.close())
.then((response) {
response.listen((_) {}, onDone: () {
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
Expect.equals(1, response.redirects.length);
server.close();
client.close();
@ -417,7 +417,7 @@ void testRedirectRelativeToAbsolute() {
handleResponse(HttpClientResponse response) {
response.listen((_) => Expect.fail("Response data not expected"),
onDone: () {
Expect.equals(HttpStatus.SEE_OTHER, response.statusCode);
Expect.equals(HttpStatus.seeOther, response.statusCode);
Expect.equals("xxx", response.headers["Location"][0]);
Expect.isTrue(response.isRedirect);
server.close();

View file

@ -12,21 +12,21 @@ import "package:expect/expect.dart";
void testDefaultResponseHeaders() {
checkDefaultHeaders(headers) {
Expect.listEquals(
headers[HttpHeaders.CONTENT_TYPE], ['text/plain; charset=utf-8']);
headers[HttpHeaders.contentTypeHeader], ['text/plain; charset=utf-8']);
Expect.listEquals(headers['X-Frame-Options'], ['SAMEORIGIN']);
Expect.listEquals(headers['X-Content-Type-Options'], ['nosniff']);
Expect.listEquals(headers['X-XSS-Protection'], ['1; mode=block']);
}
checkDefaultHeadersClear(headers) {
Expect.isNull(headers[HttpHeaders.CONTENT_TYPE]);
Expect.isNull(headers[HttpHeaders.contentTypeHeader]);
Expect.isNull(headers['X-Frame-Options']);
Expect.isNull(headers['X-Content-Type-Options']);
Expect.isNull(headers['X-XSS-Protection']);
}
checkDefaultHeadersClearAB(headers) {
Expect.isNull(headers[HttpHeaders.CONTENT_TYPE]);
Expect.isNull(headers[HttpHeaders.contentTypeHeader]);
Expect.isNull(headers['X-Frame-Options']);
Expect.isNull(headers['X-Content-Type-Options']);
Expect.isNull(headers['X-XSS-Protection']);

View file

@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// This test checks that a shutdown(SocketDirection.SEND) of a socket,
// This test checks that a shutdown(SocketDirection.send) of a socket,
// when the other end is already closed, does not discard unread data
// that remains in the connection.

View file

@ -91,7 +91,7 @@ void doTestSync() {
Expect.isFalse(dir4.existsSync());
// stat.
FileStat dirstat = dir2.statSync();
Expect.equals(FileSystemEntityType.DIRECTORY, dirstat.type);
Expect.equals(FileSystemEntityType.directory, dirstat.type);
}
doTestAsync() async {
@ -177,7 +177,7 @@ doTestAsync() async {
Expect.isFalse(await dir4.exists());
// stat.
FileStat dirstat = await dir2.stat();
Expect.equals(FileSystemEntityType.DIRECTORY, dirstat.type);
Expect.equals(FileSystemEntityType.directory, dirstat.type);
}
List<String> packageOptions() {

View file

@ -40,7 +40,7 @@ void verify(String exePath, {String altPath}) {
void testDartExecShouldNotBeInCurrentDir() {
var type = FileSystemEntity.typeSync(platformExeName);
expectEquals(FileSystemEntityType.NOT_FOUND, type);
expectEquals(FileSystemEntityType.notFound, type);
}
void testShouldFailOutsidePath() {

View file

@ -90,7 +90,7 @@ void testCloseOneEnd(String toClose) {
server.listen((serverConnection) {
serverConnection.listen((event) {
if (toClose == "server" || event == RawSocketEvent.readClosed) {
serverConnection.shutdown(SocketDirection.SEND);
serverConnection.shutdown(SocketDirection.send);
}
}, onDone: () {
serverEndDone.complete(null);
@ -101,7 +101,7 @@ void testCloseOneEnd(String toClose) {
RawSocket.connect("127.0.0.1", server.port).then((clientConnection) {
clientConnection.listen((event) {
if (toClose == "client" || event == RawSocketEvent.readClosed) {
clientConnection.shutdown(SocketDirection.SEND);
clientConnection.shutdown(SocketDirection.send);
}
}, onDone: () {
clientEndDone.complete(null);
@ -186,7 +186,7 @@ void testSimpleReadWrite({bool dropReads}) {
client.writeEventsEnabled = true;
}
if (bytesWritten == data.length) {
client.shutdown(SocketDirection.SEND);
client.shutdown(SocketDirection.send);
}
break;
case RawSocketEvent.readClosed:

View file

@ -13,7 +13,7 @@ void testHostAndPort() {
Expect.equals(clientSocket.port, socket.remotePort);
Expect.equals(clientSocket.remotePort, socket.port);
Expect.equals(socket.remoteAddress.address, "127.0.0.1");
Expect.equals(socket.remoteAddress.type, InternetAddressType.IP_V4);
Expect.equals(socket.remoteAddress.type, InternetAddressType.IPv4);
Expect.listEquals(socket.remoteAddress.rawAddress, [127, 0, 0, 1]);
Expect.equals(clientSocket.remoteAddress.address, "127.0.0.1");
Expect.equals(

View file

@ -67,12 +67,12 @@ class SecurityConfiguration {
// If the URL contains user information use that for basic
// authorization.
String auth = base64.encode(utf8.encode(uri.userInfo));
request.headers.set(HttpHeaders.AUTHORIZATION, "Basic $auth");
request.headers.set(HttpHeaders.authorizationHeader, "Basic $auth");
}
// Setup the initial handshake.
request.headers
..set(HttpHeaders.CONNECTION, "Upgrade")
..set(HttpHeaders.UPGRADE, "websocket")
..set(HttpHeaders.connectionHeader, "Upgrade")
..set(HttpHeaders.upgradeHeader, "websocket")
..set("Sec-WebSocket-Key", nonce)
..set("Cache-Control", "no-cache")
..set("Sec-WebSocket-Version", "13")
@ -168,16 +168,18 @@ class SecurityConfiguration {
asyncStart();
createServer().then((server) {
server.listen((request) {
Expect.equals('Upgrade', request.headers.value(HttpHeaders.CONNECTION));
Expect.equals('websocket', request.headers.value(HttpHeaders.UPGRADE));
Expect.equals(
'Upgrade', request.headers.value(HttpHeaders.connectionHeader));
Expect.equals(
'websocket', request.headers.value(HttpHeaders.upgradeHeader));
var key = request.headers.value('Sec-WebSocket-Key');
var digest = sha1.convert("$key$WEB_SOCKET_GUID".codeUnits);
var accept = base64.encode(digest.bytes);
request.response
..statusCode = HttpStatus.SWITCHING_PROTOCOLS
..headers.add(HttpHeaders.CONNECTION, "Upgrade")
..headers.add(HttpHeaders.UPGRADE, "websocket")
..statusCode = HttpStatus.switchingProtocols
..headers.add(HttpHeaders.connectionHeader, "Upgrade")
..headers.add(HttpHeaders.upgradeHeader, "websocket")
..headers.add("Sec-WebSocket-Accept", accept)
..headers.add(
"Sec-WebSocket-Extensions",
@ -207,7 +209,8 @@ class SecurityConfiguration {
}
void testReturnHeaders(String headerValue, String expected,
{CompressionOptions serverCompression: CompressionOptions.DEFAULT}) {
{CompressionOptions serverCompression:
CompressionOptions.compressionDefault}) {
asyncStart();
createServer().then((server) {
server.listen((request) {
@ -227,7 +230,7 @@ class SecurityConfiguration {
var url = '${secure ? "wss" : "ws"}://$HOST_NAME:${server.port}/';
createWebsocket(url, headerValue).then((HttpClientResponse response) {
Expect.equals(response.statusCode, HttpStatus.SWITCHING_PROTOCOLS);
Expect.equals(response.statusCode, HttpStatus.switchingProtocols);
print(response.headers.value('Sec-WebSocket-Extensions'));
Expect.equals(
response.headers.value("Sec-WebSocket-Extensions"), expected);
@ -361,7 +364,7 @@ class SecurityConfiguration {
'permessage-deflate; client_max_window_bits=15',
serverCompression: compression);
compression = CompressionOptions.DEFAULT;
compression = CompressionOptions.compressionDefault;
testClientRequestHeaders(compression);
compression = new CompressionOptions(
clientNoContextTakeover: true, serverNoContextTakeover: true);

View file

@ -56,9 +56,9 @@ class SecurityConfiguration {
createServer().then((server) {
server.listen((request) {
var response = request.response;
response.statusCode = HttpStatus.SWITCHING_PROTOCOLS;
response.headers.set(HttpHeaders.CONNECTION, "upgrade");
response.headers.set(HttpHeaders.UPGRADE, "websocket");
response.statusCode = HttpStatus.switchingProtocols;
response.headers.set(HttpHeaders.connectionHeader, "upgrade");
response.headers.set(HttpHeaders.upgradeHeader, "websocket");
String key = request.headers.value("Sec-WebSocket-Key");
_SHA1 sha1 = new _SHA1();
sha1.add("$key$webSocketGUID".codeUnits);

View file

@ -24,9 +24,9 @@ void testPing(int totalConnections) {
int closed = 0;
server.listen((request) {
var response = request.response;
response.statusCode = HttpStatus.SWITCHING_PROTOCOLS;
response.headers.set(HttpHeaders.CONNECTION, "upgrade");
response.headers.set(HttpHeaders.UPGRADE, "websocket");
response.statusCode = HttpStatus.switchingProtocols;
response.headers.set(HttpHeaders.connectionHeader, "upgrade");
response.headers.set(HttpHeaders.upgradeHeader, "websocket");
String key = request.headers.value("Sec-WebSocket-Key");
_SHA1 sha1 = new _SHA1();
sha1.add("$key$webSocketGUID".codeUnits);

View file

@ -50,7 +50,7 @@ class SecurityConfiguration {
checkCloseStatus(webSocket, closeStatus, closeReason) {
Expect.equals(
closeStatus == null ? WebSocketStatus.NO_STATUS_RECEIVED : closeStatus,
closeStatus == null ? WebSocketStatus.noStatusReceived : closeStatus,
webSocket.closeCode);
Expect.equals(
closeReason == null ? "" : closeReason, webSocket.closeReason);
@ -283,9 +283,9 @@ class SecurityConfiguration {
void testNoUpgrade() {
createServer().then((server) {
// Create a server which always responds with NOT_FOUND.
// Create a server which always responds with notFound.
server.listen((request) {
request.response.statusCode = HttpStatus.NOT_FOUND;
request.response.statusCode = HttpStatus.notFound;
request.response.close();
});
@ -310,7 +310,7 @@ class SecurityConfiguration {
"${secure ? 'https:' : 'http:'}//$HOST_NAME:${server.port}/"))
.then((request) => request.close())
.then((response) {
Expect.equals(HttpStatus.BAD_REQUEST, response.statusCode);
Expect.equals(HttpStatus.badRequest, response.statusCode);
client.close();
server.close();
});
@ -352,12 +352,12 @@ class SecurityConfiguration {
Expect.equals(0, onmessageCalled);
Expect.isFalse(oncloseCalled);
onopenCalled = true;
Expect.equals(WebSocket.OPEN, webSocket.readyState);
Expect.equals(WebSocket.open, webSocket.readyState);
webSocket.listen((message) {
onmessageCalled++;
Expect.isTrue(onopenCalled);
Expect.isFalse(oncloseCalled);
Expect.equals(WebSocket.OPEN, webSocket.readyState);
Expect.equals(WebSocket.open, webSocket.readyState);
webSocket.add(message);
}, onDone: () {
Expect.isTrue(onopenCalled);
@ -366,7 +366,7 @@ class SecurityConfiguration {
oncloseCalled = true;
Expect.equals(3002, webSocket.closeCode);
Expect.equals("Got tired", webSocket.closeReason);
Expect.equals(WebSocket.CLOSED, webSocket.readyState);
Expect.equals(WebSocket.closed, webSocket.readyState);
});
});
}
@ -390,7 +390,7 @@ class SecurityConfiguration {
});
} else {
Expect.isFalse(WebSocketTransformer.isUpgradeRequest(request));
request.response.statusCode = HttpStatus.OK;
request.response.statusCode = HttpStatus.ok;
request.response.close();
}
});
@ -417,7 +417,7 @@ class SecurityConfiguration {
.then((request) => request.close())
.then((response) {
response.listen((_) {});
Expect.equals(HttpStatus.OK, response.statusCode);
Expect.equals(HttpStatus.ok, response.statusCode);
}));
}
@ -433,16 +433,18 @@ class SecurityConfiguration {
asyncStart();
createServer().then((server) {
server.listen((request) {
Expect.equals('Upgrade', request.headers.value(HttpHeaders.CONNECTION));
Expect.equals('websocket', request.headers.value(HttpHeaders.UPGRADE));
Expect.equals(
'Upgrade', request.headers.value(HttpHeaders.connectionHeader));
Expect.equals(
'websocket', request.headers.value(HttpHeaders.upgradeHeader));
var key = request.headers.value('Sec-WebSocket-Key');
var digest = sha1.convert("$key$WEB_SOCKET_GUID".codeUnits);
var accept = base64.encode(digest.bytes);
request.response
..statusCode = HttpStatus.SWITCHING_PROTOCOLS
..headers.add(HttpHeaders.CONNECTION, "Upgrade")
..headers.add(HttpHeaders.UPGRADE, "websocket")
..statusCode = HttpStatus.switchingProtocols
..headers.add(HttpHeaders.connectionHeader, "Upgrade")
..headers.add(HttpHeaders.upgradeHeader, "websocket")
..headers.add("Sec-WebSocket-Accept", accept);
request.response.contentLength = 0;
request.response.detachSocket().then((socket) {

View file

@ -18,14 +18,15 @@ Future<HttpServer> createServer() => HttpServer.bind("127.0.0.1", 0);
Future<WebSocket> createClient(int port, bool compression) => compression
? WebSocket.connect('ws://127.0.0.1:$port/')
: WebSocket.connect('ws://127.0.0.1:$port/',
compression: CompressionOptions.OFF);
compression: CompressionOptions.compressionOff);
void test(expected, testData, compression) {
createServer().then((server) {
var messageCount = 0;
var transformer = compression
? new WebSocketTransformer()
: new WebSocketTransformer(compression: CompressionOptions.OFF);
: new WebSocketTransformer(
compression: CompressionOptions.compressionOff);
server.transform(transformer).listen((webSocket) {
webSocket.listen((message) {
Expect.listEquals(expected, message);
@ -76,7 +77,8 @@ void testOutOfRangeClient({bool compression: false}) {
var messageCount = 0;
var transformer = compression
? new WebSocketTransformer()
: new WebSocketTransformer(compression: CompressionOptions.OFF);
: new WebSocketTransformer(
compression: CompressionOptions.compressionOff);
server.transform(transformer).listen((webSocket) {
webSocket.listen((message) => Expect.fail("No message expected"));
});
@ -180,7 +182,8 @@ void testOutOfRangeServer({bool compression: false}) {
var messageCount = 0;
var transformer = compression
? new WebSocketTransformer()
: new WebSocketTransformer(compression: CompressionOptions.OFF);
: new WebSocketTransformer(
compression: CompressionOptions.compressionOff);
server.transform(transformer).listen((webSocket) {
webSocket.listen((message) {
messageCount++;

View file

@ -833,7 +833,7 @@ void createFiles(Directory tempDir, String subDir, Map content) {
/// The file contents are run through [fixPaths] to allow them to be self-
/// referential.
Future<HttpServer> startServer(Map files) async {
return (await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0))
return (await HttpServer.bind(InternetAddress.loopbackIPv4, 0))
..forEach((request) {
var result = files;
onFailure:
@ -856,7 +856,7 @@ Future<HttpServer> startServer(Map files) async {
}
}
request.response
..statusCode = HttpStatus.NOT_FOUND
..statusCode = HttpStatus.notFound
..close();
});
}