Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
72c861bb
Commit
72c861bb
authored
Sep 21, 2012
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Python bindings synced
parent
586574e1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
8 deletions
+18
-8
example.py
bindings/python/example.py
+1
-1
mongoose.py
bindings/python/mongoose.py
+17
-7
No files found.
bindings/python/example.py
View file @
72c861bb
...
...
@@ -13,7 +13,7 @@ def EventHandler(event, conn):
if
event
==
mongoose
.
HTTP_ERROR
:
conn
.
printf
(
'
%
s'
,
'HTTP/1.0 200 OK
\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
elif
event
==
mongoose
.
NEW_REQUEST
and
info
.
uri
==
'/show'
:
conn
.
printf
(
'
%
s'
,
'HTTP/1.0 200 OK
\r\n
'
)
...
...
bindings/python/mongoose.py
View file @
72c861bb
...
...
@@ -40,10 +40,15 @@ import ctypes
import
os
NEW_REQUEST
=
0
HTTP_ERROR
=
1
EVENT_LOG
=
2
INIT_SSL
=
3
NEW_REQUEST
=
0
REQUEST_COMPLETE
=
1
HTTP_ERROR
=
2
EVENT_LOG
=
3
INIT_SSL
=
4
WEBSOCKET_CONNECT
=
5
WEBSOCKET_READY
=
6
WEBSOCKET_MESSAGE
=
7
WEBSOCKET_CLOSE
=
8
class
mg_header
(
ctypes
.
Structure
):
...
...
@@ -57,16 +62,13 @@ class mg_header(ctypes.Structure):
class
mg_request_info
(
ctypes
.
Structure
):
"""A wrapper for struct mg_request_info."""
_fields_
=
[
(
'user_data'
,
ctypes
.
c_char_p
),
(
'request_method'
,
ctypes
.
c_char_p
),
(
'uri'
,
ctypes
.
c_char_p
),
(
'http_version'
,
ctypes
.
c_char_p
),
(
'query_string'
,
ctypes
.
c_char_p
),
(
'remote_user'
,
ctypes
.
c_char_p
),
(
'log_message'
,
ctypes
.
c_char_p
),
(
'remote_ip'
,
ctypes
.
c_long
),
(
'remote_port'
,
ctypes
.
c_int
),
(
'status_code'
,
ctypes
.
c_int
),
(
'is_ssl'
,
ctypes
.
c_int
),
(
'num_headers'
,
ctypes
.
c_int
),
(
'http_headers'
,
mg_header
*
64
),
...
...
@@ -84,6 +86,10 @@ class Connection(object):
self
.
m
=
mongoose
self
.
conn
=
ctypes
.
c_void_p
(
connection
)
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
):
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_option
.
restype
=
ctypes
.
c_char_p
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
:
# Create a closure that will be called by the shared library.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment