misc: require Dart 2. Fix Dart2 constants. Update travis config
diff --git a/.gitignore b/.gitignore
index e450c83..ec8eae3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,4 @@
# Don’t commit the following directories created by pub.
.dart_tool/
.packages
-.pub/
pubspec.lock
diff --git a/.travis.yml b/.travis.yml
index 60ab248..ddc4de6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,4 @@
language: dart
-sudo: false
os:
- linux
@@ -7,10 +6,16 @@
dart:
- dev
-# TODO(bkonyi) enable testing on stable Dart SDK after 1.24 is released.
-# - stable
dart_task:
- test: -p vm
- dartfmt
- - dartanalyzer
+ - dartanalyzer: --fatal-warnings --fatal-hints .
+
+# Only building master means that we don't run two builds for each pull request.
+branches:
+ only: [master]
+
+cache:
+ directories:
+ - $HOME/.pub-cache
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..6434e87
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,3 @@
+## v0.1.2
+
+* Require Dart 2.
diff --git a/README.md b/README.md
index fa96279..6b7b729 100644
--- a/README.md
+++ b/README.md
@@ -1,23 +1,16 @@
-Dart Synchronous HTTP Client
-============================
-
[![Build Status](https://travis-ci.org/dart-lang/sync_http.svg?branch=master)](https://travis-ci.org/dart-lang/sync_http/)
[![pub package](https://img.shields.io/pub/v/sync_http.svg)](https://pub.dartlang.org/packages/sync_http)
-**Important Note:** This package requires the RawSynchronousSocket class to
-work, which should become available in version 1.24 of the Dart SDK. If you
-really want to use this package now, you'll need to use the 1.24-dev SDK.
-
A simple Dart HTTP client implemented using RawSynchronousSockets to allow for
synchronous HTTP requests.
-**Warning**: This library should probably only be used to connect to HTTP servers
-that are hosted on 'localhost'. The operations in this library will block the
-calling thread to wait for a response from the HTTP server. The thread can
-process no other events while waiting for the server to respond. As such, this
-synchronous HTTP client library is not suitable for applications that require
-high performance. Instead, such applications should use libraries built on
-asynchronous I/O, including
-[dart:io](https://api.dartlang.org/stable/1.22.1/dart-io/dart-io-library.html)
-and [package:http](https://pub.dartlang.org/packages/http), for the best
+**Warning**: This library should probably only be used to connect to HTTP
+servers that are hosted on 'localhost'. The operations in this library will
+block the calling thread to wait for a response from the HTTP server. The thread
+can process no other events while waiting for the server to respond. As such,
+this synchronous HTTP client library is not suitable for applications that
+require high performance. Instead, such applications should use libraries built
+on asynchronous I/O, including
+[dart:io](https://api.dartlang.org/stable/1.24.3/dart-io/dart-io-library.html)
+and [package:http](https://pub.dartlang.org/packages/http), for the best
performance.
diff --git a/analysis_options.yaml b/analysis_options.yaml
deleted file mode 100644
index a10d4c5..0000000
--- a/analysis_options.yaml
+++ /dev/null
@@ -1,2 +0,0 @@
-analyzer:
- strong-mode: true
diff --git a/lib/src/line_decoder.dart b/lib/src/line_decoder.dart
index ced5499..1785dfd 100644
--- a/lib/src/line_decoder.dart
+++ b/lib/src/line_decoder.dart
@@ -42,7 +42,7 @@
}
void _process(List<int> line) =>
- _callback(UTF8.decoder.convert(line), line.length, this);
+ _callback(utf8.decoder.convert(line), line.length, this);
int get bufferedBytes => _unprocessedBytes.length;
diff --git a/lib/src/sync_http.dart b/lib/src/sync_http.dart
index 8a55104..77fa014 100644
--- a/lib/src/sync_http.dart
+++ b/lib/src/sync_http.dart
@@ -52,7 +52,7 @@
final Uri uri;
/// The default encoding for the HTTP request (UTF8).
- final Encoding encoding = UTF8;
+ final Encoding encoding = utf8;
/// The body of the HTTP request. This can be empty if there is no body
/// associated with the request.
@@ -107,23 +107,23 @@
@override
List<String> operator [](String name) {
switch (name) {
- case HttpHeaders.ACCEPT_CHARSET:
+ case HttpHeaders.acceptCharsetHeader:
return ['utf-8'];
- case HttpHeaders.ACCEPT_ENCODING:
+ case HttpHeaders.acceptEncodingHeader:
return ['identity'];
- case HttpHeaders.CONNECTION:
+ case HttpHeaders.connectionHeader:
return ['close'];
- case HttpHeaders.CONTENT_LENGTH:
+ case HttpHeaders.contentLengthHeader:
if (!_request.hasBody) {
return null;
}
return [contentLength.toString()];
- case HttpHeaders.CONTENT_TYPE:
+ case HttpHeaders.contentTypeHeader:
if (contentType == null) {
return null;
}
return [contentType.toString()];
- case HttpHeaders.HOST:
+ case HttpHeaders.hostHeader:
return ['$host:$port'];
default:
var values = _headers[name];
@@ -138,16 +138,16 @@
@override
void add(String name, Object value) {
switch (name) {
- case HttpHeaders.ACCEPT_CHARSET:
- case HttpHeaders.ACCEPT_ENCODING:
- case HttpHeaders.CONNECTION:
- case HttpHeaders.CONTENT_LENGTH:
- case HttpHeaders.DATE:
- case HttpHeaders.EXPIRES:
- case HttpHeaders.IF_MODIFIED_SINCE:
- case HttpHeaders.HOST:
+ case HttpHeaders.acceptCharsetHeader:
+ case HttpHeaders.acceptEncodingHeader:
+ case HttpHeaders.connectionHeader:
+ case HttpHeaders.contentLengthHeader:
+ case HttpHeaders.dateHeader:
+ case HttpHeaders.expiresHeader:
+ case HttpHeaders.ifModifiedSinceHeader:
+ case HttpHeaders.hostHeader:
throw new UnsupportedError('Unsupported or immutable property: $name');
- case HttpHeaders.CONTENT_TYPE:
+ case HttpHeaders.contentTypeHeader:
contentType = value;
break;
default:
@@ -162,16 +162,16 @@
@override
void remove(String name, Object value) {
switch (name) {
- case HttpHeaders.ACCEPT_CHARSET:
- case HttpHeaders.ACCEPT_ENCODING:
- case HttpHeaders.CONNECTION:
- case HttpHeaders.CONTENT_LENGTH:
- case HttpHeaders.DATE:
- case HttpHeaders.EXPIRES:
- case HttpHeaders.IF_MODIFIED_SINCE:
- case HttpHeaders.HOST:
+ case HttpHeaders.acceptCharsetHeader:
+ case HttpHeaders.acceptEncodingHeader:
+ case HttpHeaders.connectionHeader:
+ case HttpHeaders.contentLengthHeader:
+ case HttpHeaders.dateHeader:
+ case HttpHeaders.expiresHeader:
+ case HttpHeaders.ifModifiedSinceHeader:
+ case HttpHeaders.hostHeader:
throw new UnsupportedError('Unsupported or immutable property: $name');
- case HttpHeaders.CONTENT_TYPE:
+ case HttpHeaders.contentTypeHeader:
if (contentType == value) {
contentType = null;
}
@@ -190,16 +190,16 @@
@override
void removeAll(String name) {
switch (name) {
- case HttpHeaders.ACCEPT_CHARSET:
- case HttpHeaders.ACCEPT_ENCODING:
- case HttpHeaders.CONNECTION:
- case HttpHeaders.CONTENT_LENGTH:
- case HttpHeaders.DATE:
- case HttpHeaders.EXPIRES:
- case HttpHeaders.IF_MODIFIED_SINCE:
- case HttpHeaders.HOST:
+ case HttpHeaders.acceptCharsetHeader:
+ case HttpHeaders.acceptEncodingHeader:
+ case HttpHeaders.connectionHeader:
+ case HttpHeaders.contentLengthHeader:
+ case HttpHeaders.dateHeader:
+ case HttpHeaders.expiresHeader:
+ case HttpHeaders.ifModifiedSinceHeader:
+ case HttpHeaders.hostHeader:
throw new UnsupportedError('Unsupported or immutable property: $name');
- case HttpHeaders.CONTENT_TYPE:
+ case HttpHeaders.contentTypeHeader:
contentType = null;
break;
default:
@@ -239,12 +239,12 @@
};
[
- HttpHeaders.ACCEPT_CHARSET,
- HttpHeaders.ACCEPT_ENCODING,
- HttpHeaders.CONNECTION,
- HttpHeaders.CONTENT_LENGTH,
- HttpHeaders.CONTENT_TYPE,
- HttpHeaders.HOST
+ HttpHeaders.acceptCharsetHeader,
+ HttpHeaders.acceptEncodingHeader,
+ HttpHeaders.connectionHeader,
+ HttpHeaders.contentLengthHeader,
+ HttpHeaders.contentTypeHeader,
+ HttpHeaders.hostHeader
].forEach(forEachFunc);
_headers.keys.forEach(forEachFunc);
}
@@ -372,12 +372,12 @@
int separator = line.indexOf(':');
String name = line.substring(0, separator).toLowerCase().trim();
String value = line.substring(separator + 1).trim();
- if (name == HttpHeaders.TRANSFER_ENCODING &&
+ if (name == HttpHeaders.transferEncodingHeader &&
value.toLowerCase() != 'identity') {
throw new UnsupportedError(
'only identity transfer encoding is accepted');
}
- if (name == HttpHeaders.CONTENT_LENGTH) {
+ if (name == HttpHeaders.contentLengthHeader) {
contentLength = int.parse(value);
}
if (!headers.containsKey(name)) {
@@ -385,8 +385,8 @@
}
headers[name].add(value);
} else if (line.startsWith('HTTP/1.1') || line.startsWith('HTTP/1.0')) {
- statusCode = int
- .parse(line.substring('HTTP/1.x '.length, 'HTTP/1.x xxx'.length));
+ statusCode = int.parse(
+ line.substring('HTTP/1.x '.length, 'HTTP/1.x xxx'.length));
reasonPhrase = line.substring('HTTP/1.x xxx '.length);
inHeader = true;
} else {
@@ -450,9 +450,9 @@
@override
int get contentLength {
- String val = value(HttpHeaders.CONTENT_LENGTH);
+ String val = value(HttpHeaders.contentLengthHeader);
if (val != null) {
- return int.parse(val, onError: (_) => null);
+ return int.tryParse(val);
}
return null;
}
@@ -464,7 +464,7 @@
@override
ContentType get contentType {
- var val = value(HttpHeaders.CONTENT_TYPE);
+ var val = value(HttpHeaders.contentTypeHeader);
if (val != null) {
return ContentType.parse(val);
}
@@ -483,7 +483,7 @@
@override
DateTime get date {
- var val = value(HttpHeaders.DATE);
+ var val = value(HttpHeaders.dateHeader);
if (val != null) {
return DateTime.parse(val);
}
@@ -497,7 +497,7 @@
@override
DateTime get expires {
- var val = value(HttpHeaders.EXPIRES);
+ var val = value(HttpHeaders.expiresHeader);
if (val != null) {
return DateTime.parse(val);
}
@@ -514,7 +514,7 @@
@override
String get host {
- var val = value(HttpHeaders.HOST);
+ var val = value(HttpHeaders.hostHeader);
if (val != null) {
return Uri.parse(val).host;
}
@@ -523,7 +523,7 @@
@override
DateTime get ifModifiedSince {
- var val = value(HttpHeaders.IF_MODIFIED_SINCE);
+ var val = value(HttpHeaders.ifModifiedSinceHeader);
if (val != null) {
return DateTime.parse(val);
}
@@ -555,7 +555,7 @@
@override
int get port {
- var val = value(HttpHeaders.HOST);
+ var val = value(HttpHeaders.hostHeader);
if (val != null) {
return Uri.parse(val).port;
}
diff --git a/pubspec.yaml b/pubspec.yaml
index ba8c881..c1e1b3d 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,9 +1,11 @@
name: sync_http
-version: 0.1.1
+version: 0.1.2-dev
author: Dart Team <misc@dartlang.org>
description: Synchronous HTTP client for Dart.
homepage: https://github.com/dart-lang/sync_http
+
environment:
- sdk: '>=1.24.0-dev.0.0 <2.0.0'
+ sdk: '>=2.0.0-dev.64 <2.0.0'
+
dev_dependencies:
- test: ">=0.12.0 <0.13.0"
+ test: ^1.2.0
diff --git a/test/http_basic_test.dart b/test/http_basic_test.dart
index 4a3be09..54b52a4 100644
--- a/test/http_basic_test.dart
+++ b/test/http_basic_test.dart
@@ -122,7 +122,7 @@
// Return a 404.
void _notFoundHandler(HttpRequest request) {
var response = request.response;
- response.statusCode = HttpStatus.NOT_FOUND;
+ response.statusCode = HttpStatus.notFound;
String msg = "Page not found";
response.contentLength = msg.length;
response.headers.set("Content-Type", "text/html; charset=UTF-8");
@@ -133,7 +133,7 @@
// 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();
}
@@ -145,7 +145,7 @@
expect("www.dartlang.org:1234", equals(request.headers["Host"][0]));
expect("www.dartlang.org", equals(request.headers.host));
expect(1234, equals(request.headers.port));
- response.statusCode = HttpStatus.OK;
+ response.statusCode = HttpStatus.ok;
response.close();
}
@@ -155,7 +155,7 @@
new List<int>.generate((1 << 20), (i) => (i + 1) % 256);
String msg = expected.toString();
response.contentLength = msg.length;
- response.statusCode = HttpStatus.OK;
+ response.statusCode = HttpStatus.ok;
response.write(msg);
response.close();
}
@@ -227,7 +227,7 @@
var request =
SyncHttpClient.getUrl(new Uri.http("localhost:$port", "/0123456789"));
var response = request.close();
- expect(HttpStatus.OK, equals(response.statusCode));
+ expect(HttpStatus.ok, equals(response.statusCode));
expect(11, equals(response.contentLength));
expect("01234567890", equals(response.body));
testServerMain.close();
@@ -251,7 +251,7 @@
SyncHttpClient.postUrl(new Uri.http("localhost:$port", "/echo"));
request.write(data);
var response = request.close();
- expect(HttpStatus.OK, equals(response.statusCode));
+ expect(HttpStatus.ok, equals(response.statusCode));
expect(data, equals(response.body));
count++;
if (count < kMessageCount) {
@@ -274,10 +274,10 @@
Completer completer = new Completer();
TestServerMain testServerMain = new TestServerMain();
testServerMain.setServerStartedHandler((int port) {
- var request = SyncHttpClient
- .getUrl(new Uri.http("localhost:$port", "/thisisnotfound"));
+ var request = SyncHttpClient.getUrl(
+ new Uri.http("localhost:$port", "/thisisnotfound"));
var response = request.close();
- expect(HttpStatus.NOT_FOUND, equals(response.statusCode));
+ expect(HttpStatus.notFound, equals(response.statusCode));
expect("Page not found", equals(response.body));
testServerMain.close();
completer.complete();
@@ -290,10 +290,10 @@
Completer completer = new Completer();
TestServerMain testServerMain = new TestServerMain();
testServerMain.setServerStartedHandler((int port) {
- var request = SyncHttpClient
- .getUrl(new Uri.http("localhost:$port", "/reasonformoving"));
+ var request = SyncHttpClient.getUrl(
+ new Uri.http("localhost:$port", "/reasonformoving"));
var response = request.close();
- expect(HttpStatus.MOVED_PERMANENTLY, equals(response.statusCode));
+ expect(HttpStatus.movedPermanently, equals(response.statusCode));
expect(
"Don't come looking here any more\r\n", equals(response.reasonPhrase));
testServerMain.close();
@@ -312,7 +312,7 @@
var response = request.close();
String expected =
new List<int>.generate((1 << 20), (i) => (i + 1) % 256).toString();
- expect(HttpStatus.OK, equals(response.statusCode));
+ expect(HttpStatus.ok, equals(response.statusCode));
expect(expected.length, equals(response.contentLength));
expect(expected.toString(), equals(response.body));
testServerMain.close();