title: How does python's SimpleHTTPServer do_GET and do_POST functions work?
body: <p>I've created the following little HTTP server for learning purposes:</p>
  
  <pre><code>import SimpleHTTPServer
  import SocketServer
  
  class ServerHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
  
      def do_GET(self):
          print(self.headers)
          SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
  
      def do_POST(self):
          print(self.headers)
          form = cgi.FieldStorage(
              fp=self.rfile,
              headers=self.headers,
              environ={'REQUEST_METHOD':'POST',
                   'CONTENT_TYPE':self.headers['Content-Type'],
  
  def main():
      port = 50738
      Handler = ServerHandler(1000)
      httpd = SocketServer.TCPServer(("192.168.X.Y", port), Handler)
  
      print "serving at port", port
      httpd.serve_forever()
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>My assumptions are as follows:</p>
  
  <ul>
  <li>My class 'ServerHandler' extends the SimpleHTTPServer.SimpleHTTPRequestHandler class by two functions namely go_GET and do_POST</li>
  <li>The main() function creates a server handler object and server socket bound to my I.P. address and port of choice, and invokes a function to serve/listen indefinitely. </li>
  </ul>
  
  <p><strong>Aside</strong>: I know by looking at the Python DOCs <a href="https://docs.python.org/2/library/simplehttpserver.html" rel="noreferrer">https://docs.python.org/2/library/simplehttpserver.html</a> that SimpleHTTPServer.SimpleHTTPRequestHandler has a method  called do_GET, which I assume gets overridden by the do_GET in my ServerHandler class?</p>
  
  <p><strong>Question</strong>:
  What is going on under the hood relating to do_GET and do_POST? Is it the case that once we have this server listening for HTTP "activity" directed towards a specific IP:PORT that it automatically know if an incoming signal is a GET or POST and as soon as one is encountered the server calls my do_GET or do_POST functions?    </p>