Skip to content
Browse files

[#344] Requests to "www.domain" when routing is just "domain" causes …

…every future request to be 404
  • Loading branch information...
1 parent b74be93 commit 40c2fe02c15893c08bc95b2a5e1f1910fa3041a9 @pepite pepite committed Oct 29, 2010
Showing with 18 additions and 7 deletions.
  1. +18 −7 framework/src/play/mvc/Router.java
View
25 framework/src/play/mvc/Router.java
@@ -10,6 +10,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
import jregex.Matcher;
import jregex.Pattern;
import jregex.REFlags;
@@ -205,7 +206,7 @@ static void parse(VirtualFile routeFile, String prefix) {
/**
* In PROD mode and if the routes are already loaded, this does nothing.
- *
+ * <p/>
* <p>In DEV mode, this checks each routes file's "last modified" time to see if the routes need updated.
*
* @param prefix The prefix that the path of all routes in this route file start with. This prefix should not end with a '/' character.
@@ -346,6 +347,7 @@ public static String reverse(VirtualFile file, boolean absolute) {
}
if (absolute) {
if (!StringUtils.isEmpty(route.host)) {
+ // Compute the host
to = (Http.Request.current().secure ? "https://" : "http://") + route.host + to;
} else {
to = Http.Request.current().getBase() + to;
@@ -393,8 +395,16 @@ public static ActionDefinition reverse(String action, Map<String, Object> args)
inPathArgs.add(arg.name);
Object value = args.get(arg.name);
if (value == null) {
- allRequiredArgsAreHere = false;
- break;
+ String host = route.host.replaceAll("\\{", "").replaceAll("\\}", "");
+ Logger.trace("arg.name " + arg.name + " host " + host);
+ if (host.equals(arg.name) || host.matches(arg.name)) {
+ args.remove(arg.name);
+ route.host = Http.Request.current().domain;
+ break;
+ } else {
+ allRequiredArgsAreHere = false;
+ break;
+ }
} else {
if (value instanceof List<?>) {
@SuppressWarnings("unchecked")
@@ -417,7 +427,7 @@ public static ActionDefinition reverse(String action, Map<String, Object> args)
continue; // format is a special key
}
if (!args.containsKey(staticKey) || (args.get(staticKey) == null)
- || !args.get(staticKey).toString().equals(route.staticArgs.get(staticKey))) {
+ || !args.get(staticKey).toString().equals(route.staticArgs.get(staticKey))) {
allRequiredArgsAreHere = false;
break;
}
@@ -625,7 +635,8 @@ 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("\\.", "\\\\.").replaceAll("\\{.*\\}", "(.*)");
+
Logger.trace("pattern [" + pattern + "]");
Logger.trace("host [" + host + "]");
@@ -729,9 +740,9 @@ private boolean contains(String accept) {
* Check if the parts of a HTTP request equal this Route.
*
* @param method GET/POST/etc.
- * @param path Part after domain and before query-string. Starts with a "/".
+ * @param path Part after domain and before query-string. Starts with a "/".
* @param accept Format, e.g. html.
- * @param host AKA the domain.
+ * @param host AKA the domain.
* @return ???
*/
public Map<String, String> matches(String method, String path, String accept, String host) {

0 comments on commit 40c2fe0

Please sign in to comment.
Something went wrong with that request. Please try again.