Advertise the dev server password in the realm.

This commit is contained in:
Brad Fitzpatrick 2011-06-09 16:09:21 -07:00
parent 05dac3405c
commit bdfde0a5fe
2 changed files with 7 additions and 2 deletions

View File

@ -65,6 +65,7 @@ print "Starting dev server on $base/ui/ with password \"pass$port\"\n";
$ENV{CAMLI_BASEURL} = $base;
$ENV{CAMLI_PASSWORD} = "pass$port";
$ENV{CAMLI_ADVERTISED_PASSWORD} = "pass$port"; # public password
$ENV{CAMLI_ROOT} = $suffixdir->("bs");
$ENV{CAMLI_ROOT_SHARD1} = $suffixdir->("s1");
$ENV{CAMLI_ROOT_SHARD2} = $suffixdir->("s2");

View File

@ -20,6 +20,7 @@ import (
"encoding/base64"
"fmt"
"http"
"os"
"regexp"
"strings"
)
@ -64,8 +65,11 @@ func IsAuthorized(req *http.Request) bool {
func RequireAuth(handler func(conn http.ResponseWriter, req *http.Request)) func (conn http.ResponseWriter, req *http.Request) {
return func (conn http.ResponseWriter, req *http.Request) {
if !IsAuthorized(req) {
req.Body.Close() // http://code.google.com/p/go/issues/detail?id=1306
conn.Header().Set("WWW-Authenticate", "Basic realm=\"camlistored\"")
realm := "camlistored"
if pw := os.Getenv("CAMLI_ADVERTISED_PASSWORD"); pw != "" {
realm = "Any username, password is: " + pw
}
conn.Header().Set("WWW-Authenticate", fmt.Sprintf("Basic realm=%q", realm))
conn.WriteHeader(http.StatusUnauthorized)
fmt.Fprintf(conn, "Authentication required.\n")
return