Skip to content

Commit

Permalink
workaround SSL error if CA certs not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Silva committed Jul 22, 2013
1 parent 44b81cd commit c22a222
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/httpLoader.js
@@ -1,6 +1,7 @@
//
// Basic schema loader that loads schemas over HTTP[S].
// Wrapper for http.get.
// Example schema loader that loads schemas over HTTP[S].
// Wrapper for http.get. For SSL connections, the CA certificate is
// not verified.
//
// If you were to write your own HTTP[S] loader, you’d probably want
// to use https://github.com/mikeal/request to do the heavy lifting.
Expand All @@ -23,12 +24,15 @@ function loader(ref, callback, _depth) {
return callback(err);
}

var urlParts = url.parse(ref);
var options = url.parse(ref);

var getter = http.get;
if (urlParts.protocol === 'https:') { getter = https.get; }
if (options.protocol === 'https:') {
options.rejectUnauthorized = false;
getter = https.get;
}

getter(ref, function(res) {
getter(options, function(res) {

if (res.statusCode >= 300 && res.statusCode <= 399) {
// redirect
Expand Down

0 comments on commit c22a222

Please sign in to comment.