blob: 0522e390542e2575ea20b0a9306f880c3cd4ccf8 [file] [log] [blame]
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// 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.
/// @assertion HttpHeaders defaultResponseHeaders
/// Default set of headers added to all response objects.
///
/// By default the following headers are in this set:
///
/// Content-Type: text/plain; charset=utf-8
/// X-Frame-Options: SAMEORIGIN
/// X-Content-Type-Options: nosniff
/// X-XSS-Protection: 1; mode=block
///
/// If the Server header is added here and the serverHeader is set as well then
/// the value of serverHeader takes precedence.
/// @description Checks that response object contains all of the headers returned
/// by this property
/// @author sgrekhov@unipro.ru
import "dart:io";
import "../../../Utils/expect.dart";
test() async {
HttpServer server = await HttpServer.bind(InternetAddress.loopbackIPv4, 0);
asyncStart();
server.defaultResponseHeaders.removeAll("x-content-type-options");
server.listen((HttpRequest request) {
request.response.close();
server.close();
asyncEnd();
});
asyncStart();
HttpClient client = new HttpClient();
client
.getUrl(Uri.parse(
"http://${InternetAddress.loopbackIPv4.address}:${server.port}"))
.then((HttpClientRequest request) {
return request.close();
}).then((HttpClientResponse response) {
int counter = 0;
response.headers.forEach((String name, List<String> value) {
if (name == "x-frame-options") {
Expect.listEquals(["SAMEORIGIN"], value);
counter++;
}
if (name == "content-type") {
Expect.listEquals(["text/plain; charset=utf-8"], value);
counter++;
}
if (name == "x-xss-protection") {
Expect.listEquals(["1; mode=block"], value);
counter++;
}
if (name == "x-content-type-options") {
Expect.listEquals(["nosniff"], value);
counter++;
}
});
Expect.equals(3, counter);
asyncEnd();
});
asyncEnd();
}
main() {
asyncStart();
test();
}