Implement a basic HTTP request processor
This commit is contained in:
parent
20fe3e8ee1
commit
da330a4e87
|
@ -1,15 +1,28 @@
|
|||
package com.spookyinternet.cobweb;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class HttpRequest {
|
||||
public String method;
|
||||
public String path;
|
||||
public Map<String, String> headers;
|
||||
public String[] params;
|
||||
|
||||
public HttpRequest(BufferedReader reader) {
|
||||
HttpTokenStream tokens = new HttpTokenStream(reader);
|
||||
boolean processed = false;
|
||||
|
||||
while(tokens.hasNext()) {
|
||||
while(tokens.hasNext() && !processed) {
|
||||
HttpToken token = tokens.next();
|
||||
|
||||
if(token.line == 1 && token.sol) {
|
||||
this.method = token.value.toLowerCase();
|
||||
} else if(token.line == 1 && token.seq == 3) {
|
||||
this.path = token.value;
|
||||
}
|
||||
|
||||
processed = token.value == "\r\n" && token.complete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue