Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a parameter that allows the upgrade of insecure requests #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ Imports:
crayon,
rstudioapi,
stringi
RoxygenNote: 7.1.0
RoxygenNote: 7.2.3
LinkingTo:
Rcpp
34 changes: 25 additions & 9 deletions R/file_stream_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ lc_server <- R6::R6Class(
)


file_stream_server = function(host, port, file, file_id, interval = 3, template = "prism") {
file_stream_server = function(host, port, file, file_id, interval = 3, template = "prism", upgrade_content_security_policy) {
port = as.integer(port)
file_cache = file_cache(file)
if (upgrade_content_security_policy == TRUE){
content_security_policy = '<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">'
} else {
content_security_policy = ""
}
page = glue::glue(
readr::read_file(get_template(template)),
lang = "r",
title = file
title = file,
meta = content_security_policy
)

get_next_ws_id = local({
Expand Down Expand Up @@ -157,6 +163,7 @@ lc_server_iface = R6::R6Class(
interval = NULL,
bitly_url = NULL,
server = NULL,
upgrade_content_security_policy = NULL,

init_file = function(file, auto_save) {

Expand Down Expand Up @@ -271,16 +278,20 @@ lc_server_iface = R6::R6Class(
#' @param bitly should a bitly bit link be created for the server.
#' @param auto_save should the broadcast file be auto saved update tic.
#' @param open_browser should a browser session be opened.
#' @param upgrade_content_security_policy should insecure requests be upgraded.
initialize = function(
file, ip, port, interval = 2,
bitly = FALSE, auto_save = TRUE, open_browser = TRUE
bitly = FALSE, auto_save = TRUE, open_browser = TRUE,
upgrade_content_security_policy = FALSE
) {
private$init_file(file, auto_save)
private$init_ip(ip)
private$init_port(port)

private$template = "prism"
private$interval = interval
private$upgrade_content_security_policy =
upgrade_content_security_policy
self$start()

if (bitly)
Expand Down Expand Up @@ -329,10 +340,9 @@ lc_server_iface = R6::R6Class(
...,
parse_md = TRUE) {
if (parse_md) {
text = markdown::markdownToHTML(
text = markdown::mark_html(
text = text,
fragment.only = TRUE,
extensions = markdown::markdownExtensions()
template = FALSE
)
} else {
text = paste(text, collapse = "\n")
Expand Down Expand Up @@ -368,7 +378,9 @@ lc_server_iface = R6::R6Class(
start = function() {
private$server = file_stream_server(
private$ip, private$port, private$file, private$file_id,
template = private$template, interval = private$interval
template = private$template, interval = private$interval,
upgrade_content_security_policy =
private$upgrade_content_security_policy
)

usethis::ui_done( paste(
Expand Down Expand Up @@ -442,16 +454,20 @@ lc_server_iface = R6::R6Class(
#' @param bitly should a bitly bit link be created for the server.
#' @param auto_save should the broadcast file be auto saved during each update tic.
#' @param open_browser should a browser session be opened.
#' @param upgrade_content_security_policy should insecure requests be upgraded.
#'
#' @export

serve_file = function(file, ip, port, interval = 1,
bitly = FALSE, auto_save = TRUE,
open_browser = TRUE) {
open_browser = TRUE,
upgrade_content_security_policy = FALSE) {
server = lc_server_iface$new(file = file, ip = ip,
port = port, interval = interval,
bitly = bitly, auto_save = auto_save,
open_browser = open_browser)
open_browser = open_browser,
upgrade_content_security_policy =
upgrade_content_security_policy)

welcome_msg = c(
"## Welcome to `livecode`!",
Expand Down
2 changes: 2 additions & 0 deletions inst/templates/prism.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<head>
<title>{title}</title>

{meta}

<link href="web/progressbar/progressbar.css" rel="stylesheet" />
<script src="web/progressbar/progressbar.min.js"></script>

Expand Down
10 changes: 9 additions & 1 deletion man/file_stream_server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 28 additions & 25 deletions man/lc_server_iface.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/serve_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

using namespace Rcpp;

#ifdef RCPP_USE_GLOBAL_ROSTREAM
Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// get_ipv4
Rcpp::CharacterVector get_ipv4();
RcppExport SEXP _livecode_get_ipv4() {
Expand Down