mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Readd HTTP request processing.
I based this on the BaseHTTPServer request handler class because I had issues with the other request handler. This one is having issues as well so I should go back to Benoit's but I'm starting to slide towards sleep.
This commit is contained in:
parent
8be0226763
commit
1cd1cc3a86
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
import BaseHTTPServer
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import select
|
import select
|
||||||
@ -8,6 +9,25 @@ import util
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class Handler(BaseHTTPServer.BaseHTTPRequestHandler):
|
||||||
|
|
||||||
|
protocol = 'HTTP/1.1'
|
||||||
|
worker = None
|
||||||
|
|
||||||
|
def do_GET(self):
|
||||||
|
self.respond("Hello, World!\n")
|
||||||
|
|
||||||
|
def respond(self, body):
|
||||||
|
log.info("Responding")
|
||||||
|
self.send_response(200, 'OK')
|
||||||
|
self.send_header("Content-Type", "text/plain")
|
||||||
|
self.send_header("Content-Length", len(body))
|
||||||
|
self.end_headers()
|
||||||
|
log.info("Sending body.")
|
||||||
|
self.wfile.write(body)
|
||||||
|
self.wfile.flush()
|
||||||
|
log.info("Done.")
|
||||||
|
|
||||||
class Worker(object):
|
class Worker(object):
|
||||||
|
|
||||||
SIGNALS = map(
|
SIGNALS = map(
|
||||||
@ -36,24 +56,19 @@ class Worker(object):
|
|||||||
(conn, addr) = self.socket.accept()
|
(conn, addr) = self.socket.accept()
|
||||||
log.info("Client connected: %s:%s" % addr)
|
log.info("Client connected: %s:%s" % addr)
|
||||||
conn.setblocking(1)
|
conn.setblocking(1)
|
||||||
if not self.handle(conn, addr):
|
try:
|
||||||
log.info("Client requested process recycle.")
|
self.handle(conn, addr)
|
||||||
return
|
finally:
|
||||||
|
log.info("Client disconnected.")
|
||||||
|
conn.close()
|
||||||
|
|
||||||
def handle(self, conn, client):
|
def handle(self, conn, client):
|
||||||
fp = conn.makefile()
|
while True:
|
||||||
line = fp.readline()
|
req = Handler(conn, client, self.socket)
|
||||||
while line:
|
req.setup()
|
||||||
log.info("Received: %s" % line.strip())
|
req.worker = self
|
||||||
if line.strip().startswith("q"):
|
log.info("Handling request.")
|
||||||
log.info("Client disconnected.")
|
req.handle()
|
||||||
conn.close()
|
log.info("Done.")
|
||||||
return True
|
if req.close_connection:
|
||||||
elif line.strip().startswith("k"):
|
return
|
||||||
log.info("Client disconnected.")
|
|
||||||
conn.close()
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
fp.write(line)
|
|
||||||
fp.flush()
|
|
||||||
line = fp.readline()
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user