docs: public @Nonnull String getRootUrlFromRequest() {
          StaplerRequest req = Stapler.getCurrentRequest();
          if (req == null) {
              throw new IllegalStateException("cannot call getRootUrlFromRequest from outside a request handling thread");
          }
          StringBuilder buf = new StringBuilder();
          String scheme = getXForwardedHeader(req, "X-Forwarded-Proto", req.getScheme());
          buf.append(scheme).append("://");
          String host = getXForwardedHeader(req, "X-Forwarded-Host", req.getServerName());
          int index = host.indexOf(':');
          int port = req.getServerPort();
          if (index == -1) {
              // Almost everyone else except Nginx put the host and port in separate headers
              buf.append(host);
          } else {
              // Nginx uses the same spec as for the Host header, i.e. hostname:port
              buf.append(host.substring(0, index));
              if (index + 1 < host.length()) {
                  try {
                      port = Integer.parseInt(host.substring(index + 1));
                  } catch (NumberFormatException e) {
                      // ignore
                  }
              }
              // but if a user has configured Nginx with an X-Forwarded-Port, that will win out.
          }
          String forwardedPort = getXForwardedHeader(req, "X-Forwarded-Port", null);
          if (forwardedPort != null) {
              try {
                  port = Integer.parseInt(forwardedPort);
              } catch (NumberFormatException e) {
                  // ignore
              }
          }
          if (port != ("https".equals(scheme) ? 443 : 80)) {
              buf.append(':').append(port);
          }
          buf.append(req.getContextPath()).append('/');
          return buf.toString();
      }