Skip to content

Commit

Permalink
Fixed/improved the simple proxy handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Jun 4, 2016
1 parent a1efde2 commit 1bc6d5e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions rapidoid-web/src/main/java/org/rapidoid/goodies/ProxyHandler.java
Expand Up @@ -7,6 +7,8 @@
import org.rapidoid.http.*;
import org.rapidoid.http.impl.HttpIO;

import java.util.Map;

/*
* #%L
* rapidoid-web
Expand Down Expand Up @@ -43,18 +45,28 @@ public ProxyHandler(String host) {
public Object execute(final Req req, final Resp resp) throws Exception {
req.async();

Map<String, String> headers = req.headers();

client.req()
.verb(req.verb())
.url(host + req.uri())
.headers(req.headers())
.headers(headers)
.body(req.body())
.raw(true)
.execute(new Callback<HttpResp>() {

@Override
public void onDone(HttpResp result, Throwable error) {
if (error == null) {
resp.raw(result.raw()).done();
Map<String, String> hdrs = result.headers();
byte[] body = result.bodyBytes();

hdrs.remove("Transfer-Encoding");

resp.headers().putAll(hdrs);
resp.code(result.code());
resp.body(body);
resp.done();
} else {
HttpIO.errorAndDone(req, error, req.custom().errorHandler());
}
Expand Down

0 comments on commit 1bc6d5e

Please sign in to comment.