From 6bd8cc3aba040d3eff842f07d03a76583d678b83 Mon Sep 17 00:00:00 2001 From: Olivier Benz Date: Wed, 29 Sep 2021 08:23:09 +0200 Subject: [PATCH 1/3] Update vsc.R * Modify url to allow proxied requests --- R/session/vsc.R | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/R/session/vsc.R b/R/session/vsc.R index cc1728664..ad7ae2e77 100644 --- a/R/session/vsc.R +++ b/R/session/vsc.R @@ -494,11 +494,23 @@ request_browser <- function(url, title, ..., viewer) { show_browser <- function(url, title = url, ..., viewer = getOption("vsc.browser", "Active")) { + if (nzchar(Sys.getenv("VSCODE_PROXY_URI"))) { + is.base_path <- grepl("\\:\\d+$", url) + url <- sub("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:)?", + sub("\\{port\\}", "", Sys.getenv("VSCODE_PROXY_URI")), url) + if (is.base_path) { + url <- paste0(url, "/") + } + } if (grepl("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:\\d+)?", url)) { request_browser(url = url, title = title, ..., viewer = viewer) } else if (grepl("^https?\\://", url)) { message( - "VSCode WebView only supports showing local http content.\n", + if (nzchar(Sys.getenv("VSCODE_PROXY_URI"))) { + "VSCode is not running on localhost but on a remote server.\n" + } else { + "VSCode WebView only supports showing local http content.\n" + }, "Opening in external browser..." ) request_browser(url = url, title = title, ..., viewer = FALSE) @@ -535,11 +547,23 @@ show_webview <- function(url, title, ..., viewer) { stop("Invalid object") } } + if (nzchar(Sys.getenv("VSCODE_PROXY_URI"))) { + is.base_path <- grepl("\\:\\d+$", url) + url <- sub("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:)?", + sub("\\{port\\}", "", Sys.getenv("VSCODE_PROXY_URI")), url) + if (is.base_path) { + url <- paste0(url, "/") + } + } if (grepl("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:\\d+)?", url)) { request_browser(url = url, title = title, ..., viewer = viewer) } else if (grepl("^https?\\://", url)) { message( - "VSCode WebView only supports showing local http content.\n", + if (nzchar(Sys.getenv("VSCODE_PROXY_URI"))) { + "VSCode WebView only supports showing local http content.\n" + } else { + "VSCode WebView only supports showing local http content.\n" + }, "Opening in external browser..." ) request_browser(url = url, title = title, ..., viewer = FALSE) From 9449e3ec6f71a19966046977bcfd9ac6ede2dede Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Wed, 29 Sep 2021 15:49:57 +0800 Subject: [PATCH 2/3] Minor update --- R/session/vsc.R | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/R/session/vsc.R b/R/session/vsc.R index ad7ae2e77..925e62bbe 100644 --- a/R/session/vsc.R +++ b/R/session/vsc.R @@ -494,11 +494,12 @@ request_browser <- function(url, title, ..., viewer) { show_browser <- function(url, title = url, ..., viewer = getOption("vsc.browser", "Active")) { - if (nzchar(Sys.getenv("VSCODE_PROXY_URI"))) { - is.base_path <- grepl("\\:\\d+$", url) + proxy_uri <- Sys.getenv("VSCODE_PROXY_URI") + if (nzchar(proxy_uri)) { + is_base_path <- grepl("\\:\\d+$", url) url <- sub("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:)?", - sub("\\{port\\}", "", Sys.getenv("VSCODE_PROXY_URI")), url) - if (is.base_path) { + sub("{port}", "", proxy_uri, fixed = TRUE), url) + if (is_base_path) { url <- paste0(url, "/") } } @@ -506,7 +507,7 @@ show_browser <- function(url, title = url, ..., request_browser(url = url, title = title, ..., viewer = viewer) } else if (grepl("^https?\\://", url)) { message( - if (nzchar(Sys.getenv("VSCODE_PROXY_URI"))) { + if (nzchar(proxy_uri)) { "VSCode is not running on localhost but on a remote server.\n" } else { "VSCode WebView only supports showing local http content.\n" @@ -547,11 +548,12 @@ show_webview <- function(url, title, ..., viewer) { stop("Invalid object") } } - if (nzchar(Sys.getenv("VSCODE_PROXY_URI"))) { - is.base_path <- grepl("\\:\\d+$", url) + proxy_uri <- Sys.getenv("VSCODE_PROXY_URI") + if (nzchar(proxy_uri)) { + is_base_path <- grepl("\\:\\d+$", url) url <- sub("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:)?", - sub("\\{port\\}", "", Sys.getenv("VSCODE_PROXY_URI")), url) - if (is.base_path) { + sub("{port}", "", proxy_uri, fixed = TRUE), url) + if (is_base_path) { url <- paste0(url, "/") } } @@ -559,7 +561,7 @@ show_webview <- function(url, title, ..., viewer) { request_browser(url = url, title = title, ..., viewer = viewer) } else if (grepl("^https?\\://", url)) { message( - if (nzchar(Sys.getenv("VSCODE_PROXY_URI"))) { + if (nzchar(proxy_uri)) { "VSCode WebView only supports showing local http content.\n" } else { "VSCode WebView only supports showing local http content.\n" From b2c18a3d5bc656a1c482c37cbddb75dca8808c46 Mon Sep 17 00:00:00 2001 From: Olivier Benz Date: Wed, 29 Sep 2021 10:00:36 +0200 Subject: [PATCH 3/3] Fix message for webview --- R/session/vsc.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/session/vsc.R b/R/session/vsc.R index 925e62bbe..f2c4c1ed0 100644 --- a/R/session/vsc.R +++ b/R/session/vsc.R @@ -562,7 +562,7 @@ show_webview <- function(url, title, ..., viewer) { } else if (grepl("^https?\\://", url)) { message( if (nzchar(proxy_uri)) { - "VSCode WebView only supports showing local http content.\n" + "VSCode is not running on localhost but on a remote server.\n" } else { "VSCode WebView only supports showing local http content.\n" },