OpenLayers OpenLayers
Show
Ignore:
Timestamp:
05/19/06 23:29:43 (3 years ago)
Author:
crschmidt
Message:

Commit changes to proxy script. Specifically:

  • add allowedHosts.
  • Wrap all code in a try/except in case something breaks
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/examples/proxy.cgi

    r195 r205  
    1919url = fs.getvalue('url', "http://openlayers.org") 
    2020 
    21 if url.startswith("http://") or url.startswith("https://"): 
     21allowedHosts = ['www.openlayers.org', 'openlayers.org', 'octo.metacarta.com'] 
     22allowedHosts = object() 
     23host = url.split("/")[2] 
    2224 
    23     y = urllib.urlopen(url) 
     25try: 
     26    if allowedHosts and not host in allowedHosts: 
     27        print "Status: 502 Bad Gateway" 
     28        print "Content-Type: text/plain" 
     29        print 
     30        print "This proxy does not allow you to access that location." 
    2431     
    25     headers = str(y.info()).split('\n') 
    26     for h in headers: 
    27         if h.startswith("Content-Type:"): 
    28             print h 
    29     print 
     32    elif url.startswith("http://") or url.startswith("https://"): 
    3033     
    31     print y.read() 
    32      
    33     y.close() 
    34 else: 
    35     print """Content-Type: text/plain 
    36  
     34        y = urllib.urlopen(url) 
     35         
     36        headers = str(y.info()).split('\n') 
     37        for h in headers: 
     38            if h.startswith("Content-Type:"): 
     39                print h 
     40        print 
     41         
     42        print y.read() 
     43         
     44        y.close() 
     45    else: 
     46        print """Content-Type: text/plain 
     47  
    3748Illegal request.""" 
     49except Exception, E: 
     50    print "Status: 500 Unexpected Error" 
     51    print "Content-Type: text/plain" 
     52    print  
     53    print "Some unexpected error occurred. Error text was:", E