title: Content monitor getting incorrect URL
body: <p>I am trying to create an HTTP proxy server that does content monitoring. Content monitoring involves grabbing the destination website's title and searching it for blacklisted keywords that are predefined in an array.</p>
  <p>The issue that I am having is that the code is;</p>
  <ol>
  <li>Not getting the correct URL</li>
  <li>Not parsing the URL correctly.</li>
  </ol>
  <p>Is there a way to get one of the URL that is entered into the browser? I hope I am making sense.
  Here is the code:</p>
  <pre><code>from http.server import BaseHTTPRequestHandler, HTTPServer
  import logging
  import requests
  import threading
  import random
  import time
  import metadata_parser
  
  
  thread_list = []
  
  
  class S(BaseHTTPRequestHandler):
  
      print(&quot;\n\n\n Avocado Medical Proxy Server \n\n\n&quot;)
  
      def do_POST(self):
          processcount = random.randint(1, 101)
          processcount = threading.Thread(
              target=self.sendlinktoserverPost,
              args=(
                  self.path,
                  processcount,
              ),
          )
          processcount.start()
          processcount.join()
  
      def do_GET(self):
          # 2. Blacklisting Domains for greater security. Ex. blocking a specific ip address or a website.
          blacklisturl = [
              &quot;http://instagram.com&quot;,
              &quot;http://httpforever.com/&quot;,
              &quot;http://innerastoundingglowingsunset.neverssl.com/online&quot;,
              &quot;http://quietlushsilverstars.neverssl.com/online&quot;,
          ]
          blacklistkw = [
              &quot;cash&quot;,
              &quot;Free&quot;,
              &quot;password&quot;,
              &quot;bet&quot;,
              &quot;click&quot;,
              &quot;download&quot;,
          ]
  
          print(&quot;Website Here: &quot;)
          print(self.path)
          print(&quot;Ends here&quot;)
  
          page = metadata_parser.MetadataParser(url=self.path)
  
          pagetitle = page.get_metadatas(&quot;title&quot;)
          print(pagetitle)
  
          for i in blacklistkw:
              if i in pagetitle:
                  displaymsg = &quot;Page was blocked&quot;
                  errorcounter = 1
              else:
                  displaymsg = &quot;Page visited successfully&quot;
                  errorcounter = 0
  
          if self.path in blacklisturl or errorcounter == 1:
              self.send_response(200)
              self.end_headers()
              self.wfile.write(
                  &quot;This page has been blocked by the proxy Server&quot;.encode(&quot;utf-8&quot;)
              )
          else:
              if self.command == &quot;GET&quot;:
                  processcount = random.randint(1, 101)
                  processcount = threading.Thread(
                      target=self.sendlinktoserver,
                      args=(
                          self.path,
                          processcount,
                      ),
                  )
                  # 1. Handling multiple transactions simultaneously (i.e. several requests and responses) to improve its performance.
                  t = time.localtime()
                  current_time = time.strftime(&quot;%H:%M:%S&quot;, t)
                  print(&quot;\n Get requests URL : &quot;, self.path, &quot;, Time :&quot;, current_time)
                  processcount.start()
                  processcount.join()
              else:
                  print(&quot;Error: Method not found&quot;)
  
      def sendlinktoserver(self, url, processcount):
          s = requests.Session()
          r = s.request(&quot;GET&quot;, url)
          self.send_response(200)
          self.end_headers()
          self.wfile.write(r.content)
  
          # 4. Logging - storing every outbound and inbound requests
          new_path = &quot;logs.txt&quot;
          tid = threading.current_thread().ident
          t = time.localtime()
          current_time = time.strftime(&quot;%H:%M:%S&quot;, t)
  
          logdata = (
              &quot;Thread ID :&quot;
              + str(tid)
              + &quot;, Time :&quot;
              + str(current_time)
              + &quot;\n URL :&quot;
              + str(self.path)
              + str(self.headers)
              + &quot;Source IP :&quot;
              + str(self.client_address)
              + str(self.address_string())
              + &quot;, HTTP version :&quot;
              + str(self.request_version)
              + &quot;, HTTP Method :&quot;
              + str(self.command)
              + &quot;\n&quot;
          )
          writelogfile = open(new_path, &quot;a&quot;)
          writelogfile.write(logdata)
  
      def sendlinktoserverPost(self, url, processcount):
          self.send_response(200)
          self.end_headers()
          s = requests.Session()
          r = s.request(&quot;POST&quot;, url)
          self.wfile.write(r.content)
  
  
  def run(server_class=HTTPServer, handler_class=S, port=8000):
      logging.basicConfig(level=logging.INFO)
      server_address = (&quot;127.0.0.1&quot;, port)
      httpd = server_class(server_address, handler_class)
      logging.info(&quot;[Starting Server: Listening on TCP-Socket Port: 8000 ] \n&quot;)
      try:
          httpd.serve_forever()
      except KeyboardInterrupt:
          pass
      httpd.server_close()
      logging.info(&quot;Closing Proxy Server...\n&quot;)
  
  
  if __name__ == &quot;__main__&quot;:
      from sys import argv
  
      if len(argv) == 2:
          run(port=int(argv[1]))
      else:
          run()
  
  
  </code></pre>