From a8e98dd858caef6edf8001f6082eca2b0044c47c Mon Sep 17 00:00:00 2001 From: Iman Imen Date: Mon, 6 Jul 2026 18:39:02 +0330 Subject: [PATCH 1/5] chore(ci): via github --- .github/workflows/maven.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..8a04a22 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,35 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 25 + uses: actions/setup-java@v4 + with: + java-version: '25' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + - name: Update dependency graph + uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From 53d1c71a96831d0145c3c1b589e054db6de66688 Mon Sep 17 00:00:00 2001 From: Iman Imen Date: Mon, 6 Jul 2026 18:40:16 +0330 Subject: [PATCH 2/5] chore: set method --- .../imanimen/jttpserver/http/HttpRequest.java | 11 ++++++-- .../jttpserver/http/HttpParserTest.java | 26 +++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/imanimen/jttpserver/http/HttpRequest.java b/src/main/java/com/imanimen/jttpserver/http/HttpRequest.java index 02a177f..9a3ce64 100644 --- a/src/main/java/com/imanimen/jttpserver/http/HttpRequest.java +++ b/src/main/java/com/imanimen/jttpserver/http/HttpRequest.java @@ -14,8 +14,15 @@ public HttpMethod getMethod() { return method; } - public void setMethod(String methodName) { - this.method = HttpMethod.valueOf(methodName); + public void setMethod(String methodName) throws HttpParsingException{ + for (HttpMethod httpMethod: HttpMethod.values()) { + if (httpMethod.name().equals(methodName)) { + this.method = httpMethod; + } + } + throw new HttpParsingException( + HttpStatusCode.SERVER_ERROR_501_NOT_IMPLEMENTED + ); } diff --git a/src/test/java/com/imanimen/jttpserver/http/HttpParserTest.java b/src/test/java/com/imanimen/jttpserver/http/HttpParserTest.java index 7255fcc..532f974 100644 --- a/src/test/java/com/imanimen/jttpserver/http/HttpParserTest.java +++ b/src/test/java/com/imanimen/jttpserver/http/HttpParserTest.java @@ -21,13 +21,21 @@ public static void beforeClass() { @Test void parseHttpRequest() throws IOException { HttpRequest request = httpParser.parseHttpRequest( - generateValidTestCase() + generateValidGETTestCase() ); assertEquals(request.getMethod(), HttpMethod.GET); } - private InputStream generateValidTestCase() { + @Test + void parseHttpBadRequest() throws IOException { + HttpRequest request = httpParser.parseHttpRequest( + generateInValidGETTestCase() + ); + + } + + private InputStream generateValidGETTestCase() { String rawHttpRequest = "GET / HTTP/1.1\r\n" + "Host: localhost:8080\r\n" + "Connection: keep-alive\r\n" + @@ -52,4 +60,18 @@ private InputStream generateValidTestCase() { ) ); } + + private InputStream generateInValidGETTestCase() { + String rawHttpRequest = "GET / HTTP/1.1\r\n" + + "Host: localhost:8080\r\n" + + "Cookie: Phpstorm-e23b83ee=e9b0b55c-7724-483f-93b4-b23824eeb394\r\n" + + "\r\n"; + + return new ByteArrayInputStream( + rawHttpRequest.getBytes( + StandardCharsets.US_ASCII + ) + ); + } + } \ No newline at end of file From 4c4f88a3ff21e726e74e452a1c8513635f47e154 Mon Sep 17 00:00:00 2001 From: Iman Imen Date: Mon, 6 Jul 2026 18:41:07 +0330 Subject: [PATCH 3/5] HOTFIX: MAVEN CI --- .github/workflows/maven.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 8a04a22..d29df2b 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -29,7 +29,3 @@ jobs: cache: maven - name: Build with Maven run: mvn -B package --file pom.xml - - # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - - name: Update dependency graph - uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 From 7c6192ff61c819f03ee5775e5fd35b6b12ce8ad6 Mon Sep 17 00:00:00 2001 From: Iman Imen Date: Mon, 6 Jul 2026 18:43:17 +0330 Subject: [PATCH 4/5] chore(error handling): not working at this point must fix later --- src/main/java/com/imanimen/jttpserver/http/HttpParser.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/imanimen/jttpserver/http/HttpParser.java b/src/main/java/com/imanimen/jttpserver/http/HttpParser.java index 2e230bc..ccce8a9 100644 --- a/src/main/java/com/imanimen/jttpserver/http/HttpParser.java +++ b/src/main/java/com/imanimen/jttpserver/http/HttpParser.java @@ -23,6 +23,8 @@ public HttpRequest parseHttpRequest(InputStream inputStream) throws IOException parseRequestLine(reader, request); } catch (IOException e) { e.printStackTrace(); + } catch (HttpParsingException e) { + throw new RuntimeException(e); } parseHeaders(reader, request); parseBody(reader, request); @@ -30,7 +32,7 @@ public HttpRequest parseHttpRequest(InputStream inputStream) throws IOException return request; } - private void parseRequestLine(InputStreamReader reader, HttpRequest request) throws IOException { + private void parseRequestLine(InputStreamReader reader, HttpRequest request) throws IOException, HttpParsingException { StringBuilder processingDataBuffer = new StringBuilder(); boolean methodParsed = false; From d8a63caa6884db4332a57be613a2812c418435c0 Mon Sep 17 00:00:00 2001 From: Iman Imen Date: Mon, 6 Jul 2026 19:53:16 +0330 Subject: [PATCH 5/5] chore(core): fix methods --- src/main/java/com/imanimen/jttpserver/http/HttpRequest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/imanimen/jttpserver/http/HttpRequest.java b/src/main/java/com/imanimen/jttpserver/http/HttpRequest.java index 9a3ce64..643ae71 100644 --- a/src/main/java/com/imanimen/jttpserver/http/HttpRequest.java +++ b/src/main/java/com/imanimen/jttpserver/http/HttpRequest.java @@ -18,6 +18,7 @@ public void setMethod(String methodName) throws HttpParsingException{ for (HttpMethod httpMethod: HttpMethod.values()) { if (httpMethod.name().equals(methodName)) { this.method = httpMethod; + return; } } throw new HttpParsingException(