Added redirection page and fixed Navigation class
This commit is contained in:
parent
2c46c7ecf3
commit
095109eb41
4 changed files with 133 additions and 46 deletions
|
|
@ -86,6 +86,22 @@ public class HttpHeader {
|
|||
public String getRequestURL(){
|
||||
return url;
|
||||
}
|
||||
/**
|
||||
* @return parses out the page name from the request url and returns it.
|
||||
*/
|
||||
public String getRequestPage() {
|
||||
if (url != null){
|
||||
int start = 0;
|
||||
if (url.charAt(0) == '/')
|
||||
start = 1;
|
||||
int end = url.indexOf('?');
|
||||
if (end < 0)
|
||||
end = url.length();
|
||||
|
||||
return url.substring(start, end);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* @return a Iterator with all defined url keys
|
||||
*/
|
||||
|
|
@ -187,4 +203,5 @@ public class HttpHeader {
|
|||
public String toStringAttributes(){
|
||||
return Converter.toString(urlAttributes);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ public class HttpFilePage implements HttpPage{
|
|||
out.setHeader("Cache-Control", "max-age=" + MAX_CACHE_AGE_SECONDS);
|
||||
out.setHeader("ETag", "\"" + eTag + "\"");
|
||||
|
||||
if (headers.getHeader("If-None-Match") != null &&
|
||||
if (eTag != null && headers.getHeader("If-None-Match") != null &&
|
||||
eTag.equals(StringUtil.trimQuotes(headers.getHeader("If-None-Match")))){ // File has not changed
|
||||
out.setStatusCode(304);
|
||||
} else {
|
||||
|
|
|
|||
48
src/zutil/net/http/page/HttpRedirectPage.java
Executable file
48
src/zutil/net/http/page/HttpRedirectPage.java
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
package zutil.net.http.page;
|
||||
|
||||
import zutil.net.http.HttpHeader;
|
||||
import zutil.net.http.HttpPage;
|
||||
import zutil.net.http.HttpPrintStream;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2016-06-19.
|
||||
*/
|
||||
public class HttpRedirectPage implements HttpPage{
|
||||
|
||||
private String redirectUrl;
|
||||
|
||||
|
||||
public HttpRedirectPage(String redirectUrl){
|
||||
this.redirectUrl = redirectUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void respond(HttpPrintStream out,
|
||||
HttpHeader headers,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) throws IOException {
|
||||
|
||||
out.setStatusCode(301);
|
||||
out.setHeader("Location", redirectUrl);
|
||||
out.print(
|
||||
"<!DOCTYPE HTML>\n" +
|
||||
"<html lang='en-US'>\n" +
|
||||
" <head>\n" +
|
||||
" <meta charset='UTF-8'>\n" +
|
||||
" <meta http-equiv='refresh' content='0;url="+ redirectUrl +"'>\n" +
|
||||
" <script type='text/javascript'>\n" +
|
||||
" window.location.href = '"+ redirectUrl +"'\n" +
|
||||
" </script>\n" +
|
||||
" <title>Page Redirection</title>\n" +
|
||||
" </head>\n" +
|
||||
" <body>\n" +
|
||||
" If you are not redirected automatically, follow the <a href='"+ redirectUrl +"'>link to "+ redirectUrl +"</a>\n" +
|
||||
" </body>\n" +
|
||||
"</html>"
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue