- Alexander Waz
- Derek Nguyen
- Sung Hyun Yoon
One of the features we implemented was HTTP compression. The encoding we chose was gzip. We serve static file and echo requests through compressing them.
We made a Compressor class, where we have a Compress function that takes a string, and returns the compressed gzip format as a string.
string Compressor::compress(const string& original) {
create a stringstream for uncompressed and compressed
instantiate boost filter stream
push the gzip compressor to the filter stream
push the uncompressed stringstream through the filter
copy the compressed stringstream into the output
return compressed string
}
We chose gzip because it is one of the most widely used compression schemes, and is supported by Boost. In the static file handler and echo handler, we add the headers Content-Encoding: gzip
, pass the original body through the Compress function, and then set the body equal to the compressed string.
52.40.2.14/static2/test.txt (link to a static file, easier seen demonstrated by curl)
- By using
$ curl -is 52.40.2.14/static2/test.txt
- This gives the compressed output of the static file
- Then use
$ curl --compressed -is 52.40.2.14/static2/test.txt
- We now get the uncompressed plain text
We also implemented markdown rendering. When a file with a .md extension is requested, the file is transparently converted to and rendered as HTML.
Most of the changes were made to our previous implementation of static file handler. Among the libraries that were suggested as aprt of the assignment specification, we decided to go with cpp-markdown, since it was easy to integrate and relatively small.
Below is a high-level abstraction of our implementation
Status StaticHandler::HandleRequest(request, response) {
// Read file content
...
string content_type = GetMimeType(file_path); // set to text/html if .md
if (IsMarkdown(file_path)) { // check if .md extension
file_content = ProcessMarkdown(file_content); // convert to html using cpp-markdown
}
// Write response
...
}
This design document is actually a .md file that is rendered as HTML!
We attempted to implement HTTPS encryption between the client and the server to have a secured connection.
We were not able to complete this feature on time, but did attempt to implement it using boost ssl library and example. We created a private key and a self-signed certificate using openssl. We were able to set up the socket for the encrypted communication successfully, but our handshaking procedure between the server and client did not work as intended. When the browser tries to connect to the server using https, the browser warns us of an unsecured connection and self-signed certificate. In order to see the response from the server, we had to add an exception to the browser, which is not safe.
Since we were not able to complete this feature, all of the code written for https implementation were not merged into master and can be viewed under the https branch.