2016-02-29 20:48:17 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.httpd.module;
|
2013-08-27 01:48:04 +00:00
|
|
|
|
2013-09-03 14:28:56 +00:00
|
|
|
import java.net.Socket;
|
2013-09-18 01:31:46 +00:00
|
|
|
import java.util.HashMap;
|
2013-08-27 01:48:04 +00:00
|
|
|
import java.util.Map;
|
2016-02-29 20:48:17 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.HTTPSession;
|
|
|
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Method;
|
|
|
|
import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
2013-08-27 01:48:04 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public abstract class HTTPDModule
|
2013-08-27 01:48:04 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2013-08-27 01:48:04 +00:00
|
|
|
protected final String uri;
|
|
|
|
protected final Method method;
|
|
|
|
protected final Map<String, String> headers;
|
|
|
|
protected final Map<String, String> params;
|
2013-09-03 14:28:56 +00:00
|
|
|
protected final Socket socket;
|
2013-09-18 01:31:46 +00:00
|
|
|
protected final HTTPSession session;
|
2013-08-27 01:48:04 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public HTTPDModule(HTTPSession session)
|
2013-08-27 01:48:04 +00:00
|
|
|
{
|
2013-09-18 01:31:46 +00:00
|
|
|
this.uri = session.getUri();
|
|
|
|
this.method = session.getMethod();
|
|
|
|
this.headers = session.getHeaders();
|
|
|
|
this.params = session.getParms();
|
|
|
|
this.socket = session.getSocket();
|
|
|
|
this.session = session;
|
2013-08-27 01:48:04 +00:00
|
|
|
}
|
|
|
|
|
2013-08-27 19:09:07 +00:00
|
|
|
public String getBody()
|
|
|
|
{
|
2013-09-03 20:35:11 +00:00
|
|
|
return null;
|
2013-08-27 19:09:07 +00:00
|
|
|
}
|
2013-08-27 01:48:04 +00:00
|
|
|
|
2013-08-27 19:09:07 +00:00
|
|
|
public String getTitle()
|
|
|
|
{
|
2013-09-03 20:35:11 +00:00
|
|
|
return null;
|
2013-08-27 19:09:07 +00:00
|
|
|
}
|
2013-08-27 01:48:04 +00:00
|
|
|
|
2013-08-27 17:49:45 +00:00
|
|
|
public String getStyle()
|
|
|
|
{
|
2013-09-03 20:35:11 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getScript()
|
|
|
|
{
|
|
|
|
return null;
|
2013-08-27 17:49:45 +00:00
|
|
|
}
|
|
|
|
|
2013-08-27 19:09:07 +00:00
|
|
|
public Response getResponse()
|
2013-08-27 01:48:04 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
return new HTTPDPageBuilder(getBody(), getTitle(), getStyle(), getScript()).getResponse();
|
2013-08-27 01:48:04 +00:00
|
|
|
}
|
2013-09-18 01:31:46 +00:00
|
|
|
|
|
|
|
protected final Map<String, String> getFiles()
|
|
|
|
{
|
|
|
|
Map<String, String> files = new HashMap<String, String>();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
session.parseBody(files);
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2013-09-18 01:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
2013-08-27 01:48:04 +00:00
|
|
|
}
|