diff --git a/dev-blobserver b/dev-blobserver index 2fc37ae6f..0b66c591d 100755 --- a/dev-blobserver +++ b/dev-blobserver @@ -15,7 +15,8 @@ GetOptions( "tls" => \$opt_tls, ) or usage(); -my $port = shift || "3179"; +my $port = shift; +$port = "3179" unless defined($port); usage() unless $port =~ /^\d+$/; system("./build.pl", "server/go/camlistored") and die "Failed to build.\n"; @@ -38,6 +39,6 @@ $ENV{CAMLI_TLS_CRT_FILE} = $opt_tls ? "$Bin/config/dev-tls.crt" : ""; $ENV{CAMLI_TLS_KEY_FILE} = $opt_tls ? "$Bin/config/dev-tls.key" : ""; exec("$FindBin::Bin/server/go/camlistored/camlistored", "-configfile=$Bin/config/dev-blobserver-config.json", - "-listen=:$port", + "-listen=127.0.0.1:$port", @ARGV); diff --git a/dev-server b/dev-server index 3b005cdd0..505c65ce8 100755 --- a/dev-server +++ b/dev-server @@ -12,7 +12,8 @@ my $opt_wipe; GetOptions("wipe" => \$opt_wipe) or usage(); -my $port = shift || "3202"; +my $port = shift; +$port = "3202" unless defined($port); usage() unless $port =~ /^\d+$/; system("./build.pl", "server/go/camlistored") and die "Failed to build camlistored"; @@ -51,5 +52,5 @@ $ENV{CAMLI_KEY_RING} = "$Bin/lib/go/camli/jsonsign/testdata/test-keyring.gpg"; $ENV{CAMLI_SECRET_RING} = "$Bin/lib/go/camli/jsonsign/testdata/test-secring.gpg"; exec("$FindBin::Bin/server/go/camlistored/camlistored", "-configfile=$Bin/config/dev-server-config.json", - "-listen=:$port", + "-listen=127.0.0.1:$port", @ARGV); diff --git a/lib/go/camli/webserver/webserver.go b/lib/go/camli/webserver/webserver.go index ffaae4141..a4c78b263 100644 --- a/lib/go/camli/webserver/webserver.go +++ b/lib/go/camli/webserver/webserver.go @@ -61,10 +61,13 @@ func (s *Server) BaseURL() string { if s.enableTLS { scheme = "https" } - if strings.HasPrefix(*Listen, ":") { - return scheme + "://127.0.0.1" + *Listen + if s.listener != nil { + return scheme + "://" + s.listener.Addr().String() } - return scheme + "://" + strings.Replace(*Listen, "0.0.0.0:", "127.0.0.1:", 1) + if strings.HasPrefix(*Listen, ":") { + return scheme + "://localhost" + *Listen + } + return scheme + "://" + strings.Replace(*Listen, "0.0.0.0:", "localhost:", 1) } // Register conditional handler-picker functions which get run before @@ -94,8 +97,10 @@ func (s *Server) ServeHTTP(rw http.ResponseWriter, req *http.Request) { } func (s *Server) Serve() { - if os.Getenv("TESTING_PORT_WRITE_FD") == "" { // Don't make noise during unit tests - log.Printf("Starting to listen on %s\n", s.BaseURL()) + doLog := os.Getenv("TESTING_PORT_WRITE_FD") == "" // Don't make noise during unit tests + base := s.BaseURL() + if doLog { + log.Printf("Starting to listen on %s\n", base) } var err os.Error @@ -104,6 +109,10 @@ func (s *Server) Serve() { log.Fatalf("Failed to listen on %s: %v", *Listen, err) } + if doLog && strings.HasSuffix(base, ":0") { + log.Printf("Now listening on %s\n", s.BaseURL()) + } + if s.enableTLS { config := &tls.Config{ Rand: rand.Reader,