java-org.hwo/src/org/hwo/net/http/HttpRequestURI.java

67 lines
1.2 KiB
Java

package org.hwo.net.http;
import java.util.Arrays;
public class HttpRequestURI {
private String requestPath;
private HttpServerRequest request;
private String path;
private String[] elements;
private String queryString;
private String hostname;
private Integer port;
public HttpRequestURI(HttpServerRequest request,String path)
{
this.requestPath = path;
this.request = request;
}
public void decode()
{
if (requestPath.indexOf('?')>0)
{
queryString = requestPath.substring(requestPath.indexOf('?')+1);
this.path = requestPath.substring(0,requestPath.indexOf('?'));
} else
{
queryString = "";
this.path = requestPath;
}
String ptokens[] = this.path.split("/");
if (ptokens.length>0)
elements = Arrays.copyOfRange(ptokens, 1, ptokens.length);
else
elements = new String[0];
hostname = request.getRequestHeader("Host");
if (hostname.indexOf(':')>0)
{
String[] tokens = hostname.split(":");
hostname = tokens[0];
port = Integer.parseInt(tokens[1]);
}
}
public String getPath()
{
return path;
}
public String getQueryString()
{
return queryString;
}
public String[] getPathElements()
{
return elements;
}
}