Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pistache
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
Libraries
pistache
Commits
725e53ea
Commit
725e53ea
authored
Dec 29, 2015
by
octal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved URI query parameter parsing
parent
a9217a15
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
17 deletions
+39
-17
main.cc
main.cc
+15
-8
src/http.cc
src/http.cc
+23
-9
src/http.h
src/http.h
+1
-0
No files found.
main.cc
View file @
725e53ea
...
...
@@ -28,14 +28,21 @@ class MyHandler : public Net::Http::Handler {
using
namespace
Net
::
Http
;
response
.
headers
()
.
add
<
Header
::
Server
>
(
"lys"
)
.
add
<
Header
::
ContentType
>
(
MIME
(
Text
,
Plain
));
auto
stream
=
response
.
stream
(
Net
::
Http
::
Code
::
Ok
);
stream
<<
"PO"
;
stream
<<
"NG"
;
stream
<<
ends
;
timeout
.
arm
(
std
::
chrono
::
seconds
(
2
));
auto
query
=
req
.
query
();
if
(
query
.
has
(
"chunked"
))
{
std
::
cout
<<
"Using chunked encoding"
<<
std
::
endl
;
response
.
headers
()
.
add
<
Header
::
Server
>
(
"lys"
)
.
add
<
Header
::
ContentType
>
(
MIME
(
Text
,
Plain
));
auto
stream
=
response
.
stream
(
Net
::
Http
::
Code
::
Ok
);
stream
<<
"PO"
;
stream
<<
"NG"
;
stream
<<
ends
;
}
}
}
...
...
src/http.cc
View file @
725e53ea
...
...
@@ -93,21 +93,30 @@ namespace Private {
while
((
n
=
cursor
.
current
())
!=
' '
)
{
StreamCursor
::
Token
keyToken
(
cursor
);
if
(
!
match_until
(
'='
,
cursor
))
if
(
!
match_until
(
{
'='
,
' '
,
'&'
}
,
cursor
))
return
State
::
Again
;
std
::
string
key
=
keyToken
.
text
();
if
(
!
cursor
.
advance
(
1
))
return
State
::
Again
;
auto
c
=
cursor
.
current
();
if
(
c
==
' '
)
{
request
->
query_
.
add
(
std
::
move
(
key
),
""
);
}
else
if
(
c
==
'&'
)
{
request
->
query_
.
add
(
std
::
move
(
key
),
""
);
if
(
!
cursor
.
advance
(
1
))
return
State
::
Again
;
}
else
if
(
c
==
'='
)
{
if
(
!
cursor
.
advance
(
1
))
return
State
::
Again
;
StreamCursor
::
Token
valueToken
(
cursor
);
if
(
!
match_until
({
' '
,
'&'
},
cursor
))
return
State
::
Again
;
StreamCursor
::
Token
valueToken
(
cursor
);
if
(
!
match_until
({
' '
,
'&'
},
cursor
))
return
State
::
Again
;
std
::
string
value
=
valueToken
.
text
();
request
->
query_
.
add
(
std
::
move
(
key
),
std
::
move
(
value
));
if
(
cursor
.
current
()
==
'&'
)
{
if
(
!
cursor
.
advance
(
1
))
return
State
::
Again
;
std
::
string
value
=
valueToken
.
text
();
request
->
query_
.
add
(
std
::
move
(
key
),
std
::
move
(
value
));
if
(
cursor
.
current
()
==
'&'
)
{
if
(
!
cursor
.
advance
(
1
))
return
State
::
Again
;
}
}
}
}
...
...
@@ -305,6 +314,11 @@ namespace Uri {
return
Some
(
it
->
second
);
}
bool
Query
::
has
(
const
std
::
string
&
name
)
const
{
return
params
.
find
(
name
)
!=
std
::
end
(
params
);
}
}
// namespace Uri
Request
::
Request
()
...
...
src/http.h
View file @
725e53ea
...
...
@@ -65,6 +65,7 @@ namespace Uri {
void
add
(
std
::
string
name
,
std
::
string
value
);
Optional
<
std
::
string
>
get
(
const
std
::
string
&
name
)
const
;
bool
has
(
const
std
::
string
&
name
)
const
;
private:
std
::
unordered_map
<
std
::
string
,
std
::
string
>
params
;
...
...
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