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
adf5ce0e
Unverified
Commit
adf5ce0e
authored
Nov 12, 2018
by
Dennis Jenkins
Committed by
GitHub
Nov 12, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #349 from knowledge4igor/fix_issue_346
Fix issue #346
parents
b88af74d
9b4744c6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
23 deletions
+14
-23
include/pistache/http.h
include/pistache/http.h
+3
-2
include/pistache/stream.h
include/pistache/stream.h
+1
-2
src/common/description.cc
src/common/description.cc
+2
-2
src/common/http.cc
src/common/http.cc
+3
-3
src/common/stream.cc
src/common/stream.cc
+5
-14
No files found.
include/pistache/http.h
View file @
adf5ce0e
...
...
@@ -13,6 +13,7 @@
#include <sstream>
#include <algorithm>
#include <memory>
#include <string>
#include <sys/timerfd.h>
...
...
@@ -443,7 +444,7 @@ class ResponseWriter : public Response {
public:
static
constexpr
size_t
DefaultStreamSize
=
512
;
friend
Async
::
Promise
<
ssize_t
>
serveFile
(
ResponseWriter
&
,
const
char
*
,
const
Mime
::
MediaType
&
);
friend
Async
::
Promise
<
ssize_t
>
serveFile
(
ResponseWriter
&
,
const
std
::
string
&
,
const
Mime
::
MediaType
&
);
friend
class
Handler
;
friend
class
Timeout
;
...
...
@@ -602,7 +603,7 @@ private:
};
Async
::
Promise
<
ssize_t
>
serveFile
(
ResponseWriter
&
response
,
const
char
*
fileName
,
ResponseWriter
&
response
,
const
std
::
string
&
fileName
,
const
Mime
::
MediaType
&
contentType
=
Mime
::
MediaType
());
namespace
Private
{
...
...
include/pistache/stream.h
View file @
adf5ce0e
...
...
@@ -13,6 +13,7 @@
#include <vector>
#include <limits>
#include <iostream>
#include <string>
#include <pistache/os.h>
...
...
@@ -158,7 +159,6 @@ struct FileBuffer {
,
size_
()
{
}
FileBuffer
(
const
char
*
fileName
);
FileBuffer
(
const
std
::
string
&
fileName
);
std
::
string
fileName
()
const
{
return
fileName_
;
}
...
...
@@ -166,7 +166,6 @@ struct FileBuffer {
size_t
size
()
const
{
return
size_
;
}
private:
void
init
(
const
char
*
fileName
);
std
::
string
fileName_
;
Fd
fd_
;
size_t
size_
;
...
...
src/common/description.cc
View file @
adf5ce0e
...
...
@@ -461,14 +461,14 @@ Swagger::install(Rest::Router& router) {
response
.
send
(
Http
::
Code
::
Moved_Permanently
);
}
else
{
auto
index
=
uiDir
.
join
(
"index.html"
);
Http
::
serveFile
(
response
,
index
.
c_str
()
);
Http
::
serveFile
(
response
,
index
);
}
return
Route
::
Result
::
Ok
;
}
else
if
(
ui
.
isPrefix
(
req
))
{
auto
file
=
ui
.
stripPrefix
(
req
);
auto
path
=
uiDir
.
join
(
file
);
Http
::
serveFile
(
response
,
path
.
c_str
()
);
Http
::
serveFile
(
response
,
path
);
return
Route
::
Result
::
Ok
;
}
...
...
src/common/http.cc
View file @
adf5ce0e
...
...
@@ -681,11 +681,11 @@ ResponseWriter::putOnWire(const char* data, size_t len)
}
Async
::
Promise
<
ssize_t
>
serveFile
(
ResponseWriter
&
response
,
const
char
*
fileName
,
const
Mime
::
MediaType
&
contentType
)
serveFile
(
ResponseWriter
&
response
,
const
std
::
string
&
fileName
,
const
Mime
::
MediaType
&
contentType
)
{
struct
stat
sb
;
int
fd
=
open
(
fileName
,
O_RDONLY
);
int
fd
=
open
(
fileName
.
c_str
()
,
O_RDONLY
);
if
(
fd
==
-
1
)
{
std
::
string
str_error
(
strerror
(
errno
));
if
(
errno
==
ENOENT
)
{
...
...
@@ -731,7 +731,7 @@ serveFile(ResponseWriter& response, const char* fileName, const Mime::MediaType&
if
(
contentType
.
isValid
())
{
setContentType
(
contentType
);
}
else
{
auto
mime
=
Mime
::
MediaType
::
fromFile
(
fileName
);
auto
mime
=
Mime
::
MediaType
::
fromFile
(
fileName
.
c_str
()
);
if
(
mime
.
isValid
())
setContentType
(
mime
);
}
...
...
src/common/stream.cc
View file @
adf5ce0e
...
...
@@ -5,6 +5,7 @@
#include <iostream>
#include <algorithm>
#include <string>
#include <sys/types.h>
#include <sys/stat.h>
...
...
@@ -15,25 +16,15 @@
namespace
Pistache
{
FileBuffer
::
FileBuffer
(
const
char
*
fileName
)
:
fileName_
(
fileName
)
{
init
(
fileName
);
}
FileBuffer
::
FileBuffer
(
const
std
::
string
&
fileName
)
:
fileName_
(
fileName
)
{
init
(
fileName
.
c_str
());
}
void
FileBuffer
::
init
(
const
char
*
fileName
)
{
if
(
!
fileName
)
{
throw
std
::
runtime_error
(
"Missing fileName"
);
if
(
fileName
.
empty
())
{
throw
std
::
runtime_error
(
"Empty fileName"
);
}
int
fd
=
open
(
fileName
,
O_RDONLY
);
int
fd
=
open
(
fileName
.
c_str
(),
O_RDONLY
);
if
(
fd
==
-
1
)
{
throw
std
::
runtime_error
(
"Could not open file"
);
}
...
...
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