Handle custom parameters,

main
sigonasr2, Sig, Sigo 3 years ago
parent e6289eeedc
commit 7807680b25
  1. 24
      out/codeBackground
  2. 14
      sigServer.java

@ -12,7 +12,18 @@
//This is valid. //This is valid.
if (splitter[0].equals("GET")) { //This is a GET request. if (splitter[0].equals("GET")) { //This is a GET request.
if (splitter[2].equals("HTTP/1.1")||splitter[2].equals("HTTP/2.0")) { if (splitter[2].equals("HTTP/1.1")||splitter[2].equals("HTTP/2.0")) {
String requestloc = splitter[1]; String[] requestSplit = splitter[1].split(Pattern.quote("?"));
String requestloc = requestSplit[0];
HashMap<String,String> requestParams = new HashMap<>();
if (requestSplit.length>1) {
String[] params = requestSplit[1].split(Pattern.quote("&"));
for (String s : params) {
String key = s.substring(0,s.indexOf('='));
String value = s.substring(s.indexOf('=')+1);
requestParams.put(key,value);
}
System.out.println(" ==Params for this request are: "+requestParams);
}
if (requestloc.equals("/")) { if (requestloc.equals("/")) {
//Send default directory. //Send default directory.
CreateRequest(client,"200","OK","testfile.html"); CreateRequest(client,"200","OK","testfile.html");
@ -27,14 +38,3 @@
while (!(line=in.readLine()).isBlank()) { while (!(line=in.readLine()).isBlank()) {
//System.out.println(line); //System.out.println(line);
} }
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
private void CreateRawRequest(OutputStream stream, String statusCode, String statusMsg, String contentType, byte[] content) {
try {
stream.write(("HTTP/1.1 "+statusCode+" "+statusMsg+"\r\n").getBytes());
stream.write(("ContentType: "+contentType+"\r\n").getBytes());

@ -7,6 +7,7 @@ import java.net.Socket;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.HashMap;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class sigServer { public class sigServer {
@ -26,7 +27,18 @@ public class sigServer {
//This is valid. //This is valid.
if (splitter[0].equals("GET")) { //This is a GET request. if (splitter[0].equals("GET")) { //This is a GET request.
if (splitter[2].equals("HTTP/1.1")||splitter[2].equals("HTTP/2.0")) { if (splitter[2].equals("HTTP/1.1")||splitter[2].equals("HTTP/2.0")) {
String requestloc = splitter[1]; String[] requestSplit = splitter[1].split(Pattern.quote("?"));
String requestloc = requestSplit[0];
HashMap<String,String> requestParams = new HashMap<>();
if (requestSplit.length>1) {
String[] params = requestSplit[1].split(Pattern.quote("&"));
for (String s : params) {
String key = s.substring(0,s.indexOf('='));
String value = s.substring(s.indexOf('=')+1);
requestParams.put(key,value);
}
System.out.println(" ==Params for this request are: "+requestParams);
}
if (requestloc.equals("/")) { if (requestloc.equals("/")) {
//Send default directory. //Send default directory.
CreateRequest(client,"200","OK","testfile.html"); CreateRequest(client,"200","OK","testfile.html");

Loading…
Cancel
Save