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 ca6e28c commit 9744993
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 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
13 changes: 11 additions & 2 deletions framework/src/play/server/PlayHandler.java
Expand Up @@ -49,6 +49,10 @@ 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 +61,8 @@ 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 +86,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 Expand Up @@ -367,6 +373,7 @@ static String getRemoteIPAddress(ChannelHandlerContext ctx) {
return fullAddress;
}


public static Request parseRequest(ChannelHandlerContext ctx, HttpRequest nettyRequest) throws Exception {
Logger.trace("parseRequest: begin");
Logger.trace("parseRequest: URI = " + nettyRequest.getUri());
Expand All @@ -378,10 +385,11 @@ public static Request parseRequest(ChannelHandlerContext ctx, HttpRequest nettyR
querystring = nettyRequest.getUri().substring(index + 1);
}

final Request request = new Request();
final Http.Request request = new Http.Request();

request.remoteAddress = getRemoteIPAddress(ctx);
request.method = nettyRequest.getMethod().getName();

request.path = path;
request.querystring = querystring;
final String contentType = nettyRequest.getHeader(CONTENT_TYPE);
Expand Down Expand Up @@ -488,6 +496,7 @@ protected static void addToRequest(HttpRequest nettyRequest, Request request) {
}
}


@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
throws Exception {
Expand Down
7 changes: 7 additions & 0 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 Down Expand Up @@ -42,6 +43,12 @@ public void operationComplete(ChannelFuture future) throws Exception {

}

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

@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e)
throws Exception {
Expand Down

0 comments on commit 9744993

Please sign in to comment.