Starting from:
$30

$24

Assignment 6 Web Hosting Solution

Overview




In this assignment, you will be writing a basic HTTP Web server in Python 3. This web server will listen on port 8080 (unprivileged), and respond to HTTP GET requests with code 200 and the following information in a JSON object: Hostname of the system, the user running the webserver, "Hello CS447/647!". Make sure to set the 'Content-type' header to 'application/json'. Have this web server run via a systemd service.




```json

{

"hostname": "instance-1",

"user": "grading",

"body": "Hello CS447/647!"

}

```




Submission




Submit via the provided git repo by 11:59pm Monday, April 15th. You will submit your web server script, as well as the systemd service file used to keep it running. Leave your web server running on your GCP server, as I will be connecting to them to grade.

```

assignment-6-username

│ README.md

│ http_server.py

│ http_server.service

```







Tips




`#!/usr/bin/env python3` as shebang. Make sure script is excecutable before submitting `chmod +x http_server.py`




Use curl or a web browser to test your server. `curl http://ip_address:8080`




Use the `http.server` Python module for the request handler base class. Create a new class using `BaseHTTPRequestHandler` as a template, and override the `do_GET()` function to serve data.




Use the `serve_forever()` function at the end of your script to run the server until cancelled.




[https://docs.python.org/3/library/http.server.html](https://docs.python.org/3/library/http.server.html)

[https://docs.python.org/3/library/getpass.html](https://docs.python.org/3/library/getpass.html)

[https://docs.python.org/3/library/json.html](https://docs.python.org/3/library/json.html)

More products