def main(): app = MeepExampleApp() environ = {} def fake_start_response(status, headers): print status print headers print datetime.datetime.now().strftime("%Y-%m-%d %H:%M") print '\n' while(True): f = raw_input("Enter file name:") try: f = open(f) line = f.readline() while line: if line.startswith('GET'): line = line.rstrip('\n') #removes extra line words = line.split(' ') environ['REQUEST_METHOD'] = 'GET' environ['PATH_INFO'] = words[1] environ['SERVER_PROTOCOL'] = words[2] elif line.startswith('cookie:'): line = line.rstrip('\n') #removes extra line line = line.lstrip('cookie: ') environ['HTTP_COOKIE'] = line line = f.readline() app.__call__(environ, fake_start_response) except IOError: print "Couldn't read that file"
def main(): app = MeepExampleApp() environ = {} def fake_start_response(status, headers): print status print headers print datetime.datetime.now().strftime("%Y-%m-%d %H:%M") print '\n' while(True): fileName = raw_input("Give me a text file to read (1-request.txt, 2-request.txt, 3-request.txt)...\n") try: fp = open(os.getcwd() + "\\requests\\" + fileName) #open cwd gets your current directory for line in fp.readlines(): print line if line.startswith('GET'): line = line.rstrip('\n') words = line.split(' ') environ['REQUEST_METHOD'] = 'GET' environ['PATH_INFO'] = words[1] environ['SERVER_PROTOCOL'] = words[2] elif line.startswith('cookie:'): line = line.rstrip('\n') line = line.lstrip('cookie: ') environ['HTTP_COOKIE'] = line app.__call__(environ, fake_start_response) data = app(environ, fake_start_response) print data except IOError: print "Couldn't read that file"
def process_request(request): environ = {} for line in request: line = line.strip() #print (line,) if line == '': continue if line.startswith('get') or line.startswith('post'): line = line.split() environ['REQUEST_METHOD'] = line[0] environ['PATH_INFO'] = line[1] else: line = line.split(':', 1) try: environ[headers_to_environ[line[0]]] = line[1].strip() except KeyError: pass initialize() app = MeepExampleApp() response_fn_callable = ResponseFunctionHolder() appResponse = app(environ, response_fn_callable) response = [] response.append('HTTP/1.0 ' + response_fn_callable.status) response.extend([x+': '+y for x,y in response_fn_callable.headers]) response.append('Date: ' + time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())) response.append('Server: WSGIServer/0.1 Python/2.7') response.append('\r\n') response.extend(a for a in appResponse) return '\r\n'.join(response)
def main(): app = MeepExampleApp() environ = {} def fake_start_response(status, headers): print status print headers print datetime.datetime.now().strftime("%Y-%m-%d %H:%M") print '\n' while (True): fileName = raw_input( "Give me a text file to read (1-request.txt, 2-request.txt, 3-request.txt)...\n" ) try: fp = open(os.getcwd() + "\\requests\\" + fileName) #open cwd gets your current directory for line in fp.readlines(): print line if line.startswith('GET'): line = line.rstrip('\n') words = line.split(' ') environ['REQUEST_METHOD'] = 'GET' environ['PATH_INFO'] = words[1] environ['SERVER_PROTOCOL'] = words[2] elif line.startswith('cookie:'): line = line.rstrip('\n') line = line.lstrip('cookie: ') environ['HTTP_COOKIE'] = line app.__call__(environ, fake_start_response) data = app(environ, fake_start_response) print data except IOError: print "Couldn't read that file"
def buildResponse(webRequest): #parse request requestMap = {'wsgi.input': ''} for line in webRequest: line = line.strip() #remove leading and trailing whitespace if (line.startswith('GET') or line.startswith('POST')): line = line.split() requestMap['REQUEST_METHOD'] = line[0] if line[1].find('?') == -1: requestMap['PATH_INFO'] = line[1] else: tmpPath = line[1].split('?') requestMap['PATH_INFO'] = tmpPath[0] requestMap['QUERY_STRING'] = tmpPath[1] else: try: line = line.split(':', 1) requestMap[environMap[line[0].lower()]] = line[1].strip() except: pass #build response initialize() app = MeepExampleApp() response = app(requestMap, fake_start_response) output = [] output.append('HTTP/1.0 ' + _status) currentTime = datetime.datetime.now() output.append('Date: ' + currentTime.strftime('%a, %d %b %Y %H:%M:%S EST')) output.append('Server: WSGIServer/0.1 Python/2.5') for tmpHeader in _headers: output.append(tmpHeader[0] + ': ' + tmpHeader[1]) output.append('\r\n') for r in response: output.append(r) return '\r\n'.join(output)
from meep_example_app import MeepExampleApp, initialize from wsgiref.simple_server import make_server initialize() app = MeepExampleApp() httpd = make_server('', 8000, app) print "Serving HTTP on port 8000..." # Respond to requests until process is killed httpd.serve_forever() # Alternative: serve one request, then exit httpd.handle_request() #updated 11/18/2011