From 3e4da983ee08ba5a638113864f5f12f360c84c80 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Tue, 16 Nov 2021 12:36:20 -0600 Subject: [PATCH] default options(servr.test.0.0.0.0 = TRUE), i.e., test the availability of a port on both 127.0.0.1 and 0.0.0.0 by default --- DESCRIPTION | 2 +- NEWS.md | 1 + R/utils.R | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 331eff0..2ce7a69 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: servr Type: Package Title: A Simple HTTP Server to Serve Static Files or Dynamic Documents -Version: 0.23.2 +Version: 0.23.3 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), person("Carson", "Sievert", role = "ctb"), diff --git a/NEWS.md b/NEWS.md index 924edff..384dd0d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # CHANGES IN servr VERSION 0.24 +- When searching for an available random port via `servr::random_port()` on the host `127.0.0.1`, the availability of the port is also tested on `0.0.0.0` by default. This is to avoid the situation where a port has been used on `0.0.0.0` but **httpuv** still thinks it is available on `127.0.0.1`. If you want to skip this additional testing, you may set `options(servr.test.0.0.0.0 = FALSE)`. # CHANGES IN servr VERSION 0.23 diff --git a/R/utils.R b/R/utils.R index 63c6268..26768e4 100644 --- a/R/utils.R +++ b/R/utils.R @@ -180,7 +180,7 @@ random_port = function(port = 4321L, host = getOption('servr.host', '127.0.0.1') # when the same port is tested on 127.0.0.1, which might be a bug of httpuv; # so we provide an option to test the availability of a port on 0.0.0.0 when # we intend to serve a site on 127.0.0.1 - test0 = host == '127.0.0.1' && getOption('servr.test.0.0.0.0', FALSE) + test0 = host == '127.0.0.1' && getOption('servr.test.0.0.0.0', TRUE) for (p in ports) if (port_available(p, host) && (!test0 || port_available(p, '0.0.0.0'))) { port = p break