Skip to content

Commit

Permalink
Minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Nov 28, 2018
1 parent 5fa585d commit 45cc37e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
6 changes: 6 additions & 0 deletions R/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ WebServer <- R6Class("WebServer",

private$running <- TRUE
registerServer(self)
},
getHost = function() {
private$host
},
getPort = function() {
private$port
}
),
private = list(
Expand Down
16 changes: 12 additions & 4 deletions R/static_paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,10 @@ normalizeStaticPaths <- function(paths) {
if (substr(path, 1, 1) != "/") {
path <- paste0("/", path)
}
# Strip trailing slashes
path <- sub("/+$", "", path)
# Strip trailing slashes, except when the path is just "/".
if (path != "/") {
path <- sub("/+$", "\\1", path)
}

path
}, "")
Expand Down Expand Up @@ -227,14 +229,20 @@ normalizeStaticPathOptions <- function(opts) {
if (is.list(opts$headers)) {
# Convert list to named character vector
opts$headers <- unlist(opts$headers, recursive = FALSE)
# Special case: if opts$headers was an empty list before unlist(), it is
# now NULL. Replace it with an empty named character vector.
if (length(opts$headers) == 0) {
opts$headers <- c(a="a")[0]
}

if (!is.character(opts$headers) || any_unnamed(opts$headers)) {
"`headers` option must be a named list or character vector."
stop("`headers` option must be a named list or character vector.")
}
}

if (!is.null(opts$validation)) {
if (!is.character(opts$validation) || length(opts$validation) > 1) {
"`validation` option must be a character vector with zero or one element."
stop("`validation` option must be a character vector with zero or one element.")
}

# Both "" and character(0) result in character(0). Length-1 strings other
Expand Down
2 changes: 1 addition & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Rcpp::RObject optional_wrap(boost::optional<T> value) {
if (value == boost::none) {
return R_NilValue;
}
return Rcpp::wrap(*value);
return Rcpp::wrap(value.get());
}


Expand Down
3 changes: 1 addition & 2 deletions src/webapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ boost::shared_ptr<HttpResponse> RWebApplication::staticFileResponse(
int ret = pDataSource->initialize(local_path, false);

if (ret != 0) {
std::cout << pDataSource->lastErrorMessage() << "\n";
// Couldn't read the file
delete pDataSource;

Expand Down Expand Up @@ -552,7 +551,7 @@ boost::shared_ptr<HttpResponse> RWebApplication::staticFileResponse(
ResponseHeaders& respHeaders = pResponse->headers();

// Add any extra headers
ResponseHeaders extraRespHeaders = sp.options.headers.get();
const ResponseHeaders& extraRespHeaders = sp.options.headers.get();
if (extraRespHeaders.size() != 0) {
ResponseHeaders::const_iterator it;
for (it = extraRespHeaders.begin(); it != extraRespHeaders.end(); it++) {
Expand Down

0 comments on commit 45cc37e

Please sign in to comment.