Skip to content

Commit

Permalink
Add http-parser binding
Browse files Browse the repository at this point in the history
  • Loading branch information
1st1 committed Oct 29, 2015
1 parent fe4fb8c commit 6115d73
Show file tree
Hide file tree
Showing 9 changed files with 423 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ __pycache__/
.d8_history
/*.egg
/*.egg-info
/dist
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2015 MagicStack Inc. http://magic.io

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
recursive-include vendor *.c *.h LICENSE* README*
include MANIFEST.in LICENSE
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compile:
cython httptools/parser/parser.pyx
python3 setup.py build_ext --inplace


release: compile
python3 setup.py sdist upload
3 changes: 3 additions & 0 deletions httptools/parser/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.so
*.html
*.c
1 change: 1 addition & 0 deletions httptools/parser/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .parser import HttpParser, HttpParserError, MODE_REQUEST, MODE_RESPONSE
108 changes: 108 additions & 0 deletions httptools/parser/cparser.pxd
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from libc.stdint cimport uint32_t, uint64_t


cdef extern from "../../vendor/http-parser/http_parser.h":
ctypedef int (*http_data_cb) (http_parser*, const char *at, size_t length)
ctypedef int (*http_cb) (http_parser*)

struct http_parser:
unsigned int type
unsigned int flags
unsigned int state
unsigned int header_state
unsigned int index

uint32_t nread
uint64_t content_length

unsigned short http_major
unsigned short http_minor
unsigned int status_code
unsigned int method
unsigned int http_errno

unsigned int upgrade

void *data

struct http_parser_settings:
http_cb on_message_begin
http_data_cb on_url
http_data_cb on_status
http_data_cb on_header_field
http_data_cb on_header_value
http_cb on_headers_complete
http_data_cb on_body
http_cb on_message_complete
http_cb on_chunk_header
http_cb on_chunk_complete

enum http_parser_type:
HTTP_REQUEST,
HTTP_RESPONSE,
HTTP_BOTH

enum http_errno:
HPE_OK,
HPE_CB_message_begin,
HPE_CB_url,
HPE_CB_header_field,
HPE_CB_header_value,
HPE_CB_headers_complete,
HPE_CB_body,
HPE_CB_message_complete,
HPE_CB_status,
HPE_CB_chunk_header,
HPE_CB_chunk_complete,
HPE_INVALID_EOF_STATE,
HPE_HEADER_OVERFLOW,
HPE_CLOSED_CONNECTION,
HPE_INVALID_VERSION,
HPE_INVALID_STATUS,
HPE_INVALID_METHOD,
HPE_INVALID_URL,
HPE_INVALID_HOST,
HPE_INVALID_PORT,
HPE_INVALID_PATH,
HPE_INVALID_QUERY_STRING,
HPE_INVALID_FRAGMENT,
HPE_LF_EXPECTED,
HPE_INVALID_HEADER_TOKEN,
HPE_INVALID_CONTENT_LENGTH,
HPE_INVALID_CHUNK_SIZE,
HPE_INVALID_CONSTANT,
HPE_INVALID_INTERNAL_STATE,
HPE_STRICT,
HPE_PAUSED,
HPE_UNKNOWN

enum flags:
F_CHUNKED,
F_CONNECTION_KEEP_ALIVE,
F_CONNECTION_CLOSE,
F_CONNECTION_UPGRADE,
F_TRAILING,
F_UPGRADE,
F_SKIPBODY

enum http_method:
DELETE, GET, HEAD, POST, PUT, CONNECT, OPTIONS, TRACE, COPY,
LOCK, MKCOL, MOVE, PROPFIND, PROPPATCH, SEARCH, UNLOCK, BIND,
REBIND, UNBIND, ACL, REPORT, MKACTIVITY, CHECKOUT, MERGE,
MSEARCH, NOTIFY, SUBSCRIBE, UNSUBSCRIBE, PATCH, PURGE, MKCALENDAR,
LINK, UNLINK

void http_parser_init(http_parser *parser, http_parser_type type)

size_t http_parser_execute(http_parser *parser,
const http_parser_settings *settings,
const char *data,
size_t len)

int http_should_keep_alive(const http_parser *parser)

void http_parser_settings_init(http_parser_settings *settings)

const char *http_errno_name(http_errno err)
const char *http_errno_description(http_errno err)
const char *http_method_str(http_method m)
Loading

0 comments on commit 6115d73

Please sign in to comment.