mathopd  

[PATCH] Include query string in Location redirects

Mr Allwyn Fernandes
Mon, 10 Sep 2007 12:29:24 -0700

Hi all,

I noticed that when using the "Location http://"; syntax for redirects, Mathopd 
doesn't include the query string in the redirected url. For example, using 
the configuration:

Host example.net
Control {
        Alias /
        Location http://example.com
}

if you access the url:

http://example.net/pages/index.php?q=4

you are redirected to:

http://example.com/pages/index.php

Since I needed the query string to be passed to the redirected page, I've 
hacked up a quick patch which adds it back in to the destination url:

http://example.com/pages/index.php?q=4

If there is no query string, then no change is made. (Specifically, the 
question mark is not added in, either.) So http://example.net/sample.html 
redirects to http://example.com/sample.html

It's a fairly straightforward change, and I've included patches for both 1.5p6 
and 1.6b9.

The patch can be applied as 

/tmp/mathopd-1.6b9$ gunzip QueryStringInRedirect.1.6b9.diff.gz | patch -p1 

If there are any problems, questions or comments, please don't hesitate to let 
me know.

Cheers,

Allwyn.

-- 
Allwyn Fernandes
Director
Stobor Pty Ltd

Mobile: + 61 430 436 758
LinkedIn: http://www.linkedin.com/in/AllwynFernandes
diff -ru mathopd-1.5p6/src/request.c mathopd-1.5qs/src/request.c
--- mathopd-1.5p6/src/request.c	2007-07-21 20:48:00.000000000 +1000
+++ mathopd-1.5qs/src/request.c	2007-09-11 04:50:41.086724848 +1000
@@ -1497,9 +1497,14 @@
 			return -1;
 		break;
 	case 302:
-		if (r->location)
-			if (pool_print(p, "Location: %s\r\n", r->location) == -1)
-				return -1;
+		if (r->location) {
+			if (r->args) {
+				if (pool_print(p, "Location: %s?%s\r\n", r->location, r->args) == -1)
+					return -1;
+			} else {
+				if (pool_print(p, "Location: %s\r\n", r->location) == -1)
+					return -1;
+			}
 		break;
 	case 401:
 		if (r->c && r->c->realm)
@@ -1552,8 +1557,13 @@
 		return -1;
 	switch (r->status) {
 	case 302:
-		if (pool_print(p, "This document has moved to URL <a href=\"%s\">%s</a>.\n", r->location, r->location) == -1)
-			return -1;
+		if (r->args) {
+			if (pool_print(p, "This document has moved to URL <a href=\"%s?%s\">%s?%s</a>.\n", r->location, r->args, r->location, r->args) == -1)
+				return -1;
+		} else {
+			if (pool_print(p, "This document has moved to URL <a href=\"%s\">%s</a>.\n", r->location, r->location) == -1)
+				return -1;
+		}
 		break;
 	case 401:
 		if (pool_print(p, "You need proper authorization to use this resource.\n") == -1)

Attachment: QueryStringInRedirect.1.6b9.diff.gz
Description: GNU Zip compressed data

Attachment: QueryStringInRedirect.1.5p6.diff.gz
Description: GNU Zip compressed data