Skip to content

Commit 78c13b1

Browse files
benz0lirenkun-ken
andauthored
Update vsc.R (#803)
* Update vsc.R * Modify url to allow proxied requests * Minor update * Fix message for webview Co-authored-by: Kun Ren <renkun@outlook.com>
1 parent f2bca32 commit 78c13b1

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

R/session/vsc.R

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,24 @@ request_browser <- function(url, title, ..., viewer) {
494494

495495
show_browser <- function(url, title = url, ...,
496496
viewer = getOption("vsc.browser", "Active")) {
497+
proxy_uri <- Sys.getenv("VSCODE_PROXY_URI")
498+
if (nzchar(proxy_uri)) {
499+
is_base_path <- grepl("\\:\\d+$", url)
500+
url <- sub("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:)?",
501+
sub("{port}", "", proxy_uri, fixed = TRUE), url)
502+
if (is_base_path) {
503+
url <- paste0(url, "/")
504+
}
505+
}
497506
if (grepl("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:\\d+)?", url)) {
498507
request_browser(url = url, title = title, ..., viewer = viewer)
499508
} else if (grepl("^https?\\://", url)) {
500509
message(
501-
"VSCode WebView only supports showing local http content.\n",
510+
if (nzchar(proxy_uri)) {
511+
"VSCode is not running on localhost but on a remote server.\n"
512+
} else {
513+
"VSCode WebView only supports showing local http content.\n"
514+
},
502515
"Opening in external browser..."
503516
)
504517
request_browser(url = url, title = title, ..., viewer = FALSE)
@@ -535,11 +548,24 @@ show_webview <- function(url, title, ..., viewer) {
535548
stop("Invalid object")
536549
}
537550
}
551+
proxy_uri <- Sys.getenv("VSCODE_PROXY_URI")
552+
if (nzchar(proxy_uri)) {
553+
is_base_path <- grepl("\\:\\d+$", url)
554+
url <- sub("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:)?",
555+
sub("{port}", "", proxy_uri, fixed = TRUE), url)
556+
if (is_base_path) {
557+
url <- paste0(url, "/")
558+
}
559+
}
538560
if (grepl("^https?\\://(127\\.0\\.0\\.1|localhost)(\\:\\d+)?", url)) {
539561
request_browser(url = url, title = title, ..., viewer = viewer)
540562
} else if (grepl("^https?\\://", url)) {
541563
message(
542-
"VSCode WebView only supports showing local http content.\n",
564+
if (nzchar(proxy_uri)) {
565+
"VSCode is not running on localhost but on a remote server.\n"
566+
} else {
567+
"VSCode WebView only supports showing local http content.\n"
568+
},
543569
"Opening in external browser..."
544570
)
545571
request_browser(url = url, title = title, ..., viewer = FALSE)

0 commit comments

Comments
 (0)