Skip to content

Commit

Permalink
#277 TkForward fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed May 10, 2015
1 parent da6545c commit f42cfda
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/main/java/org/takes/facets/forward/TkForward.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.takes.facets.forward;

import java.io.IOException;
import java.io.InputStream;
import lombok.EqualsAndHashCode;
import org.takes.Request;
import org.takes.Response;
Expand Down Expand Up @@ -63,7 +64,44 @@ public Response act(final Request req) throws IOException {
} catch (final RsForward ex) {
res = ex;
}
return res;
return new TkForward.Safe(res);
}

/**
* Safe response.
*/
private static final class Safe implements Response {
/**
* Original response.
*/
private final transient Response origin;
/**
* Ctor.
* @param res Original response
*/
private Safe(final Response res) {
this.origin = res;
}
@Override
public Iterable<String> head() throws IOException {
Iterable<String> head;
try {
head = this.origin.head();
} catch (final RsForward ex) {
head = ex.head();
}
return head;
}
@Override
public InputStream body() throws IOException {
InputStream body;
try {
body = this.origin.body();
} catch (final RsForward ex) {
body = ex.body();
}
return body;
}
}

}

0 comments on commit f42cfda

Please sign in to comment.