mirror of
https://github.com/golang/go.git
synced 2025-05-29 03:11:26 +00:00
gofmt-ify hash, http
(gofmt will be able to re-align map entries as in http nicely, eventually) R=rsc http://go/go-review/1018055
This commit is contained in:
parent
b16e6ab148
commit
ca2a69ea06
@ -21,7 +21,7 @@ const (
|
||||
)
|
||||
|
||||
// The size of an Adler-32 checksum in bytes.
|
||||
const Size = 4;
|
||||
const Size = 4
|
||||
|
||||
// digest represents the partial evaluation of a checksum.
|
||||
type digest struct {
|
||||
@ -51,7 +51,7 @@ func update(a, b uint32, p []byte) (aa, bb uint32) {
|
||||
a += uint32(p[i]);
|
||||
b += a;
|
||||
// invariant: a <= b
|
||||
if b > (0xffffffff - 255) / 2 {
|
||||
if b > (0xffffffff - 255)/2 {
|
||||
a %= mod;
|
||||
b %= mod;
|
||||
// invariant: a < mod && b < mod
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
// TODO this should be in a mime package somewhere
|
||||
var contentByExt = map[string] string {
|
||||
var contentByExt = map[string]string{
|
||||
".css": "text/css",
|
||||
".gif": "image/gif",
|
||||
".html": "text/html; charset=utf-8",
|
||||
@ -57,12 +57,12 @@ func dirList(c *Conn, f *os.File) {
|
||||
for {
|
||||
dirs, err := f.Readdir(100);
|
||||
if err != nil || len(dirs) == 0 {
|
||||
break
|
||||
break;
|
||||
}
|
||||
for _, d := range dirs {
|
||||
name := d.Name;
|
||||
if d.IsDirectory() {
|
||||
name += "/"
|
||||
name += "/";
|
||||
}
|
||||
// TODO htmlescape
|
||||
fmt.Fprintf(c, "<a href=\"%s\">%s</a>\n", name, name);
|
||||
@ -76,9 +76,9 @@ func serveFileInternal(c *Conn, r *Request, name string, redirect bool) {
|
||||
const indexPage = "/index.html";
|
||||
|
||||
// redirect to strip off any index.html
|
||||
n := len(name) - len(indexPage);
|
||||
n := len(name)-len(indexPage);
|
||||
if n >= 0 && name[n:len(name)] == indexPage {
|
||||
Redirect(c, name[0:n+1], StatusMovedPermanently);
|
||||
Redirect(c, name[0 : n+1], StatusMovedPermanently);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -103,12 +103,12 @@ func serveFileInternal(c *Conn, r *Request, name string, redirect bool) {
|
||||
url := r.Url.Path;
|
||||
if d.IsDirectory() {
|
||||
if url[len(url)-1] != '/' {
|
||||
Redirect(c, url + "/", StatusMovedPermanently);
|
||||
Redirect(c, url+"/", StatusMovedPermanently);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if url[len(url)-1] == '/' {
|
||||
Redirect(c, url[0:len(url)-1], StatusMovedPermanently);
|
||||
Redirect(c, url[0 : len(url)-1], StatusMovedPermanently);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -181,4 +181,3 @@ func (f *fileHandler) ServeHTTP(c *Conn, r *Request) {
|
||||
path = path[len(f.prefix):len(path)];
|
||||
serveFileInternal(c, r, f.root + "/" + path, true);
|
||||
}
|
||||
|
||||
|
@ -112,6 +112,6 @@ func TestRedirect(t *testing.T) {
|
||||
}
|
||||
r.Body.Close();
|
||||
if r.StatusCode != 200 || url != end {
|
||||
t.Fatalf("Get(%s) got status %d at %s, want 200 at %s", start, r.StatusCode, url, end)
|
||||
t.Fatalf("Get(%s) got status %d at %s, want 200 at %s", start, r.StatusCode, url, end);
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ const (
|
||||
StatusHTTPVersionNotSupported = 505;
|
||||
)
|
||||
|
||||
var statusText = map[int]string {
|
||||
var statusText = map[int]string{
|
||||
StatusContinue: "Continue",
|
||||
StatusSwitchingProtocols: "Switching Protocols",
|
||||
|
||||
@ -98,4 +98,3 @@ var statusText = map[int]string {
|
||||
StatusGatewayTimeout: "Gateway Timeout",
|
||||
StatusHTTPVersionNotSupported: "HTTP Version Not Supported",
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ type URLTest struct {
|
||||
roundtrip string; // expected result of reserializing the URL; empty means same as "in".
|
||||
}
|
||||
|
||||
var urltests = []URLTest {
|
||||
var urltests = []URLTest{
|
||||
// no path
|
||||
URLTest{
|
||||
"http://www.google.com",
|
||||
@ -30,9 +30,9 @@ var urltests = []URLTest {
|
||||
"http://www.google.com",
|
||||
"http", "//www.google.com",
|
||||
"www.google.com", "", "www.google.com",
|
||||
"", "", ""
|
||||
"", "", "",
|
||||
},
|
||||
""
|
||||
"",
|
||||
},
|
||||
// path
|
||||
URLTest{
|
||||
@ -41,9 +41,9 @@ var urltests = []URLTest {
|
||||
"http://www.google.com/",
|
||||
"http", "//www.google.com/",
|
||||
"www.google.com", "", "www.google.com",
|
||||
"/", "", ""
|
||||
"/", "", "",
|
||||
},
|
||||
""
|
||||
"",
|
||||
},
|
||||
// path with hex escaping... note that space roundtrips to +
|
||||
URLTest{
|
||||
@ -52,9 +52,9 @@ var urltests = []URLTest {
|
||||
"http://www.google.com/file%20one%26two",
|
||||
"http", "//www.google.com/file%20one%26two",
|
||||
"www.google.com", "", "www.google.com",
|
||||
"/file one&two", "", ""
|
||||
"/file one&two", "", "",
|
||||
},
|
||||
"http://www.google.com/file+one%26two"
|
||||
"http://www.google.com/file+one%26two",
|
||||
},
|
||||
// user
|
||||
URLTest{
|
||||
@ -63,9 +63,9 @@ var urltests = []URLTest {
|
||||
"ftp://webmaster@www.google.com/",
|
||||
"ftp", "//webmaster@www.google.com/",
|
||||
"webmaster@www.google.com", "webmaster", "www.google.com",
|
||||
"/", "", ""
|
||||
"/", "", "",
|
||||
},
|
||||
""
|
||||
"",
|
||||
},
|
||||
// escape sequence in username
|
||||
URLTest{
|
||||
@ -74,9 +74,9 @@ var urltests = []URLTest {
|
||||
"ftp://john%20doe@www.google.com/",
|
||||
"ftp", "//john%20doe@www.google.com/",
|
||||
"john doe@www.google.com", "john doe", "www.google.com",
|
||||
"/", "", ""
|
||||
"/", "", "",
|
||||
},
|
||||
"ftp://john+doe@www.google.com/"
|
||||
"ftp://john+doe@www.google.com/",
|
||||
},
|
||||
// query
|
||||
URLTest{
|
||||
@ -85,9 +85,9 @@ var urltests = []URLTest {
|
||||
"http://www.google.com/?q=go+language",
|
||||
"http", "//www.google.com/?q=go+language",
|
||||
"www.google.com", "", "www.google.com",
|
||||
"/", "q=go+language", ""
|
||||
"/", "q=go+language", "",
|
||||
},
|
||||
""
|
||||
"",
|
||||
},
|
||||
// query with hex escaping: NOT parsed
|
||||
URLTest{
|
||||
@ -96,9 +96,9 @@ var urltests = []URLTest {
|
||||
"http://www.google.com/?q=go%20language",
|
||||
"http", "//www.google.com/?q=go%20language",
|
||||
"www.google.com", "", "www.google.com",
|
||||
"/", "q=go%20language", ""
|
||||
"/", "q=go%20language", "",
|
||||
},
|
||||
""
|
||||
"",
|
||||
},
|
||||
// path without /, so no query parsing
|
||||
URLTest{
|
||||
@ -107,9 +107,9 @@ var urltests = []URLTest {
|
||||
"http:www.google.com/?q=go+language",
|
||||
"http", "www.google.com/?q=go+language",
|
||||
"", "", "",
|
||||
"www.google.com/?q=go language", "", ""
|
||||
"www.google.com/?q=go language", "", "",
|
||||
},
|
||||
"http:www.google.com/%3fq%3dgo+language"
|
||||
"http:www.google.com/%3fq%3dgo+language",
|
||||
},
|
||||
// non-authority
|
||||
URLTest{
|
||||
@ -118,9 +118,9 @@ var urltests = []URLTest {
|
||||
"mailto:/webmaster@golang.org",
|
||||
"mailto", "/webmaster@golang.org",
|
||||
"", "", "",
|
||||
"/webmaster@golang.org", "", ""
|
||||
"/webmaster@golang.org", "", "",
|
||||
},
|
||||
""
|
||||
"",
|
||||
},
|
||||
// non-authority
|
||||
URLTest{
|
||||
@ -129,9 +129,9 @@ var urltests = []URLTest {
|
||||
"mailto:webmaster@golang.org",
|
||||
"mailto", "webmaster@golang.org",
|
||||
"", "", "",
|
||||
"webmaster@golang.org", "", ""
|
||||
"webmaster@golang.org", "", "",
|
||||
},
|
||||
""
|
||||
"",
|
||||
},
|
||||
// unescaped :// in query should not create a scheme
|
||||
URLTest{
|
||||
@ -140,35 +140,35 @@ var urltests = []URLTest {
|
||||
"/foo?query=http://bad",
|
||||
"", "/foo?query=http://bad",
|
||||
"", "", "",
|
||||
"/foo", "query=http://bad", ""
|
||||
"/foo", "query=http://bad", "",
|
||||
},
|
||||
""
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
var urlnofragtests = []URLTest {
|
||||
var urlnofragtests = []URLTest{
|
||||
URLTest{
|
||||
"http://www.google.com/?q=go+language#foo",
|
||||
&URL{
|
||||
"http://www.google.com/?q=go+language#foo",
|
||||
"http", "//www.google.com/?q=go+language#foo",
|
||||
"www.google.com", "", "www.google.com",
|
||||
"/", "q=go+language#foo", ""
|
||||
"/", "q=go+language#foo", "",
|
||||
},
|
||||
""
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
var urlfragtests = []URLTest {
|
||||
var urlfragtests = []URLTest{
|
||||
URLTest{
|
||||
"http://www.google.com/?q=go+language#foo",
|
||||
&URL{
|
||||
"http://www.google.com/?q=go+language",
|
||||
"http", "//www.google.com/?q=go+language",
|
||||
"www.google.com", "", "www.google.com",
|
||||
"/", "q=go+language", "foo"
|
||||
"/", "q=go+language", "foo",
|
||||
},
|
||||
""
|
||||
"",
|
||||
},
|
||||
URLTest{
|
||||
"http://www.google.com/?q=go+language#foo%26bar",
|
||||
@ -176,9 +176,9 @@ var urlfragtests = []URLTest {
|
||||
"http://www.google.com/?q=go+language",
|
||||
"http", "//www.google.com/?q=go+language",
|
||||
"www.google.com", "", "www.google.com",
|
||||
"/", "q=go+language", "foo&bar"
|
||||
"/", "q=go+language", "foo&bar",
|
||||
},
|
||||
""
|
||||
"",
|
||||
},
|
||||
}
|
||||
|
||||
@ -246,36 +246,36 @@ type URLEscapeTest struct {
|
||||
err os.Error;
|
||||
}
|
||||
|
||||
var unescapeTests = []URLEscapeTest {
|
||||
var unescapeTests = []URLEscapeTest{
|
||||
URLEscapeTest{
|
||||
"",
|
||||
"",
|
||||
nil
|
||||
nil,
|
||||
},
|
||||
URLEscapeTest{
|
||||
"abc",
|
||||
"abc",
|
||||
nil
|
||||
nil,
|
||||
},
|
||||
URLEscapeTest{
|
||||
"1%41",
|
||||
"1A",
|
||||
nil
|
||||
nil,
|
||||
},
|
||||
URLEscapeTest{
|
||||
"1%41%42%43",
|
||||
"1ABC",
|
||||
nil
|
||||
nil,
|
||||
},
|
||||
URLEscapeTest{
|
||||
"%4a",
|
||||
"J",
|
||||
nil
|
||||
nil,
|
||||
},
|
||||
URLEscapeTest{
|
||||
"%6F",
|
||||
"o",
|
||||
nil
|
||||
nil,
|
||||
},
|
||||
URLEscapeTest{
|
||||
"%", // not enough characters after %
|
||||
@ -313,31 +313,31 @@ func TestURLUnescape(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
var escapeTests = []URLEscapeTest {
|
||||
var escapeTests = []URLEscapeTest{
|
||||
URLEscapeTest{
|
||||
"",
|
||||
"",
|
||||
nil
|
||||
nil,
|
||||
},
|
||||
URLEscapeTest{
|
||||
"abc",
|
||||
"abc",
|
||||
nil
|
||||
nil,
|
||||
},
|
||||
URLEscapeTest{
|
||||
"one two",
|
||||
"one+two",
|
||||
nil
|
||||
nil,
|
||||
},
|
||||
URLEscapeTest{
|
||||
"10%",
|
||||
"10%25",
|
||||
nil
|
||||
nil,
|
||||
},
|
||||
URLEscapeTest{
|
||||
" ?&=#+%!",
|
||||
"+%3f%26%3d%23%2b%25!",
|
||||
nil
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
@ -355,4 +355,3 @@ func TestURLEscape(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user