Skip to content

Commit 4a84f57

Browse files
committed
Update example a bit
1 parent 5ab9999 commit 4a84f57

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

README.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,47 @@
33
Simple container with SOCKS proxy server running behind sockify, to connect from WebAssembly.
44

55

6-
## Test with a public proxy server
6+
## Minimal example with a public proxy server
77

88
Open the WebR test app on https://webr.r-wasm.org/latest/ run some code to test:
99

10-
1110
```r
12-
# This routes all traffic over a public proxy server!
13-
Sys.setenv(ALL_PROXY="socks5h://test:yolo@ws.opencpu.org:443")
14-
11+
# Install packages
1512
install.packages("curl")
16-
library(curl)
1713

18-
example(curl_fetch_memory)
14+
# Make a request via the public server server!
15+
Sys.setenv(ALL_PROXY="socks5h://test:yolo@ws.r-universe.dev:443")
16+
req <- curl::curl_fetch_memory('https://hb.cran.dev/get')
17+
cat(rawToChar(req$content))
1918
```
2019

2120
The `ALL_PROXY` variable will make libcurl route all traffic via this proxy server.
2221

23-
The server `ws.opencpu.org` is running exactly the same service from this container, but behind cloudflare to get improved routing and proper https certificates.
22+
The server `ws.r-universe.dev` is running exactly the same service from this container, but behind cloudflare to get improved routing and proper https certificates.
23+
24+
## Testing many requests in parallel
25+
26+
The following code downloads 500 small text files in parallel over HTTP/2 to your home dir with verbosity turned on.
27+
28+
```r
29+
install.packages('curl')
30+
Sys.setenv(ALL_PROXY='socks5h://test:yolo@ws.opencpu.org:443')
31+
mirror <- 'https://cran.rstudio.com'
32+
df <- read.dcf(curl::curl(sprintf('%s/src/contrib/PACKAGES', mirror)))
33+
pkgs <- df[1:500,'Package']
34+
urls <- sprintf('%s/web/packages/%s/DESCRIPTION', mirror, pkgs)
35+
destfiles <- sprintf('~/%s.txt', pkgs)
36+
results <- curl::multi_download(urls, destfiles, progress = FALSE, multiplex = TRUE, verbose=TRUE)
37+
all(results$status == 200)
38+
39+
# Read one of the files to show it is there
40+
list.files('~')
41+
readLines("~/abc.txt")
42+
```
2443

44+
If you run this in https://webr.r-wasm.org/latest/ you can also the file in the WebUI under `/home/web_user`.
2545

26-
## Test with a local proxy server
46+
## Test a local proxy server
2747

2848
On your local machine start the proxy server with:
2949

@@ -34,14 +54,14 @@ docker run -it -p7777:7777 ghcr.io/r-wasm/ws-proxy
3454
Now open the WebR test app on https://webr.r-wasm.org/latest/ run this code to test:
3555

3656
```r
37-
# Need to use non-https ws:// for local testing
57+
# Need to use non-https ws:// for local testing!
3858
webr::eval_js("SOCKFS.websocketArgs.url = 'ws://'")
39-
Sys.setenv(ALL_PROXY="socks5h://test:yolo@localhost:7777")
4059

60+
# Same as before, but with localhost
61+
Sys.setenv(ALL_PROXY="socks5h://test:yolo@localhost:7777")
4162
install.packages("curl")
42-
library(curl)
43-
44-
example(curl_fetch_memory)
63+
req <- curl::curl_fetch_memory('https://hb.cran.dev/get')
64+
cat(rawToChar(req$content))
4565
```
4666

4767
You should be able to see the proxy traffic in the docker terminal session.

0 commit comments

Comments
 (0)