Giter VIP home page Giter VIP logo

socket-http-server-homework's Introduction

SOCKET HTTP SERVER

Once you're done, you should be able to start the web server inside the homework directory using python -u http_server.py and then point your web browser at locations like: * http://localhost:10000/sample.txt * http://localhost:10000/a_web_page.html * http://localhost:10000/images/sample_1.png

and see the corresponding file located under homework/webroot. Take a moment to look into the homework/webroot and see these files. 

Inside this repository you'll find the http_server.py file we’ve just written in class. I've added enough stub code for the missing functions to let the server run. And there are more tests for you to make pass!

You do NOT need to execute the make_time.py Python file. When a web user visits http://localhost:1000/make_time.py you only need to serve up the contents of that file. But if you'd like to take on a challenge, then you can choose to execute the file and serve up the result of performming that execution.

Building the Response

Your response_path function will need to accomplish the following tasks:

  • It should take a URI as the sole argument
  • It should map the pathname represented by the URI to a filesystem location.
  • It should have a ‘home directory’, and look only in that location.
  • If the URI is a directory, it should return a plain-text listing of the directory contents and the mimetype text/plain.
  • If the URI is a file, it should return the contents of that file and its correct mimetype.
  • If the URI does not map to a real location, it should raise an exception that the server can catch to return a 404 response.

Because your server will be transmitting files as bytes, you might want to try searching for "reading a file as bytes in Python".

To find the correct mimetype for a file, you might find the following code helpful:

>>> import mimetypes
>>> mimetypes.guess_type('file.txt')[0]
    'text/plain'
>>> mimetypes.types_map['.txt']
    'text/plain'

Use Your Tests

As you work your way through the steps outlined above, look at your tests. Write code that makes them pass.

socket-http-server-homework's People

Contributors

jaschilz avatar

Watchers

James Cloos avatar  avatar Mike Bozee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.