This project is STRICTLY solo. You may not collaborate with other students at all.
Setup
Register for the project using grinch
: https://grinch.caltech.edu/register 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 this git@gitlab.caltech.edu:cs3-24sp/solo04-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!
Initialization
Task 0a. Copy over the following files from the previous solo projects:
- library/router.c
- library/http_request.c
- library/ll.c
- library/mystr.c
- library/strarray.c
- server/web_server.c
DO NOT copy over http_response.c
, as we’ve provided you with a better (but more complicated) version of this module.
Task 0b.
Run the command git clone git@gitlab.caltech.edu:cs3-24sp/game-YOURGAME.git game
, replacing YOURGAME
with the wizard name you were assigned!
Now that you have that out of the way, it’s time to get started.
Task 1.
In solo02
, 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
Task 2.
Run run.sh
and test the routes you created in task 1. One of these should serve your final game itself!!!!
For this project, we will run your webserver and try to run the three routes when grading. There are no automated tests. Push your code to complete the project.