From 5d3da9528f2b379c04c80fee1b68510789de3433 Mon Sep 17 00:00:00 2001 From: hlafaille Date: Fri, 9 Aug 2024 13:51:00 -0400 Subject: [PATCH 1/2] #6 populating out HttpRequest --- .../java/io/kerosenelabs/kindling/HttpRequest.java | 12 ++++++++++++ .../io/kerosenelabs/kindling/KindlingServer.java | 6 +++--- src/main/java/io/kerosenelabs/kindling/Main.java | 4 ++-- .../kindling/handler/RequestHandler.java | 7 +++---- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/kerosenelabs/kindling/HttpRequest.java b/src/main/java/io/kerosenelabs/kindling/HttpRequest.java index bfb5a3b..a2b9c6f 100644 --- a/src/main/java/io/kerosenelabs/kindling/HttpRequest.java +++ b/src/main/java/io/kerosenelabs/kindling/HttpRequest.java @@ -58,6 +58,18 @@ public HttpMethod getHttpMethod() { return httpMethod; } + public HashMap getHeaders() { + return headers; + } + + public String getProtocolVersion() { + return protocolVersion; + } + + public String getContent() { + return content; + } + /** * Get a valid re-creation of the HTTP message */ diff --git a/src/main/java/io/kerosenelabs/kindling/KindlingServer.java b/src/main/java/io/kerosenelabs/kindling/KindlingServer.java index 4e0e194..cc33224 100644 --- a/src/main/java/io/kerosenelabs/kindling/KindlingServer.java +++ b/src/main/java/io/kerosenelabs/kindling/KindlingServer.java @@ -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 @@ -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) { diff --git a/src/main/java/io/kerosenelabs/kindling/Main.java b/src/main/java/io/kerosenelabs/kindling/Main.java index 4e7f3c7..d9a3413 100644 --- a/src/main/java/io/kerosenelabs/kindling/Main.java +++ b/src/main/java/io/kerosenelabs/kindling/Main.java @@ -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("/"); } /** diff --git a/src/main/java/io/kerosenelabs/kindling/handler/RequestHandler.java b/src/main/java/io/kerosenelabs/kindling/handler/RequestHandler.java index 9afd3e4..b8740d7 100644 --- a/src/main/java/io/kerosenelabs/kindling/handler/RequestHandler.java +++ b/src/main/java/io/kerosenelabs/kindling/handler/RequestHandler.java @@ -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() From 9b9712d69084fd974889f523e8fa2710d3bb6cf7 Mon Sep 17 00:00:00 2001 From: hlafaille Date: Fri, 9 Aug 2024 13:52:09 -0400 Subject: [PATCH 2/2] #6 changing pom version number --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 942838d..59c15e6 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ io.kerosenelabs kindling jar - 0.1.2 + 0.1.3 kindling http://maven.apache.org