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
ce01689c
Commit
ce01689c
authored
Feb 02, 2016
by
octal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Experimental http client
parent
3a154192
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
342 additions
and
278 deletions
+342
-278
include/client.h
include/client.h
+128
-196
include/common.h
include/common.h
+2
-0
include/http.h
include/http.h
+1
-0
include/http_header.h
include/http_header.h
+7
-2
include/http_headers.h
include/http_headers.h
+10
-0
main.cc
main.cc
+21
-11
src/client/client.cc
src/client/client.cc
+154
-68
src/common/http_header.cc
src/common/http_header.cc
+4
-0
src/common/http_headers.cc
src/common/http_headers.cc
+14
-0
tests/headers_test.cc
tests/headers_test.cc
+1
-1
No files found.
include/client.h
View file @
ce01689c
This diff is collapsed.
Click to expand it.
include/common.h
View file @
ce01689c
...
...
@@ -15,6 +15,8 @@
#include <sys/socket.h>
#include <netdb.h>
#define unsafe
#define TRY(...) \
do { \
auto ret = __VA_ARGS__; \
...
...
include/http.h
View file @
ce01689c
...
...
@@ -97,6 +97,7 @@ public:
friend
class
Private
::
Parser
<
Http
::
Request
>
;
friend
class
RequestBuilder
;
friend
class
Client
;
Request
(
const
Request
&
other
)
=
default
;
Request
&
operator
=
(
const
Request
&
other
)
=
default
;
...
...
include/http_header.h
View file @
ce01689c
...
...
@@ -314,7 +314,8 @@ public:
Host
()
{
}
explicit
Host
(
const
std
::
string
&
host
,
Net
::
Port
port
=
80
)
explicit
Host
(
const
std
::
string
&
host
);
explicit
Host
(
const
std
::
string
&
host
,
Net
::
Port
port
)
:
host_
(
host
)
,
port_
(
port
)
{
}
...
...
@@ -364,7 +365,11 @@ public:
void
parse
(
const
std
::
string
&
data
);
void
write
(
std
::
ostream
&
os
)
const
;
std
::
string
ua
()
const
{
return
ua_
;
}
void
setAgent
(
std
::
string
ua
)
{
ua_
=
std
::
move
(
ua
);
}
std
::
string
agent
()
const
{
return
ua_
;
}
private:
std
::
string
ua_
;
...
...
include/http_headers.h
View file @
ce01689c
...
...
@@ -61,6 +61,14 @@ public:
return
add
(
std
::
make_shared
<
H
>
(
std
::
forward
<
Args
>
(
args
)...));
}
template
<
typename
H
>
typename
std
::
enable_if
<
IsHeader
<
H
>::
value
,
bool
>::
type
remove
()
{
return
remove
(
H
::
Name
);
}
std
::
shared_ptr
<
const
Header
>
get
(
const
std
::
string
&
name
)
const
;
std
::
shared_ptr
<
Header
>
get
(
const
std
::
string
&
name
);
Raw
getRaw
(
const
std
::
string
&
name
)
const
;
...
...
@@ -80,6 +88,8 @@ public:
std
::
vector
<
std
::
shared_ptr
<
Header
>>
list
()
const
;
bool
remove
(
const
std
::
string
&
name
);
void
clear
();
private:
...
...
main.cc
View file @
ce01689c
...
...
@@ -339,22 +339,32 @@ int main(int argc, char *argv[]) {
#if 1
int
main
()
{
Net
::
Http
::
Client
client
(
"http://
www.foaas.com
"
);
Net
::
Http
::
Client
client
(
"http://
supnetwork.org:9080
"
);
auto
opts
=
Net
::
Http
::
Client
::
options
()
.
threads
(
1
)
.
maxConnections
(
1
);
.
maxConnections
(
20
);
using
namespace
Net
::
Http
;
constexpr
size_t
Requests
=
1000
;
std
::
atomic
<
int
>
responsesReceived
(
0
);
client
.
init
(
opts
);
client
.
get
(
client
.
request
(
"/off/octal/nask"
)
.
header
<
Header
::
ContentType
>
(
MIME
(
Text
,
Plain
))
.
cookie
(
Cookie
(
"FOO"
,
"bar"
)))
.
then
([](
const
Http
::
Response
&
response
)
{
std
::
cout
<<
"code = "
<<
response
.
code
()
<<
std
::
endl
;
std
::
cout
<<
"body = "
<<
response
.
body
()
<<
std
::
endl
;
},
Async
::
NoExcept
);
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
1
));
for
(
int
i
=
0
;
i
<
Requests
;
++
i
)
{
client
.
get
(
client
.
request
(
"/ping"
)
.
cookie
(
Cookie
(
"FOO"
,
"bar"
)))
.
then
([
&
](
const
Http
::
Response
&
response
)
{
responsesReceived
.
fetch_add
(
1
);
//std::cout << "code = " << response.code() << std::endl;
// std::cout << "body = " << response.body() << std::endl;
},
Async
::
NoExcept
);
}
std
::
cout
<<
"Sent "
<<
Requests
<<
" requests"
<<
std
::
endl
;
for
(;;)
{
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
seconds
(
1
));
std
::
cout
<<
"Received "
<<
responsesReceived
.
load
()
<<
" responses"
<<
std
::
endl
;
}
client
.
shutdown
();
}
#endif
src/client/client.cc
View file @
ce01689c
This diff is collapsed.
Click to expand it.
src/common/http_header.cc
View file @
ce01689c
...
...
@@ -297,6 +297,10 @@ Expect::write(std::ostream& os) const {
}
}
Host
::
Host
(
const
std
::
string
&
data
)
{
parse
(
data
);
}
void
Host
::
parse
(
const
std
::
string
&
data
)
{
auto
pos
=
data
.
find
(
':'
);
...
...
src/common/http_headers.cc
View file @
ce01689c
...
...
@@ -157,6 +157,20 @@ Collection::list() const {
return
ret
;
}
bool
Collection
::
remove
(
const
std
::
string
&
name
)
{
auto
tit
=
headers
.
find
(
name
);
if
(
tit
==
std
::
end
(
headers
))
{
auto
rit
=
rawHeaders
.
find
(
name
);
if
(
rit
==
std
::
end
(
rawHeaders
))
return
false
;
rawHeaders
.
erase
(
rit
);
return
true
;
}
headers
.
erase
(
tit
);
return
true
;
}
void
Collection
::
clear
()
{
headers
.
clear
();
...
...
tests/headers_test.cc
View file @
ce01689c
...
...
@@ -225,7 +225,7 @@ TEST(headers_test, user_agent) {
Header
::
UserAgent
ua
;
ua
.
parse
(
"CERN-LineMode/2.15 libwww/2.17b3"
);
ASSERT_EQ
(
ua
.
ua
(),
"CERN-LineMode/2.15 libwww/2.17b3"
);
ASSERT_EQ
(
ua
.
agent
(),
"CERN-LineMode/2.15 libwww/2.17b3"
);
}
TEST
(
headers_test
,
content_encoding
)
{
...
...
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