ry / ebb fork watch download tarball
public this repo is viewable by everyone
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
python binding supports wsgi1 and wsgi2
ryah (author)
about 1 month ago
commit  330364ac2933ad98948bd1a9089fa06174a13033
tree    ead91d758681c860260651f21a9e464169045bc5
parent  0861921e11e6cc5211d59ad13fd3471e85270b7a
...
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
 
38
39
40
41
42
43
44
 
45
46
47
 
48
49
50
...
60
61
62
63
 
 
64
65
66
...
84
85
86
87
88
 
 
 
 
 
 
89
...
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 
77
78
79
80
81
82
83
 
84
85
86
 
87
88
89
90
...
100
101
102
 
103
104
105
106
107
...
125
126
127
 
128
129
130
131
132
133
134
135
0
@@ -33,18 +33,58 @@ def should_keep_alive(env):
0
       return True
0
   return False
0
 
0
+class StartResponse:
0
+ def __init__(self, client):
0
+ self.client = client
0
+
0
+ def __call__(self, status_string, response_headers, exc_info=None):
0
+ # status_string should be something like "200 OK" or "404 Not Found"
0
+ # need to split this into an integer and human readable string for ebb
0
+ match = re.search('(\d+) (.*)', status_string)
0
+ status = int(match.group(1))
0
+ reason_phrase = match.group(2)
0
+
0
+ # write the status
0
+ self.client.write_status(status, reason_phrase)
0
+
0
+ headers = Headers(response_headers)
0
+
0
+ # Decide if we should keep the connection alive or not
0
+ if not headers.has_key('Connection'):
0
+ if headers.has_key('Content-Length') and should_keep_alive(self.client.env()):
0
+ headers['Connection'] = 'Keep-Alive'
0
+ else:
0
+ headers['Connection'] = 'close'
0
+
0
+ # write the headers
0
+ for field, value in headers.items():
0
+ self.client.write_header(field, value)
0
+
0
+ # This should return a write() object. but it's stupid and I don't want
0
+ # to support it
0
+ return None
0
+
0
+def request_wsgi1(app, client):
0
+ body = app.__call__(client.env(), StartResponse(client))
0
+
0
+ # write the body
0
+ for part in body:
0
+ client.write_body(part)
0
+
0
+ client.release()
0
+
0
 # For WSGI 2.0
0
-def request_cb(app, client):
0
+def request_wsgi2(app, client):
0
   status_string, header_list, body = app.__call__(client.env())
0
   
0
   # status_string should be something like "200 OK" or "404 Not Found"
0
   # need to split this into an integer and human readable string for ebb
0
   match = re.search('(\d+) (.*)', status_string)
0
   status = int(match.group(1))
0
- status_human = match.group(2)
0
+ reason_phrase = match.group(2)
0
   
0
   # write the status
0
- client.write_status(status, status_human)
0
+ client.write_status(status, reason_phrase)
0
   
0
   headers = Headers(header_list)
0
   if not headers.has_key('Content-Length'):
0
@@ -60,7 +100,8 @@ def request_cb(app, client):
0
   # write the headers
0
   for field, value in headers.items():
0
     client.write_header(field, value)
0
-
0
+
0
+ # write the body
0
   for part in body:
0
     client.write_body(part)
0
   
0
@@ -84,4 +125,9 @@ def start_server(app, args = {}):
0
     ebb_ffi.listen_on_port(port)
0
     print "Ebb is listening at http://0.0.0.0:%d/" % port
0
   
0
- ebb_ffi.process_connections(app, request_cb)
0
\ No newline at end of file
0
+ if args.has_key('wsgi_version') and args['wsgi_version'] >= (2,0):
0
+ cb = request_wsgi2
0
+ else:
0
+ cb = request_wsgi1
0
+
0
+ ebb_ffi.process_connections(app, cb)
0
\ No newline at end of file
...
648
649
650
651
 
652
653
654
...
656
657
658
659
 
660
661
662
...
648
649
650
 
651
652
653
654
...
656
657
658
 
659
660
661
662
0
@@ -648,7 +648,7 @@ void ebb_client_close(ebb_client *client)
0
 }
0
 
0
 
0
-void ebb_client_write_status(ebb_client *client, int status, const char *human_status)
0
+void ebb_client_write_status(ebb_client *client, int status, const char *reason_phrase)
0
 {
0
   assert(client->in_use);
0
   if(!client->open) return;
0
@@ -656,7 +656,7 @@ void ebb_client_write_status(ebb_client *client, int status, const char *human_s
0
   g_string_append_printf( client->response_buffer
0
                         , "HTTP/1.1 %d %s\r\n"
0
                         , status
0
- , human_status
0
+ , reason_phrase
0
                         );
0
   client->status_written = TRUE;
0
 }
...
28
29
30
31
 
32
33
34
...
28
29
30
 
31
32
33
34
0
@@ -28,7 +28,7 @@ void ebb_client_close(ebb_client*);
0
 /* user MUST call this function on each client passed by the request_cb */
0
 void ebb_client_release(ebb_client*);
0
 int ebb_client_read(ebb_client *client, char *buffer, int length);
0
-void ebb_client_write_status(ebb_client*, int status, const char *human_status);
0
+void ebb_client_write_status(ebb_client*, int status, const char *reason_phrase);
0
 void ebb_client_write_header(ebb_client*, const char *field, const char *value);
0
 void ebb_client_write_body(ebb_client*, const char *data, int length);
0
 /* int ebb_client_should_keep_alive(ebb_client*); */
...
238
239
240
241
 
242
243
244
245
 
246
247
248
...
238
239
240
 
241
242
243
244
 
245
246
247
248
0
@@ -238,11 +238,11 @@ VALUE client_read_input(VALUE _, VALUE client, VALUE size)
0
   return string;
0
 }
0
 
0
-VALUE client_write_status(VALUE _, VALUE client, VALUE status, VALUE human_status)
0
+VALUE client_write_status(VALUE _, VALUE client, VALUE status, VALUE reason_phrase)
0
 {
0
   ebb_client *_client;
0
   Data_Get_Struct(client, ebb_client, _client);
0
- ebb_client_write_status(_client, FIX2INT(status), StringValuePtr(human_status));
0
+ ebb_client_write_status(_client, FIX2INT(status), StringValuePtr(reason_phrase));
0
   return Qnil;
0
 }
0
 
...
10
11
12
13
14
 
 
 
 
 
 
 
 
 
 
 
15
...
10
11
12
 
13
14
15
16
17
18
19
20
21
22
23
24
25
0
@@ -10,4 +10,14 @@ def simple_app(environ):
0
   body = ["Hello world!\n"]
0
   return([status, headers, body])
0
 
0
-ebb.start_server(simple_app, {'unix_socket': '/tmp/ebb.sock'})
0
\ No newline at end of file
0
+
0
+def simple_wsgi1_app(environ, start_response):
0
+ status = '200 OK'
0
+ headers = [('Content-type','text/plain')]
0
+ body = ["Hello world!\n"]
0
+
0
+ start_response(status, headers)
0
+ return body
0
+
0
+
0
+ebb.start_server(simple_wsgi1_app)
0
\ No newline at end of file

Comments

    No one has commented yet.