Skip to content

Commit

Permalink
fix: ssl: should support self-signed certs on the proxy target (for l…
Browse files Browse the repository at this point in the history
…ocal development) - fixes #17
  • Loading branch information
shakyShane committed Oct 12, 2018
1 parent ee4646d commit 279b271
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/lib/presets/m2/static/post_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ xhr.open('POST', '/__bs/post');
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function() {
if (xhr.status === 200) {
console.log('sent');
console.log('config-gen: merged RequireJS config sent');
}
else if (xhr.status !== 200) {
alert('Request failed. Returned status of ' + xhr.status);
console.log('config-gen: request failed, returned status of ' + xhr.status);
}
};
xhr.send(JSON.stringify(requirejs.s.contexts._.config));
16 changes: 13 additions & 3 deletions src/lib/proxy_transform.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use actix::Actor;
use actix_web::client::ClientConnector;
use actix_web::client::ClientRequestBuilder;
use actix_web::http::{header, HeaderMap, Method};
use actix_web::{client, dev, http, Error, HttpMessage, HttpRequest, HttpResponse};
use base64::encode;
use futures::Future;
use headers::clone_headers;
use openssl::ssl::SslConnector;
use openssl::ssl::{SslMethod, SslVerifyMode};
use preset::AppState;
use presets::m2::opts::{AuthBasic, M2PresetOptions};
use std::str;
Expand Down Expand Up @@ -49,11 +53,17 @@ pub fn proxy_req_setup(original_request: &HttpRequest<AppState>) -> ClientReques
}
);

// now choose how to handle it
// if the client responds with a request we want to alter (such as HTML)
// then we need to buffer the body into memory in order to apply regex's on the string
let mut outgoing = client::ClientRequest::build();

// Since this is a development tool only, we're being risky here
// and just disabling all SSL verifications
let mut ssl_conn = SslConnector::builder(SslMethod::tls()).unwrap();
ssl_conn.set_verify(SslVerifyMode::NONE);

let conn = ClientConnector::with_connector(ssl_conn.build()).start();

outgoing
.with_connector(conn)
.method(original_request.method().clone())
.uri(next_url);

Expand Down

0 comments on commit 279b271

Please sign in to comment.