Skip to content

Commit

Permalink
Committing to complete merge
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchen1991 committed Oct 22, 2018
2 parents 09d39b9 + aa8dbce commit 94e4cdd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 30 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ src/data.txt
*.o
cache_tests/cache_tests
cache_tests/cache_tests.exe
cache_tests/cache_tests.log
cache_tests/cache_tests.log
target/
data.txt
45 changes: 17 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ What you need to write:
* Your code will interface with the existing code. Understanding the existing
code is an expected part of this challenge.

What's already there:
What's already here:

* Low-level networking code
* Code that determines a MIME type from a file extension
* File-reading code
* A hashtable implementation
* A linked list implementation (used solely by the hashable--you don't need it)
* All system calls, including `send()` and `recv()`
* `net.h` and `net.c` contain low-level networking code
* `mime.h` and `mime.c` contains functionality for determining the MIME type of a file
* `file.h` and `file.c` contain file-reading code
* `hashtable.h` and `hashtable.c` contain an implementation of a hashtable (this one is a bit more complicated than what you built in the Hashtables sprint)
* `llist.h` and `llist.c` contain an implementation of a doubly-linked list (used solely by the hashable--you don't need it)
* `cache.h` and `cache.c` are where you will implement the LRU cache functionality for days 3 and 4

## What is a Web Server?

Expand All @@ -36,13 +36,10 @@ requests for HTML pages), and returns responses (e.g. HTML pages). Other common

## Assignment

We will write a simple web server that returns files and some specialized data
on a certain endpoint.
We will write a simple web server that returns files and some specialized data on a certain endpoint.

* `http://localhost:3490/d20` should return a random number between 1 and 20
inclusive as `text/plain` data.
* Any other URL should map to the `serverroot` directory and files that lie
within. For example:
* `http://localhost:3490/d20` should return a random number between 1 and 20 inclusive as `text/plain` data.
* Any other URL should map to the `serverroot` directory and files that lie within. For example:

```
http://localhost:3490/index.html
Expand All @@ -54,39 +51,31 @@ on a certain endpoint.
./serverroot/index.html
```

Examine the skeleton source code in `server.c` and `cache.c` for which pieces
you'll need to implement.
Examine the skeleton source code in `server.c` and `cache.c` for which pieces you'll need to implement.

**IMPORTANT** _Spend some time inventorying the code to see what is where. Write
down notes. Write an outline. Note which functions call which other functions.
Time spent up front doing this will reduce overall time spent down the road._
**IMPORTANT** _Spend some time inventorying the code to see what is where. Write down notes. Write an outline. Note which functions call which other functions. Time spent up front doing this will reduce overall time spent down the road._

_The existing code is all one big hint on how to attack the problem._

For the portions that are already written, study the moderately-well-commented
code to see how it works.
For the portions that are already written, study the moderately-well-commented code to see how it works.

There is a `Makefile` provided. On the command line, type `make` to build the
server.
There is a `Makefile` provided. On the command line, type `make` to build the server.

Type `./server` to run the server.

### Main Goals

_Read through all the main and stretch goals before writing any code to get an
overall view, then come back to goal #1 and dig in._
_Read through all the main and stretch goals before writing any code to get an overall view, then come back to goal #1 and dig in._

#### Days 1 and 2

1. Examine `handle_http_request()` in the file `server.c`.

You'll want to parse the first line of the HTTP request header to see if this is a `GET` or `POST` request, and to see what the path is. You'll use this information to decide which handler function to call.

The variable `request` in `handle_http_request()` holds the entire HTTP
request once the `recv()` call returns.
The variable `request` in `handle_http_request()` holds the entire HTTP request once the `recv()` call returns.

Read the three components from the first line of the HTTP header. Hint:
`sscanf()`.
Read the three components from the first line of the HTTP header. Hint: `sscanf()`.

Right after that, call the appropriate handler based on the request type
(`GET`, `POST`) and the path (`/d20` or other file path.) You can start by
Expand Down
3 changes: 2 additions & 1 deletion src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void resp_404(int fd)
struct file_data *filedata;
char *mime_type;

// Fetch the 404.html file
snprintf(filepath, sizeof filepath, "%s/404.html", SERVER_FILES);
filedata = file_load(filepath);

Expand Down Expand Up @@ -190,7 +191,7 @@ int main(void)
printf("webserver: waiting for connections on port %s...\n", PORT);

// This is the main loop that accepts incoming connections and
// fork()s a handler process to take care of it. The main parent
// forks a handler process to take care of it. The main parent
// process then goes back to waiting for new connections.

while(1) {
Expand Down

0 comments on commit 94e4cdd

Please sign in to comment.