mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-23 20:11:49 +00:00
Python bindings synced
This commit is contained in:
1 parent
586574e176
commit
72c861bb83
2 files changed
+18
-8
No files matched your search
@@ -13,7 +13,7 @@ def EventHandler(event, conn):
|
|||||||
if event == mongoose.HTTP_ERROR:
|
if event == mongoose.HTTP_ERROR:
|
||||||
conn.printf('%s', 'HTTP/1.0 200 OK\r\n')
|
conn.printf('%s', 'HTTP/1.0 200 OK\r\n')
|
||||||
conn.printf('%s', 'Content-Type: text/plain\r\n\r\n')
|
conn.printf('%s', 'Content-Type: text/plain\r\n\r\n')
|
||||||
conn.printf('HTTP error: %d\n', info.status_code)
|
conn.printf('HTTP error: %d\n', conn.reply_status_code)
|
||||||
return True
|
return True
|
||||||
elif event == mongoose.NEW_REQUEST and info.uri == '/show':
|
elif event == mongoose.NEW_REQUEST and info.uri == '/show':
|
||||||
conn.printf('%s', 'HTTP/1.0 200 OK\r\n')
|
conn.printf('%s', 'HTTP/1.0 200 OK\r\n')
|
||||||
|
|||||||
@@ -40,10 +40,15 @@ import ctypes
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
NEW_REQUEST = 0
|
NEW_REQUEST = 0
|
||||||
HTTP_ERROR = 1
|
REQUEST_COMPLETE = 1
|
||||||
EVENT_LOG = 2
|
HTTP_ERROR = 2
|
||||||
INIT_SSL = 3
|
EVENT_LOG = 3
|
||||||
|
INIT_SSL = 4
|
||||||
|
WEBSOCKET_CONNECT = 5
|
||||||
|
WEBSOCKET_READY = 6
|
||||||
|
WEBSOCKET_MESSAGE = 7
|
||||||
|
WEBSOCKET_CLOSE = 8
|
||||||
|
|
||||||
|
|
||||||
class mg_header(ctypes.Structure):
|
class mg_header(ctypes.Structure):
|
||||||
@@ -57,16 +62,13 @@ class mg_header(ctypes.Structure):
|
|||||||
class mg_request_info(ctypes.Structure):
|
class mg_request_info(ctypes.Structure):
|
||||||
"""A wrapper for struct mg_request_info."""
|
"""A wrapper for struct mg_request_info."""
|
||||||
_fields_ = [
|
_fields_ = [
|
||||||
('user_data', ctypes.c_char_p),
|
|
||||||
('request_method', ctypes.c_char_p),
|
('request_method', ctypes.c_char_p),
|
||||||
('uri', ctypes.c_char_p),
|
('uri', ctypes.c_char_p),
|
||||||
('http_version', ctypes.c_char_p),
|
('http_version', ctypes.c_char_p),
|
||||||
('query_string', ctypes.c_char_p),
|
('query_string', ctypes.c_char_p),
|
||||||
('remote_user', ctypes.c_char_p),
|
('remote_user', ctypes.c_char_p),
|
||||||
('log_message', ctypes.c_char_p),
|
|
||||||
('remote_ip', ctypes.c_long),
|
('remote_ip', ctypes.c_long),
|
||||||
('remote_port', ctypes.c_int),
|
('remote_port', ctypes.c_int),
|
||||||
('status_code', ctypes.c_int),
|
|
||||||
('is_ssl', ctypes.c_int),
|
('is_ssl', ctypes.c_int),
|
||||||
('num_headers', ctypes.c_int),
|
('num_headers', ctypes.c_int),
|
||||||
('http_headers', mg_header * 64),
|
('http_headers', mg_header * 64),
|
||||||
@@ -84,6 +86,10 @@ class Connection(object):
|
|||||||
self.m = mongoose
|
self.m = mongoose
|
||||||
self.conn = ctypes.c_void_p(connection)
|
self.conn = ctypes.c_void_p(connection)
|
||||||
self.info = self.m.dll.mg_get_request_info(self.conn).contents
|
self.info = self.m.dll.mg_get_request_info(self.conn).contents
|
||||||
|
self.user_data = self.m.dll.mg_get_user_data(self.conn)
|
||||||
|
self.log_message = self.m.dll.mg_get_log_message(self.conn)
|
||||||
|
self.reply_status_code = self.m.dll.mg_get_reply_status_code(self.conn)
|
||||||
|
self.ssl_context = self.m.dll.mg_get_ssl_context(self.conn)
|
||||||
|
|
||||||
def get_header(self, name):
|
def get_header(self, name):
|
||||||
val = self.m.dll.mg_get_header(self.conn, name)
|
val = self.m.dll.mg_get_header(self.conn, name)
|
||||||
@@ -131,6 +137,10 @@ class Mongoose(object):
|
|||||||
self.dll.mg_get_cookie.restype = ctypes.c_int
|
self.dll.mg_get_cookie.restype = ctypes.c_int
|
||||||
self.dll.mg_get_option.restype = ctypes.c_char_p
|
self.dll.mg_get_option.restype = ctypes.c_char_p
|
||||||
self.dll.mg_get_request_info.restype = ctypes.POINTER(mg_request_info)
|
self.dll.mg_get_request_info.restype = ctypes.POINTER(mg_request_info)
|
||||||
|
self.dll.mg_get_user_data.restype = ctypes.c_void_p
|
||||||
|
self.dll.mg_get_reply_status_code.restype = ctypes.c_int
|
||||||
|
self.dll.mg_get_log_message.restype = ctypes.c_char_p
|
||||||
|
self.dll.mg_get_ssl_context.restype = ctypes.c_void_p
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
# Create a closure that will be called by the shared library.
|
# Create a closure that will be called by the shared library.
|
||||||
|
|||||||
Reference in new issue
Block a user