#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
A hackable http proxy
"""
import logging

from six.moves.urllib.parse import urlparse
from gevent.pywsgi import WSGIServer,WSGIHandler

def get_dist(environ):
    http_host = environ.get('HTTP_HOST', '').lower()
    http_host_partail = http_host.split(':')
    if len(http_host_partail) == 2:
        return http_host_partail[0], int(http_host_partail[1])
    return http_host,80

def is_visible_request():
    '''
    return http request is visible by user's bowser
    '''
    return False

def proxy_request():
    pass

def application(environ,start_response):
    start_response("200 OK",[("Content-Type", "text/plain; charset=utf-8")])
    host,port = get_dist(environ)
    return b'request to %s:%d' % (host,port)

if __name__ == '__main__':
    WSGIServer(':8080', application).serve_forever()

@@ -212,66 +212,322 @@
     
-http_host = environ.get('HTTP_HOST', '').lower()%0A    http_
+keys = ('PATH_INFO','HTTP_HOST')%0A    host = ''%0A    port = 80%0A    if environ.get('wsgi.url_scheme') == 'https':%0A        return False,443%0A    for k in keys:%0A        host = environ.get(k,'')%0A        if not host:%0A            continue%0A        if host.startswith('http'):%0A            host = host%5B7:%5D.lstrip('/')%0A        
 host
@@ -537,21 +537,16 @@
 rtail = 
-http_
 host.spl
@@ -561,20 +561,19 @@
     
+  
+  
 if len(
-http_
 host
@@ -585,15 +585,17 @@
 ail)
- 
 ==
- 
 2:%0A
+    
     
@@ -601,29 +601,24 @@
      return 
-http_
 host_partail
@@ -625,18 +625,12 @@
 %5B0%5D,
- 
 int(
-http_
 host
@@ -642,16 +642,20 @@
 ail%5B1%5D)%0A
+    
     retu
@@ -662,19 +662,48 @@
 rn h
-ttp_host,80
+ost,port%0A%0Adef get_url(environ):%0A    pass
 %0A%0Ade
@@ -884,16 +884,131 @@
 ponse):%0A
+    host,port = get_dist(environ)%0A    if not host:%0A        start_response('501 Not Implemented', %5B%5D)%0A    else:%0A    
     star
@@ -1084,38 +1084,8 @@
     
-host,port = get_dist(environ)%0A
     

reconstruct get_dist