Skip to content

Commit

Permalink
[#302]
Browse files Browse the repository at this point in the history
  • Loading branch information
pepite committed Oct 17, 2010
1 parent 4e3ede1 commit bce60a8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
16 changes: 9 additions & 7 deletions framework/src/play/mvc/Router.java
Expand Up @@ -323,7 +323,7 @@ public static String reverse(VirtualFile file, boolean absolute) {
}
if (absolute) {
if (!StringUtils.isEmpty(route.host)) {
to = "http://" + route.host + to;
to = (Http.Request.current().secure ? "https://" : "http://") + route.host + to;
} else {
to = Http.Request.current().getBase() + to;
}
Expand Down Expand Up @@ -502,10 +502,12 @@ public String toString() {
}

public void absolute() {
if (StringUtils.isEmpty(host)) {
url = Http.Request.current().getBase() + url;
} else {
url = "http://" + host + url;
if (!url.startsWith("http")) {
if (StringUtils.isEmpty(host)) {
url = Http.Request.current().getBase() + url;
} else {
url = (Http.Request.current().secure ? "https://" : "http://") + host + url;
}
}
}

Expand Down Expand Up @@ -571,7 +573,7 @@ public void compute() {
String p = this.path;
this.path = p.substring(p.indexOf("/"));
this.host = p.substring(0, p.indexOf("/"));
String pattern = host.replaceAll("\\.","\\\\.").replaceFirst("\\{.*\\}", "(.*)");
String pattern = host.replaceAll("\\.", "\\\\.").replaceFirst("\\{.*\\}", "(.*)");
Logger.trace("pattern [" + pattern + "]");
Logger.trace("host [" + host + "]");

Expand All @@ -580,7 +582,7 @@ public void compute() {

if (m.matches()) {
if (this.host.contains("{")) {
String name = m.group(1).replace("{", "").replace("}","");
String name = m.group(1).replace("{", "").replace("}", "");
hostArg = new Arg();
hostArg.name = name;
Logger.trace("hostArg name [" + name + "]");
Expand Down
10 changes: 9 additions & 1 deletion framework/src/play/server/PlayHandler.java
Expand Up @@ -49,6 +49,11 @@ public class PlayHandler extends SimpleChannelUpstreamHandler {

private final static String signature = "Play! Framework;" + Play.version + ";" + Play.mode.name().toLowerCase();

public Request processRequest(Request request) {
return request;
}


@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
Logger.trace("messageReceived: begin");
Expand All @@ -57,7 +62,9 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Ex
if (msg instanceof HttpRequest) {
final HttpRequest nettyRequest = (HttpRequest) msg;
try {
final Request request = parseRequest(ctx, nettyRequest);
Request request = parseRequest(ctx, nettyRequest);
request = processRequest(request);

final Response response = new Response();

Http.Response.current.set(response);
Expand All @@ -81,6 +88,7 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Ex
}
Logger.trace("messageReceived: end");
}

private static Map<String, RenderStatic> staticPathsCache = new HashMap<String, RenderStatic>();

public class NettyInvocation extends Invoker.Invocation {
Expand Down
22 changes: 15 additions & 7 deletions framework/src/play/server/ssl/SslPlayHandler.java
Expand Up @@ -4,6 +4,7 @@
import org.jboss.netty.handler.codec.http.*;
import org.jboss.netty.handler.ssl.SslHandler;
import play.Logger;
import play.mvc.Http;
import play.server.PlayHandler;
import play.server.Server;

Expand All @@ -17,16 +18,23 @@ public class SslPlayHandler extends PlayHandler {
public SslPlayHandler() {
}

@Override
public Http.Request processRequest(Http.Request request) {
request.secure = true;
return request;
}


@Override
public void channelConnected(
ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
ctx.setAttachment(e.getValue());
// Get the SslHandler in the current pipeline.
final SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
sslHandler.setEnableRenegotiation(false);
// Get notified when SSL handshake is done.
ChannelFuture handshakeFuture = sslHandler.handshake();
handshakeFuture.addListener(new SslListener());
ctx.setAttachment(e.getValue());
// Get the SslHandler in the current pipeline.
final SslHandler sslHandler = ctx.getPipeline().get(SslHandler.class);
sslHandler.setEnableRenegotiation(false);
// Get notified when SSL handshake is done.
ChannelFuture handshakeFuture = sslHandler.handshake();
handshakeFuture.addListener(new SslListener());
}

private static final class SslListener implements ChannelFutureListener {
Expand Down

0 comments on commit bce60a8

Please sign in to comment.