def test(self): server = http.HTTPServer(self.address, self.handle) server.start() s = self.connect() s.sendall('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n') s.sendall('GET / HTTP/1.1\r\nHost: localhost\r\n\r\n') s.close() server.stop() gevent.sleep(0.02) # stopping what already stopped is OK server.stop()
def serve_photos(): http.HTTPServer(('127.0.0.1', 8001), static_app).serve_forever()
and returns a full RESPONSE. the method and uri can be found in the header, the response body is json data containing the POST_DATA variables that was sent in the request. Altough made for testing REST clients with simple data its easy to change for other testing uses. depends on: gevent : pip install gevent # needs libevent-dev to compile dependencies """ from gevent import http import urlparse def callback(request): body = dict(urlparse.parse_qsl(request.input_buffer.read())) print '%s %s - %s' % (request.typestr, request.uri, body) request.add_output_header('Content-Type', 'text/json') request.add_output_header('uri', '%s %s' % (request.typestr,request.uri)) request.send_reply(200, "OK", '%s' % body) print 'Serving on 8000...' http.HTTPServer(('0.0.0.0', 8000), callback).serve_forever()
def setUp(self): greentest.TestCase.setUp(self) self.server = http.HTTPServer(self.address, self.handle) self.server.start()