>> SPEAKER 1: All right, so what is it you concretely need to do?
Well, turns out there's just four functions
that you need to implement whose functionality is
integral to the proper operation of the web server,
but all of whose behavior is very narrowly
defined, so that they only do pretty much one thing.
First thing you're going to need to do is implement,
per the specification, the LOOKUP function.
This is a fairly simple function in the end, that takes as an argument
whatever the path to the file that the user wants to request,
and you need to respond with the so-called MIME type, or Content-type,
of that file.
For instance, if it's a file like, hello dot
HTML you're going to respond with a MIME type of quote unquote text slash HTML.
>> Or if it's an image, you might want to respond with image dot slash
JIFF or image slash JPEG.
See the specification for the various file formats you need to detect.
But it really boils down to taking a look at the path, that you are past,
and looking at its file extension, the last few characters
after the trailing period or dot.
So we'll leave it to you with some of the hints in the specification
to figure out exactly how to find that dot and the file extension
so that you can do the mapping from one to the other.
>> Next up is the parse function.
So this one's a little more involved, in that
you need to take in that argument [INAUDIBLE],
it's iterated over it, character for character, or string by string,
in order to make sure that it meets exactly
the formal definition of that first request line, as per the specification.
And you need to load into absolute path that substring, that represents
something like, slash hello dot HTML.
Meanwhile, optionally, after that path might be a question mark
and then a query string like, q equals cats,
or q equals cats ampersand, and then another key value pair.
So you're going to need to step over those characters,
as well, up until the first space, in order
to create a string that stores inside of it the query string itself.
Next, you're going to implement the load function.
So it turns out, if you look through the source code, as the spec directs,
the load function is used in two places.
It's either used to load the output from the PHP Interpreter.
And we wrote all of the PHP handling code,
but it does need to use a function called
load, that essentially reads all of the bytes of output from PHP's Interpreter
into a big array.
>> That same function load is also used to load
into memory all of the bytes from a file like, a JIFF, or a JPEG, or dot HTML
file, that the user has requested.
So you will need to use some tricks and tools from problem set 4 in file IO,
but you should find that relatively familiar and in a nice way, hopefully,
of tying together the newer web stuff with the older file IO stuff.
>> Finally, in the indexes function, all you need to do
is to decide whether or not there exists some file effectively
called index dot HTML, or index dot PHP, inside of the directory, whose path you
are past.
The upside of this means that if the user does request a directory,
we're not just going to show him or her the contents of that directory,
we'll literally show them index dot HTML, or index dot PHP, by default.
But it's going to be left to you to figure out, using some of the hints
in the source code, that we've already given you,
how you can actually check whether a certain file exists
in the current directory, so that you can return the correct response.
>> So in the end there's relatively few bytes
that you need to take out of the problem set to implement the server's
incomplete functionality.
But definitely make sure you wrap your mind around as much of the code
as you can, taking comfort in that you don't
need to understand all of the lowest level networking code, all
of the lowest level file IO code.
Really, what we're doing with this problem set
is synthesizing the past several problem sets, introducing a bit of WebLogic,
and networking concepts, so that ultimately you
build something that's really quite interesting, really quite powerful,
but still using the same building blocks,
that we've been using for some time.