add proxy config to docker, fix IP x-forwarded-for

This commit is contained in:
Brandon Thomas
2020-06-29 23:56:26 -04:00
parent b50f84c280
commit 4a5ec4bdba
2 changed files with 10 additions and 1 deletions
+2
View File
@@ -45,6 +45,8 @@ RUN apt-get update \
curl \
&& apt-get clean
COPY proxy_configs.toml .
EXPOSE 8080
CMD LD_LIBRARY_PATH=/usr/lib /tts-service-proxy
+8 -1
View File
@@ -17,6 +17,8 @@ use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
use rand::seq::IteratorRandom;
use hyper::http::header::HeaderName;
use hyper::header::HeaderValue;
type BoxFut = Box<dyn Future<Item=Response<Body>, Error=hyper::Error> + Send>;
@@ -122,7 +124,12 @@ impl Router {
}
fn speak_proxy(req: Request<Body>, remote_addr: SocketAddr, router: Arc<Router>, endpoint: &'static str) -> BoxFut {
let headers = req.headers().clone();
let mut headers = req.headers().clone();
let forwarded_for = HeaderValue::from_str(&remote_addr.ip().to_string())
.ok()
.unwrap_or(HeaderValue::from_static("127.0.0.1"));
headers.insert(HeaderName::from_static("x-forwarded-for"), forwarded_for);
Box::new(req.into_body().concat2().map(move |b| { // Builds a BoxedFut to return
let request_bytes = b.as_ref();