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
c20e9ef8
Commit
c20e9ef8
authored
Aug 01, 2018
by
Nico Caprioli
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'upstream/master'
parents
e183294c
ae904949
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
25 deletions
+61
-25
include/pistache/http.h
include/pistache/http.h
+4
-2
include/pistache/mime.h
include/pistache/mime.h
+1
-0
src/client/client.cc
src/client/client.cc
+33
-21
src/common/http.cc
src/common/http.cc
+20
-1
src/common/mime.cc
src/common/mime.cc
+3
-1
No files found.
include/pistache/http.h
View file @
c20e9ef8
...
@@ -87,7 +87,6 @@ protected:
...
@@ -87,7 +87,6 @@ protected:
};
};
namespace
Uri
{
namespace
Uri
{
typedef
std
::
string
Fragment
;
class
Query
{
class
Query
{
public:
public:
...
@@ -97,12 +96,15 @@ namespace Uri {
...
@@ -97,12 +96,15 @@ namespace Uri {
void
add
(
std
::
string
name
,
std
::
string
value
);
void
add
(
std
::
string
name
,
std
::
string
value
);
Optional
<
std
::
string
>
get
(
const
std
::
string
&
name
)
const
;
Optional
<
std
::
string
>
get
(
const
std
::
string
&
name
)
const
;
bool
has
(
const
std
::
string
&
name
)
const
;
bool
has
(
const
std
::
string
&
name
)
const
;
// Return empty string or "?key1=value1&key2=value2" if query exist
std
::
string
as_str
()
const
;
void
clear
()
{
void
clear
()
{
params
.
clear
();
params
.
clear
();
}
}
private:
private:
//first is key second is value
std
::
unordered_map
<
std
::
string
,
std
::
string
>
params
;
std
::
unordered_map
<
std
::
string
,
std
::
string
>
params
;
};
};
}
// namespace Uri
}
// namespace Uri
...
...
include/pistache/mime.h
View file @
c20e9ef8
...
@@ -36,6 +36,7 @@ namespace Mime {
...
@@ -36,6 +36,7 @@ namespace Mime {
SUB_TYPE(Javascript, "javascript") \
SUB_TYPE(Javascript, "javascript") \
SUB_TYPE(Css , "css") \
SUB_TYPE(Css , "css") \
\
\
SUB_TYPE(OctetStream, "octet-stream") \
SUB_TYPE(Json , "json") \
SUB_TYPE(Json , "json") \
SUB_TYPE(FormUrlEncoded, "x-www-form-urlencoded") \
SUB_TYPE(FormUrlEncoded, "x-www-form-urlencoded") \
\
\
...
...
src/client/client.cc
View file @
c20e9ef8
...
@@ -463,43 +463,55 @@ Connection::handleResponsePacket(const char* buffer, size_t bytes) {
...
@@ -463,43 +463,55 @@ Connection::handleResponsePacket(const char* buffer, size_t bytes) {
parser_
.
feed
(
buffer
,
bytes
);
parser_
.
feed
(
buffer
,
bytes
);
if
(
parser_
.
parse
()
==
Private
::
State
::
Done
)
{
if
(
parser_
.
parse
()
==
Private
::
State
::
Done
)
{
auto
req
=
std
::
move
(
inflightRequests
.
front
());
if
(
!
inflightRequests
.
empty
())
{
inflightRequests
.
pop_back
();
auto
req
=
std
::
move
(
inflightRequests
.
front
());
inflightRequests
.
pop_back
();
if
(
req
.
timer
)
{
if
(
req
.
timer
)
{
req
.
timer
->
disarm
();
req
.
timer
->
disarm
();
timerPool_
.
releaseTimer
(
req
.
timer
);
timerPool_
.
releaseTimer
(
req
.
timer
);
}
}
req
.
resolve
(
std
::
move
(
parser_
.
response
));
req
.
resolve
(
std
::
move
(
parser_
.
response
));
req
.
onDone
();
if
(
req
.
onDone
)
req
.
onDone
();
}
parser_
.
reset
();
parser_
.
reset
();
}
}
}
}
void
void
Connection
::
handleError
(
const
char
*
error
)
{
Connection
::
handleError
(
const
char
*
error
)
{
auto
req
=
std
::
move
(
inflightRequests
.
front
());
if
(
!
inflightRequests
.
empty
())
{
if
(
req
.
timer
)
{
auto
req
=
std
::
move
(
inflightRequests
.
front
());
req
.
timer
->
disarm
();
if
(
req
.
timer
)
{
timerPool_
.
releaseTimer
(
req
.
timer
);
req
.
timer
->
disarm
();
}
timerPool_
.
releaseTimer
(
req
.
timer
);
}
req
.
reject
(
Error
(
error
));
req
.
reject
(
Error
(
error
));
req
.
onDone
();
if
(
req
.
onDone
)
req
.
onDone
();
}
}
}
void
void
Connection
::
handleTimeout
()
{
Connection
::
handleTimeout
()
{
auto
req
=
std
::
move
(
inflightRequests
.
front
());
if
(
!
inflightRequests
.
empty
())
{
inflightRequests
.
pop_back
();
auto
req
=
std
::
move
(
inflightRequests
.
front
());
inflightRequests
.
pop_back
();
timerPool_
.
releaseTimer
(
req
.
timer
);
timerPool_
.
releaseTimer
(
req
.
timer
);
if
(
req
.
onDone
)
req
.
onDone
();
req
.
onDone
();
/* @API: create a TimeoutException */
/* @API: create a TimeoutException */
req
.
reject
(
std
::
runtime_error
(
"Timeout"
));
req
.
reject
(
std
::
runtime_error
(
"Timeout"
));
}
}
}
Async
::
Promise
<
Response
>
Async
::
Promise
<
Response
>
Connection
::
perform
(
Connection
::
perform
(
const
Http
::
Request
&
request
,
const
Http
::
Request
&
request
,
...
...
src/common/http.cc
View file @
c20e9ef8
...
@@ -500,6 +500,18 @@ namespace Uri {
...
@@ -500,6 +500,18 @@ namespace Uri {
return
Some
(
it
->
second
);
return
Some
(
it
->
second
);
}
}
std
::
string
Query
::
as_str
()
const
{
std
::
string
query_url
;
for
(
const
auto
&
e
:
params
)
{
query_url
+=
"&"
+
e
.
first
+
"="
+
e
.
second
;
}
if
(
not
query_url
.
empty
())
{
query_url
[
0
]
=
'?'
;
// replace first `&` with `?`
}
else
{
/* query_url is empty */
}
return
query_url
;
}
bool
bool
Query
::
has
(
const
std
::
string
&
name
)
const
{
Query
::
has
(
const
std
::
string
&
name
)
const
{
...
@@ -668,10 +680,17 @@ serveFile(ResponseWriter& response, const char* fileName, const Mime::MediaType&
...
@@ -668,10 +680,17 @@ serveFile(ResponseWriter& response, const char* fileName, const Mime::MediaType&
int
fd
=
open
(
fileName
,
O_RDONLY
);
int
fd
=
open
(
fileName
,
O_RDONLY
);
if
(
fd
==
-
1
)
{
if
(
fd
==
-
1
)
{
std
::
string
str_error
(
strerror
(
errno
));
if
(
errno
==
ENOENT
)
{
throw
HttpError
(
Http
::
Code
::
Not_Found
,
std
::
move
(
str_error
));
}
//eles if TODO
/* @Improvement: maybe could we check for errno here and emit a different error
/* @Improvement: maybe could we check for errno here and emit a different error
message
message
*/
*/
throw
HttpError
(
Http
::
Code
::
Not_Found
,
""
);
else
{
throw
HttpError
(
Http
::
Code
::
Internal_Server_Error
,
std
::
move
(
str_error
));
}
}
}
int
res
=
::
fstat
(
fd
,
&
sb
);
int
res
=
::
fstat
(
fd
,
&
sb
);
...
...
src/common/mime.cc
View file @
c20e9ef8
...
@@ -82,7 +82,9 @@ MediaType::fromFile(const char* fileName)
...
@@ -82,7 +82,9 @@ MediaType::fromFile(const char* fileName)
{
"bmp"
,
Type
::
Image
,
Subtype
::
Bmp
},
{
"bmp"
,
Type
::
Image
,
Subtype
::
Bmp
},
{
"txt"
,
Type
::
Text
,
Subtype
::
Plain
},
{
"txt"
,
Type
::
Text
,
Subtype
::
Plain
},
{
"md"
,
Type
::
Text
,
Subtype
::
Plain
}
{
"md"
,
Type
::
Text
,
Subtype
::
Plain
},
{
"bin"
,
Type
::
Application
,
Subtype
::
OctetStream
},
};
};
for
(
const
auto
&
ext
:
KnownExtensions
)
{
for
(
const
auto
&
ext
:
KnownExtensions
)
{
...
...
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