Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
http-server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefane Fermigier
http-server
Commits
416ac9dc
Commit
416ac9dc
authored
Nov 10, 2021
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement HTTP parser
parent
6433d87f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
108 additions
and
0 deletions
+108
-0
src/stdlib/http.pxd
src/stdlib/http.pxd
+108
-0
No files found.
src/stdlib/http.pxd
0 → 100644
View file @
416ac9dc
from
stdlib.string
cimport
Str
from
libcythonplus.dict
cimport
cypdict
cdef
cypclass
HTTPRequest
:
Str
raw
Str
method
Str
uri
Str
version
cypdict
[
Str
,
Str
]
headers
int
_pos
bint
ok
__init__
(
self
,
Str
request
):
self
.
headers
=
cypdict
[
Str
,
Str
]()
self
.
raw
=
request
self
.
ok
=
True
self
.
parse
()
int
whitespace
(
self
):
cdef
int
i
=
self
.
_pos
cdef
int
l
=
self
.
raw
.
__len__
()
cdef
int
n
while
i
<
l
:
c
=
self
.
raw
[
i
]
# space or tab
if
c
==
<
char
>
32
or
c
==
<
char
>
9
:
i
+=
1
continue
break
n
=
i
-
self
.
_pos
self
.
_pos
=
i
return
n
int
rstrip
(
self
,
int
start
,
int
stop
):
while
stop
>
start
:
c
=
self
.
raw
[
stop
-
1
]
# space or tab
if
c
==
<
char
>
32
or
c
==
<
char
>
9
:
stop
-=
1
continue
break
return
stop
int
peek
(
self
,
Str
sentinel
,
int
stop
=
0
):
return
self
.
raw
.
find
(
sentinel
,
self
.
_pos
,
stop
)
void
skip
(
self
,
Str
sentinel
,
int
start
=-
1
):
if
start
<
self
.
_pos
:
start
=
self
.
_pos
self
.
_pos
=
start
+
sentinel
.
__len__
()
Str
step
(
self
,
int
stop
):
cdef
int
start
=
self
.
_pos
self
.
_pos
=
stop
return
self
.
raw
.
substr
(
start
,
stop
)
Str
token
(
self
,
Str
sentinel
,
int
stop
=
0
):
cdef
int
start
=
self
.
_pos
stop
=
self
.
peek
(
sentinel
,
stop
)
if
stop
==
-
1
:
return
NULL
self
.
_pos
=
stop
+
sentinel
.
__len__
()
return
self
.
raw
.
substr
(
start
,
stop
)
void
error
(
self
):
self
.
ok
=
False
void
parse
(
self
):
cdef
Str
SP
=
Str
(
' '
)
cdef
Str
CRLF
=
Str
(
'
\
r
\
n
'
)
cdef
Str
COL
=
Str
(
':'
)
cdef
int
end
=
self
.
raw
.
__len__
()
self
.
_pos
=
0
endline
=
self
.
peek
(
CRLF
)
method
=
self
.
token
(
SP
,
endline
)
if
method
is
NULL
:
self
.
error
()
return
self
.
method
=
method
uri
=
self
.
token
(
SP
,
endline
)
if
uri
is
NULL
:
self
.
error
()
return
self
.
uri
=
uri
version
=
self
.
token
(
CRLF
)
if
version
is
NULL
:
self
.
error
()
return
self
.
version
=
version
while
self
.
_pos
<
end
:
endline
=
self
.
peek
(
CRLF
)
if
endline
==
self
.
_pos
:
self
.
skip
(
CRLF
)
break
key
=
self
.
token
(
COL
,
endline
)
if
key
is
NULL
:
self
.
error
()
return
self
.
whitespace
()
stop
=
self
.
rstrip
(
self
.
_pos
,
endline
)
if
stop
<=
self
.
_pos
:
self
.
error
()
return
value
=
self
.
raw
.
substr
(
self
.
_pos
,
stop
)
self
.
skip
(
CRLF
,
endline
)
self
.
headers
[
key
]
=
value
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