Implement static file handler (foundation for #18)#8
Implement static file handler (foundation for #18)#8annikaholmqvist94 wants to merge 11 commits intomainfrom
Conversation
* chore: Update POM to Java 25 and rename artifactId/groupId * update folder name from example to juv25d --------- Co-authored-by: WHITEROSE <firasmoussa60@gmail.com>
* http parser * Bunny fixes. (only using input stream to recieve requests) * Bunny review improvements * Improved http parser ReadLine helper method to eliminate dependency on mark() and reset(). Implemented handleClient() using socket as a try-with-resources to avoid memory leakage in case of exception thrown by httpparser-methods. * NumberFormatException fix on line 53 -> 60 * chore: Update POM to Java 25 and rename artifactId/groupId (#11) * chore: Update POM to Java 25 and rename artifactId/groupId * update folder name from example to juv25d --------- Co-authored-by: WHITEROSE <firasmoussa60@gmail.com> * resolve conflicts --------- Co-authored-by: Kristina <kristina0x7@gmail.com> Co-authored-by: WHITEROSE <firasmoussa60@gmail.com>
* Add ServerLogging.java as separate class for logging. Implement said class in SocketServer.java to return logging information upon opening socket and user connecting to server. * Update ServerLogging.java to include a static initializer block and an empty utility class to prevent instantiation. * Update ServerLogging.java to reference same class in getLogger argument. * Update ServerLogging.java to check if handler has already been instantiated and allow for log level to be set by args in JVM (default level 'INFO' if no args provided). * normalize logging statements to be consistent * remove unused imports * Update SockerServer.java to properly log server socket errors. --------- Co-authored-by: Mats Rönnqvist <mats.f.ronnqvist@gmail.com> Co-authored-by: WHITEROSE <firasmoussa60@gmail.com>
* update POM with pitest * add junit plugin dependency
Rebased 4 commits in this PR.
…#27) * Fix PiTest by defining argLine and removing invalid Mockito javaagent * self close argline
Core Implementation: - Add StaticFileHandler for serving files from /resources/static/ - Add MimeTypeResolver for Content-Type detection - Add security validation to prevent path traversal attacks Testing: - Add MimeTypeResolverTest (15 test cases) - Add StaticFileHandlerTest (20+ test cases) - All tests passing Example Files: - Add index.html demo page with gradient styling - Add styles.css for professional styling - Add app.js for JavaScript functionality demo Note: Integration with Server/ConnectionHandler will be added after PR #28 merges to avoid conflicts. Foundation work for #18
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThis PR establishes a complete Java HTTP server project. It renames the project from org.example/JavaTemplate to org.juv25d/JavaHttpServer, adds Maven wrapper scripts and Docker support, implements core HTTP handling with request parsing and response writing, configures CI/CD workflows, and introduces code formatting and mutation testing tools. Changes
Sequence DiagramsequenceDiagram
participant Client
participant SocketServer
participant HttpParser
participant App
Client->>SocketServer: TCP connect to port 3000
SocketServer->>SocketServer: Accept connection
SocketServer->>SocketServer: Spawn virtual thread
SocketServer->>HttpParser: new HttpParser()
Client->>HttpParser: Send HTTP request bytes
HttpParser->>HttpParser: readLine() request line
HttpParser->>HttpParser: Parse method, path, version
HttpParser->>HttpParser: readLine() headers until blank
HttpParser->>HttpParser: Parse Content-Length if present
HttpParser->>HttpParser: Read body bytes
HttpParser->>SocketServer: Return HttpRequest
SocketServer->>SocketServer: Log method & path
SocketServer->>Client: (connection remains open)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Changes
Foundation work for #18 - GET handling for static files
What's Added
Core Logic
/resources/static/Security Features
../,//,\Testing (35+ test cases)
MimeTypeResolverTest (15 tests):
StaticFileHandlerTest (20+ tests):
Example Static Files
File Structure
Integration Status
⏸️ Not yet integrated with Server/ConnectionHandler
This PR contains all core logic but avoids modifying
Server/SocketServer/ConnectionHandler to prevent conflicts with PR #28.
Integration Plan (after PR #28 merges):
Architecture
Architecture decisions documented in ADR-001 (see PR #7 ).
Dependencies
Review Focus
Notes
Summary by CodeRabbit
New Features
Tests
Chores