Skip to content

Commit

Permalink
Merge pull request #7 from Kerosene-Labs/feat/6
Browse files Browse the repository at this point in the history
Feat/6
  • Loading branch information
hlafaille authored Aug 9, 2024
2 parents ab262b2 + 9b9712d commit 6ab42c7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>io.kerosenelabs</groupId>
<artifactId>kindling</artifactId>
<packaging>jar</packaging>
<version>0.1.2</version>
<version>0.1.3</version>
<name>kindling</name>
<url>http://maven.apache.org</url>
<dependencies>
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/kerosenelabs/kindling/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ public HttpMethod getHttpMethod() {
return httpMethod;
}

public HashMap<String, String> getHeaders() {
return headers;
}

public String getProtocolVersion() {
return protocolVersion;
}

public String getContent() {
return content;
}

/**
* Get a valid re-creation of the HTTP message
*/
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/kerosenelabs/kindling/KindlingServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ private void dispatchWorker(SSLSocket sslSocket) {
Thread.ofVirtual().name(workerThreadName).start(() -> {
try (
InputStream inputStream = sslSocket.getInputStream();
InputStreamReader inputStreamReder = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReder);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
OutputStream outputStream = sslSocket.getOutputStream();) {

// parse our http request
Expand All @@ -137,7 +137,7 @@ private void dispatchWorker(SSLSocket sslSocket) {
// iterate over request handlers, finding one that can take this request
HttpResponse response = null;
for (RequestHandler requestHandler : requestHandlers) {
if (requestHandler.accepts(httpRequest.getHttpMethod(), httpRequest.getResource())) {
if (requestHandler.accepts(httpRequest)) {
try {
response = requestHandler.handle(httpRequest);
} catch (Exception e) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/kerosenelabs/kindling/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static void main(String[] args) throws KindlingException {
* Tell the server what type of request this handler can work with
*/
@Override
public boolean accepts(HttpMethod httpMethod, String resource) throws KindlingException {
return httpMethod.equals(HttpMethod.GET) && resource.equals("/");
public boolean accepts(HttpRequest httpRequest) throws KindlingException {
return httpRequest.getHttpMethod().equals(HttpMethod.GET) && httpRequest.getResource().equals("/");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
public abstract class RequestHandler {
public abstract HttpResponse handle(HttpRequest httpRequest) throws KindlingException;

public abstract boolean accepts(HttpMethod httpMethod, String resource) throws KindlingException;
public abstract boolean accepts(HttpRequest httpRequest) throws KindlingException;

/**
* Called from {@link io.kerosenelabs.kindling.Server} if an error occurs during
* Called from {@link io.kerosenelabs.kindling.KindlingServer} if an error occurs during
* {@link RequestHandler#handle(HttpRequest)}
*
* @param The throwable that occurred
* @param t the Throwable that occurred
* @return
* @throws KindlingException
*/
public HttpResponse handleError(Throwable t) {
return new HttpResponse.Builder()
Expand Down

0 comments on commit 6ab42c7

Please sign in to comment.