-
Notifications
You must be signed in to change notification settings - Fork 0
feat: make HttpResponse mutable and implement NotFoundPlugin default #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b0834b0
feat: make HttpResponse mutable and implement NotFoundPlugin default
LinusWestling 3a34182
ran mvn spotless:apply to fix violations
LinusWestling baa704d
Rabbit comment fixes
LinusWestling 1b0a5d1
Review fixes
LinusWestling f2d8b4f
Final buggfixes for this PR (again)
LinusWestling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.juv25d.plugin; | ||
|
|
||
| import org.juv25d.http.HttpRequest; | ||
| import org.juv25d.http.HttpResponse; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public class NotFoundPlugin implements Plugin { | ||
| @Override | ||
| public void handle(HttpRequest req, HttpResponse res) throws IOException { | ||
| res.setStatusCode(404); | ||
| res.setStatusText("Not Found"); | ||
| res.setBody("404 - Resource Not Found".getBytes()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package org.juv25d; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
| import org.juv25d.plugin.HelloPlugin; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class PipelineTest { | ||
|
|
||
| @Test | ||
| void throwsExceptionWhenSettingNullPlugin() { | ||
| Pipeline pipeline = new Pipeline(); | ||
| assertThrows(IllegalArgumentException.class, () -> pipeline.setPlugin(null)); | ||
| } | ||
|
|
||
| @Test | ||
| void customPluginIsUsed() { | ||
| Pipeline pipeline = new Pipeline(); | ||
| HelloPlugin hello = new HelloPlugin(); | ||
|
|
||
| pipeline.setPlugin(hello); | ||
|
|
||
| assertEquals(hello, pipeline.getPlugin()); | ||
| } | ||
|
fmazmz marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package org.juv25d.plugin; | ||
|
|
||
| import org.juv25d.http.HttpRequest; | ||
| import org.juv25d.http.HttpResponse; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class NotFoundPluginTest { | ||
|
|
||
| @Test | ||
| void sets404StatusAndBody() throws IOException { | ||
| NotFoundPlugin plugin = new NotFoundPlugin(); | ||
| HttpRequest req = new HttpRequest("GET", "/unknown", null, "HTTP/1.1", Map.of(), new byte[0]); | ||
| HttpResponse res = new HttpResponse(); | ||
|
|
||
| plugin.handle(req, res); | ||
|
|
||
| assertEquals(404, res.statusCode()); | ||
| assertEquals("Not Found", res.statusText()); | ||
| assertArrayEquals("404 - Resource Not Found".getBytes(), res.body()); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.