Skip to content

Commit

Permalink
modified rstudio to support ipv6
Browse files Browse the repository at this point in the history
  • Loading branch information
chaturvedikna authored and jiridanek committed Jan 21, 2025
1 parent 1833397 commit 9ce93ee
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ location = /rstudio {
location /rstudio/ {
rewrite ^/rstudio/(.*)$ /$1 break;
# Standard RStudio/NGINX configuration
proxy_pass http://127.0.0.1:8787;
proxy_pass http://localhost:8787;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ location = / {
location /rstudio/ {
rewrite ^/rstudio/(.*)$ /$1 break;
# Standard RStudio/NGINX configuration
proxy_pass http://127.0.0.1:8787;
proxy_pass http://localhost:8787;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
Expand Down
26 changes: 25 additions & 1 deletion rstudio/c9s-python-3.11/setup_rstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ def _support_arg(arg):
ret = subprocess.check_output([get_rstudio_executable('rserver'), '--help'])
return ret.decode().find(arg) != -1

def detect_env():
import socket
supports_ipv4 = supports_ipv6 = False
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('127.0.0.1', 0))
supports_ipv4 = True
except OSError:
pass
try:
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
s.bind(('::1', 0))
supports_ipv6 = True
except OSError:
pass
if supports_ipv4 and supports_ipv6:
return '::' # Dual-stack
elif supports_ipv6:
return '::'
elif supports_ipv4:
return '0.0.0.0'
else:
raise EnvironmentError('No IPv4 or IPv6 support detected.')

def _get_cmd(port):
ntf = tempfile.NamedTemporaryFile()

Expand All @@ -60,7 +84,7 @@ def _get_cmd(port):
'--server-working-dir=' + os.getenv('HOME'),
'--auth-none=1',
'--www-frame-origin=same',
#'--www-address=0.0.0.0',
'--www-address='+ detect_env(),
'--www-port=' + str(port),
'--www-verify-user-agent=0',
'--rsession-which-r=' + get_rstudio_executable('R'),
Expand Down

0 comments on commit 9ce93ee

Please sign in to comment.