This project is STRICTLY solo. You may not collaborate with other students at all.
Setup
Register for the project using the registration tool and clone the repository as explained in the setup instructions.
You MUST work solo on this project!
You may not collaborate at all with anyone else! Please use the SSH link found on the registration page and in the email sent to you,
it should look something like git@gitlab.caltech.edu:cs3-25sp/webserver04-blank.git
.
Introduction
In the last project, you wrote code to route requests…but then you never used it.
This project will be focused on actually writing the web server, culminating in using it to server your own game!
Remember that code quality WILL be part of your grade in this project!
Initialization
Task 0a. Copy over the following files from the previous webserver projects:
- library/router.c
- library/http_request.c
- library/http_response.c
- library/ll.c
- library/mystr.c
- library/strarray.c
- server/web_server.c
Task 0b.
In your webserver04
directory, run the command git clone git@gitlab.caltech.edu:cs3-25sp/game-YOURGAME.git game
, replacing YOURGAME
with the dog name you were assigned! This should create a copy of your game
repository inside your webserver04
directory.
Now that you have that out of the way, it’s time to get started.
Task 1.
In webserver02
, you implemented a basic web server in server/web_server.c
. Now, we’ll integrate the router you wrote last time and create three handlers which will correspond to three routes:
- Hello Handler (
/hello
)- Return a “Hello, world!” response using
response_type_format
withHTTP_OK
andMIME_HTML
- Return a “Hello, world!” response using
- Roll Handler (
/roll
)- Generate a number between 1 and 6
- Format an
HTTP_OK
response withMIME_HTML
and a string version of the number
- Default Handler
- Use
wutil_get_resolved_path
to get a resolved path- If not successful (i.e., it returns
NULL
), returnHTTP_FORBIDDEN
(useMIME_PLAIN
and some error message)
- If not successful (i.e., it returns
- Use
wutil_check_resolved_path
to determine if the path the user requested is valid- If not
HTTP_OK
, return response code given (useMIME_PLAIN
and some error message)
- If not
- Open the file corresponding to the resolved path
- Use wutil_get_file_size to get the size of the file
- Read the file using
fread
- Construct the response using…
wutil_get_filename_ext
wutil_get_mime_from_extension
response_type_format
- Return the response
- Use
Now, install your handlers and modify main
slightly to incorporate them:
-
main
- Register your three routes before the infinite loop
- Inside the infinite loop, edit your existing code to use
router_dispatch
after parsing the response - Inside the infinite loop, edit your existing code to send the result of
router_dispatch
usingnu_send_bytes
Make sure your web_server.c
file has #include "web_util.h"
at the top!
Task 2.
Run ./run.sh
and test the routes you created in task 1. Note that this also compiles your game.
One of your routes should serve your final game itself!!!!
We’ve also added one server test this week. Once all 3 of your routes are working, run make test
to make sure your
tests all pass.
Task 3.
Run make test
to confirm that your server passes the tests.
For this project, we will run your webserver and try to run the three routes when grading.
For full credit, make test
must also pass without any errors. There are no automated tests.
Push your code to complete the project.