Issue by kaisellgren
_Originally opened as dart-lang/sdk#17173_
I'm trying to read URIs such as http://devblog.paypal.com/feed/ that lead to a bad certificate exception.
Can we add a callback to handle bad certificates in the HTTP package? For .get, .read, etc.?
Simplest reproduce step is: http.read('http://devblog.paypal.com/feed/');
_This comment was originally written by f41ltastic...@gmail.com_
If this was triaged, I don't see where.
Comment by sgjesse
In dart.io the HttpClient have a callback to handle bad certificates, e.g.
import 'dart:io';
import 'dart:convert';
void main(List<String> args) {
var client = new HttpClient();
client.badCertificateCallback = (_, __, ___) => true;
client.getUrl(Uri.parse("http://devblog.paypal.com/feed/"))
.then((req) => req.close())
.then((resp) => resp.transform(UTF8.decoder).join(''))
.then(print)
.whenComplete(() => client.close());
}
This can be done by setting the innerClient within a 'IoClient'.
import 'dart:io';
import 'package:http/http.dart' as http;
bool _certificateCheck(X509Certificate cert, String host, int port) =>
host == 'devblog.paypal.com';
http.Client paypalClient() {
var ioClient = new HttpClient()
..badCertificateCallback = _certificateCheck;
return new http.IOClient(ioClient);
}
update,
'new http.IOClient()' might not build, now use IOClient() or new IOClient() directly with the following import :
import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:http/io_client.dart'; //has IOClient
bool _certificateCheck(X509Certificate cert, String host, int port) => true;
http.Client paypalClient() {
var ioClient = new HttpClient()
..badCertificateCallback = _certificateCheck;
return new IOClient(ioClient);
}
Most helpful comment
This can be done by setting the innerClient within a 'IoClient'.