mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
a nagging inconsistency: capitalization of
HTML vs Html, URL vs Url, HTTP vs Http, current source is 6:1 in favor of the former, so change instances of the latter. R=r CC=go-dev http://go/go-review/1024026
This commit is contained in:
parent
830813f019
commit
ed6eb5b577
13 changed files with 97 additions and 97 deletions
|
|
@ -131,7 +131,7 @@ func pkgName(filename string) string {
|
||||||
|
|
||||||
func htmlEscape(s string) string {
|
func htmlEscape(s string) string {
|
||||||
var buf bytes.Buffer;
|
var buf bytes.Buffer;
|
||||||
template.HtmlEscape(&buf, strings.Bytes(s));
|
template.HTMLEscape(&buf, strings.Bytes(s));
|
||||||
return buf.String();
|
return buf.String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -460,37 +460,37 @@ type Styler struct {
|
||||||
var defaultStyler Styler
|
var defaultStyler Styler
|
||||||
|
|
||||||
|
|
||||||
func (s *Styler) LineTag(line int) (text []byte, tag printer.HtmlTag) {
|
func (s *Styler) LineTag(line int) (text []byte, tag printer.HTMLTag) {
|
||||||
tag = printer.HtmlTag{fmt.Sprintf(`<a id="L%d">`, line), "</a>"};
|
tag = printer.HTMLTag{fmt.Sprintf(`<a id="L%d">`, line), "</a>"};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *Styler) Comment(c *ast.Comment, line []byte) (text []byte, tag printer.HtmlTag) {
|
func (s *Styler) Comment(c *ast.Comment, line []byte) (text []byte, tag printer.HTMLTag) {
|
||||||
text = line;
|
text = line;
|
||||||
// minimal syntax-coloring of comments for now - people will want more
|
// minimal syntax-coloring of comments for now - people will want more
|
||||||
// (don't do anything more until there's a button to turn it on/off)
|
// (don't do anything more until there's a button to turn it on/off)
|
||||||
tag = printer.HtmlTag{`<span class="comment">`, "</span>"};
|
tag = printer.HTMLTag{`<span class="comment">`, "</span>"};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *Styler) BasicLit(x *ast.BasicLit) (text []byte, tag printer.HtmlTag) {
|
func (s *Styler) BasicLit(x *ast.BasicLit) (text []byte, tag printer.HTMLTag) {
|
||||||
text = x.Value;
|
text = x.Value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *Styler) Ident(id *ast.Ident) (text []byte, tag printer.HtmlTag) {
|
func (s *Styler) Ident(id *ast.Ident) (text []byte, tag printer.HTMLTag) {
|
||||||
text = strings.Bytes(id.Value);
|
text = strings.Bytes(id.Value);
|
||||||
if s.highlight == id.Value {
|
if s.highlight == id.Value {
|
||||||
tag = printer.HtmlTag{"<span class=highlight>", "</span>"};
|
tag = printer.HTMLTag{"<span class=highlight>", "</span>"};
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *Styler) Token(tok token.Token) (text []byte, tag printer.HtmlTag) {
|
func (s *Styler) Token(tok token.Token) (text []byte, tag printer.HTMLTag) {
|
||||||
text = strings.Bytes(tok.String());
|
text = strings.Bytes(tok.String());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -512,7 +512,7 @@ func writeNode(w io.Writer, node interface{}, html bool, styler printer.Styler)
|
||||||
// Write text to w; optionally html-escaped.
|
// Write text to w; optionally html-escaped.
|
||||||
func writeText(w io.Writer, text []byte, html bool) {
|
func writeText(w io.Writer, text []byte, html bool) {
|
||||||
if html {
|
if html {
|
||||||
template.HtmlEscape(w, text);
|
template.HTMLEscape(w, text);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
w.Write(text);
|
w.Write(text);
|
||||||
|
|
@ -552,7 +552,7 @@ func htmlFmt(w io.Writer, x interface{}, format string) {
|
||||||
func htmlCommentFmt(w io.Writer, x interface{}, format string) {
|
func htmlCommentFmt(w io.Writer, x interface{}, format string) {
|
||||||
var buf bytes.Buffer;
|
var buf bytes.Buffer;
|
||||||
writeAny(&buf, x, false);
|
writeAny(&buf, x, false);
|
||||||
doc.ToHtml(w, buf.Bytes()); // does html-escaping
|
doc.ToHTML(w, buf.Bytes()); // does html-escaping
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -651,7 +651,7 @@ func paddingFmt(w io.Writer, x interface{}, format string) {
|
||||||
// Template formatter for "time" format.
|
// Template formatter for "time" format.
|
||||||
func timeFmt(w io.Writer, x interface{}, format string) {
|
func timeFmt(w io.Writer, x interface{}, format string) {
|
||||||
// note: os.Dir.Mtime_ns is in uint64 in ns!
|
// note: os.Dir.Mtime_ns is in uint64 in ns!
|
||||||
template.HtmlEscape(w, strings.Bytes(time.SecondsToLocalTime(int64(x.(uint64) / 1e9)).String()));
|
template.HTMLEscape(w, strings.Bytes(time.SecondsToLocalTime(int64(x.(uint64) / 1e9)).String()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -684,25 +684,25 @@ func readTemplate(name string) *template.Template {
|
||||||
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dirlistHtml,
|
dirlistHTML,
|
||||||
godocHtml,
|
godocHTML,
|
||||||
packageHtml,
|
packageHTML,
|
||||||
packageText,
|
packageText,
|
||||||
parseerrorHtml,
|
parseerrorHTML,
|
||||||
parseerrorText,
|
parseerrorText,
|
||||||
searchHtml *template.Template;
|
searchHTML *template.Template;
|
||||||
)
|
)
|
||||||
|
|
||||||
func readTemplates() {
|
func readTemplates() {
|
||||||
// have to delay until after flags processing,
|
// have to delay until after flags processing,
|
||||||
// so that main has chdir'ed to goroot.
|
// so that main has chdir'ed to goroot.
|
||||||
dirlistHtml = readTemplate("dirlist.html");
|
dirlistHTML = readTemplate("dirlist.html");
|
||||||
godocHtml = readTemplate("godoc.html");
|
godocHTML = readTemplate("godoc.html");
|
||||||
packageHtml = readTemplate("package.html");
|
packageHTML = readTemplate("package.html");
|
||||||
packageText = readTemplate("package.txt");
|
packageText = readTemplate("package.txt");
|
||||||
parseerrorHtml = readTemplate("parseerror.html");
|
parseerrorHTML = readTemplate("parseerror.html");
|
||||||
parseerrorText = readTemplate("parseerror.txt");
|
parseerrorText = readTemplate("parseerror.txt");
|
||||||
searchHtml = readTemplate("search.html");
|
searchHTML = readTemplate("search.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -725,8 +725,8 @@ func servePage(c *http.Conn, title, query string, content []byte) {
|
||||||
Content: content,
|
Content: content,
|
||||||
};
|
};
|
||||||
|
|
||||||
if err := godocHtml.Execute(&d, c); err != nil {
|
if err := godocHTML.Execute(&d, c); err != nil {
|
||||||
log.Stderrf("godocHtml.Execute: %s", err);
|
log.Stderrf("godocHTML.Execute: %s", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -756,7 +756,7 @@ func commentText(src []byte) (text string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func serveHtmlDoc(c *http.Conn, r *http.Request, path string) {
|
func serveHTMLDoc(c *http.Conn, r *http.Request, path string) {
|
||||||
// get HTML body contents
|
// get HTML body contents
|
||||||
src, err := io.ReadFile(path);
|
src, err := io.ReadFile(path);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -780,8 +780,8 @@ func serveHtmlDoc(c *http.Conn, r *http.Request, path string) {
|
||||||
func serveParseErrors(c *http.Conn, errors *parseErrors) {
|
func serveParseErrors(c *http.Conn, errors *parseErrors) {
|
||||||
// format errors
|
// format errors
|
||||||
var buf bytes.Buffer;
|
var buf bytes.Buffer;
|
||||||
if err := parseerrorHtml.Execute(errors, &buf); err != nil {
|
if err := parseerrorHTML.Execute(errors, &buf); err != nil {
|
||||||
log.Stderrf("parseerrorHtml.Execute: %s", err);
|
log.Stderrf("parseerrorHTML.Execute: %s", err);
|
||||||
}
|
}
|
||||||
servePage(c, "Parse errors in source file " + errors.filename, "", buf.Bytes());
|
servePage(c, "Parse errors in source file " + errors.filename, "", buf.Bytes());
|
||||||
}
|
}
|
||||||
|
|
@ -799,12 +799,12 @@ func serveGoSource(c *http.Conn, r *http.Request, path string, styler printer.St
|
||||||
writeNode(&buf, prog, true, styler);
|
writeNode(&buf, prog, true, styler);
|
||||||
fmt.Fprintln(&buf, "</pre>");
|
fmt.Fprintln(&buf, "</pre>");
|
||||||
|
|
||||||
servePage(c, "Source file " + r.Url.Path, "", buf.Bytes());
|
servePage(c, "Source file " + r.URL.Path, "", buf.Bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func redirect(c *http.Conn, r *http.Request) (redirected bool) {
|
func redirect(c *http.Conn, r *http.Request) (redirected bool) {
|
||||||
if canonical := pathutil.Clean(r.Url.Path) + "/"; r.Url.Path != canonical {
|
if canonical := pathutil.Clean(r.URL.Path) + "/"; r.URL.Path != canonical {
|
||||||
http.Redirect(c, canonical, http.StatusMovedPermanently);
|
http.Redirect(c, canonical, http.StatusMovedPermanently);
|
||||||
redirected = true;
|
redirected = true;
|
||||||
}
|
}
|
||||||
|
|
@ -866,7 +866,7 @@ func serveTextFile(c *http.Conn, r *http.Request, path string) {
|
||||||
|
|
||||||
var buf bytes.Buffer;
|
var buf bytes.Buffer;
|
||||||
fmt.Fprintln(&buf, "<pre>");
|
fmt.Fprintln(&buf, "<pre>");
|
||||||
template.HtmlEscape(&buf, src);
|
template.HTMLEscape(&buf, src);
|
||||||
fmt.Fprintln(&buf, "</pre>");
|
fmt.Fprintln(&buf, "</pre>");
|
||||||
|
|
||||||
servePage(c, "Text file " + path, "", buf.Bytes());
|
servePage(c, "Text file " + path, "", buf.Bytes());
|
||||||
|
|
@ -885,8 +885,8 @@ func serveDirectory(c *http.Conn, r *http.Request, path string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer;
|
var buf bytes.Buffer;
|
||||||
if err := dirlistHtml.Execute(list, &buf); err != nil {
|
if err := dirlistHTML.Execute(list, &buf); err != nil {
|
||||||
log.Stderrf("dirlistHtml.Execute: %s", err);
|
log.Stderrf("dirlistHTML.Execute: %s", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
servePage(c, "Directory " + path, "", buf.Bytes());
|
servePage(c, "Directory " + path, "", buf.Bytes());
|
||||||
|
|
@ -896,21 +896,21 @@ func serveDirectory(c *http.Conn, r *http.Request, path string) {
|
||||||
var fileServer = http.FileServer(".", "")
|
var fileServer = http.FileServer(".", "")
|
||||||
|
|
||||||
func serveFile(c *http.Conn, r *http.Request) {
|
func serveFile(c *http.Conn, r *http.Request) {
|
||||||
path := pathutil.Join(".", r.Url.Path);
|
path := pathutil.Join(".", r.URL.Path);
|
||||||
|
|
||||||
// pick off special cases and hand the rest to the standard file server
|
// pick off special cases and hand the rest to the standard file server
|
||||||
switch ext := pathutil.Ext(path); {
|
switch ext := pathutil.Ext(path); {
|
||||||
case r.Url.Path == "/":
|
case r.URL.Path == "/":
|
||||||
serveHtmlDoc(c, r, "doc/root.html");
|
serveHTMLDoc(c, r, "doc/root.html");
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case r.Url.Path == "/doc/root.html":
|
case r.URL.Path == "/doc/root.html":
|
||||||
// hide landing page from its real name
|
// hide landing page from its real name
|
||||||
http.NotFound(c, r);
|
http.NotFound(c, r);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case ext == ".html":
|
case ext == ".html":
|
||||||
serveHtmlDoc(c, r, path);
|
serveHTMLDoc(c, r, path);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case ext == ".go":
|
case ext == ".go":
|
||||||
|
|
@ -1023,7 +1023,7 @@ func (h *httpHandler) ServeHTTP(c *http.Conn, r *http.Request) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
path := r.Url.Path;
|
path := r.URL.Path;
|
||||||
path = path[len(h.pattern):len(path)];
|
path = path[len(h.pattern):len(path)];
|
||||||
info := h.getPageInfo(path);
|
info := h.getPageInfo(path);
|
||||||
|
|
||||||
|
|
@ -1036,8 +1036,8 @@ func (h *httpHandler) ServeHTTP(c *http.Conn, r *http.Request) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := packageHtml.Execute(info, &buf); err != nil {
|
if err := packageHTML.Execute(info, &buf); err != nil {
|
||||||
log.Stderrf("packageHtml.Execute: %s", err);
|
log.Stderrf("packageHTML.Execute: %s", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if path == "" {
|
if path == "" {
|
||||||
|
|
@ -1085,8 +1085,8 @@ func search(c *http.Conn, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer;
|
var buf bytes.Buffer;
|
||||||
if err := searchHtml.Execute(result, &buf); err != nil {
|
if err := searchHTML.Execute(result, &buf); err != nil {
|
||||||
log.Stderrf("searchHtml.Execute: %s", err);
|
log.Stderrf("searchHTML.Execute: %s", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
var title string;
|
var title string;
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ func usage() {
|
||||||
|
|
||||||
func loggingHandler(h http.Handler) http.Handler {
|
func loggingHandler(h http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(c *http.Conn, req *http.Request) {
|
return http.HandlerFunc(func(c *http.Conn, req *http.Request) {
|
||||||
log.Stderrf("%s\t%s", c.RemoteAddr, req.Url);
|
log.Stderrf("%s\t%s", c.RemoteAddr, req.URL);
|
||||||
h.ServeHTTP(c, req);
|
h.ServeHTTP(c, req);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -162,7 +162,7 @@ func main() {
|
||||||
readTemplates();
|
readTemplates();
|
||||||
|
|
||||||
if *httpaddr != "" {
|
if *httpaddr != "" {
|
||||||
// Http server mode.
|
// HTTP server mode.
|
||||||
var handler http.Handler = http.DefaultServeMux;
|
var handler http.Handler = http.DefaultServeMux;
|
||||||
if *verbose {
|
if *verbose {
|
||||||
log.Stderrf("Go Documentation Server\n");
|
log.Stderrf("Go Documentation Server\n");
|
||||||
|
|
@ -218,8 +218,8 @@ func main() {
|
||||||
|
|
||||||
// Command line mode.
|
// Command line mode.
|
||||||
if *html {
|
if *html {
|
||||||
packageText = packageHtml;
|
packageText = packageHTML;
|
||||||
parseerrorText = parseerrorHtml;
|
parseerrorText = parseerrorHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
info := pkgHandler.getPageInfo(flag.Arg(0));
|
info := pkgHandler.getPageInfo(flag.Arg(0));
|
||||||
|
|
|
||||||
|
|
@ -30,15 +30,15 @@ type snippetStyler struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *snippetStyler) LineTag(line int) (text []uint8, tag printer.HtmlTag) {
|
func (s *snippetStyler) LineTag(line int) (text []uint8, tag printer.HTMLTag) {
|
||||||
return; // no LineTag for snippets
|
return; // no LineTag for snippets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (s *snippetStyler) Ident(id *ast.Ident) (text []byte, tag printer.HtmlTag) {
|
func (s *snippetStyler) Ident(id *ast.Ident) (text []byte, tag printer.HTMLTag) {
|
||||||
text = strings.Bytes(id.Value);
|
text = strings.Bytes(id.Value);
|
||||||
if s.highlight == id {
|
if s.highlight == id {
|
||||||
tag = printer.HtmlTag{"<span class=highlight>", "</span>"};
|
tag = printer.HTMLTag{"<span class=highlight>", "</span>"};
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -214,7 +214,7 @@ func (p *printer) writeFormfeeds(n int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (p *printer) writeTaggedItem(data []byte, tag HtmlTag) {
|
func (p *printer) writeTaggedItem(data []byte, tag HTMLTag) {
|
||||||
// write start tag, if any
|
// write start tag, if any
|
||||||
// (no html-escaping and no p.pos update for tags - use write0)
|
// (no html-escaping and no p.pos update for tags - use write0)
|
||||||
if tag.Start != "" {
|
if tag.Start != "" {
|
||||||
|
|
@ -235,7 +235,7 @@ func (p *printer) writeTaggedItem(data []byte, tag HtmlTag) {
|
||||||
// before and after the data. writeItem updates p.last to the position
|
// before and after the data. writeItem updates p.last to the position
|
||||||
// immediately following the data.
|
// immediately following the data.
|
||||||
//
|
//
|
||||||
func (p *printer) writeItem(pos token.Position, data []byte, tag HtmlTag) {
|
func (p *printer) writeItem(pos token.Position, data []byte, tag HTMLTag) {
|
||||||
p.pos = pos;
|
p.pos = pos;
|
||||||
if debug {
|
if debug {
|
||||||
// do not update p.pos - use write0
|
// do not update p.pos - use write0
|
||||||
|
|
@ -357,7 +357,7 @@ func (p *printer) writeCommentLine(comment *ast.Comment, pos token.Position, lin
|
||||||
line = bytes.Join([][]byte{esc, line, esc}, nil);
|
line = bytes.Join([][]byte{esc, line, esc}, nil);
|
||||||
|
|
||||||
// apply styler, if any
|
// apply styler, if any
|
||||||
var tag HtmlTag;
|
var tag HTMLTag;
|
||||||
if p.Styler != nil {
|
if p.Styler != nil {
|
||||||
line, tag = p.Styler.Comment(comment, line);
|
line, tag = p.Styler.Comment(comment, line);
|
||||||
}
|
}
|
||||||
|
|
@ -696,7 +696,7 @@ func (p *printer) print(args ...) {
|
||||||
|
|
||||||
next := p.pos; // estimated position of next item
|
next := p.pos; // estimated position of next item
|
||||||
var data []byte;
|
var data []byte;
|
||||||
var tag HtmlTag;
|
var tag HTMLTag;
|
||||||
isKeyword := false;
|
isKeyword := false;
|
||||||
switch x := f.Interface().(type) {
|
switch x := f.Interface().(type) {
|
||||||
case whiteSpace:
|
case whiteSpace:
|
||||||
|
|
@ -890,8 +890,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// An HtmlTag specifies a start and end tag.
|
// An HTMLTag specifies a start and end tag.
|
||||||
type HtmlTag struct {
|
type HTMLTag struct {
|
||||||
Start, End string; // empty if tags are absent
|
Start, End string; // empty if tags are absent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -900,11 +900,11 @@ type HtmlTag struct {
|
||||||
// A format consists of text and a (possibly empty) surrounding HTML tag.
|
// A format consists of text and a (possibly empty) surrounding HTML tag.
|
||||||
//
|
//
|
||||||
type Styler interface {
|
type Styler interface {
|
||||||
LineTag(line int) ([]byte, HtmlTag);
|
LineTag(line int) ([]byte, HTMLTag);
|
||||||
Comment(c *ast.Comment, line []byte) ([]byte, HtmlTag);
|
Comment(c *ast.Comment, line []byte) ([]byte, HTMLTag);
|
||||||
BasicLit(x *ast.BasicLit) ([]byte, HtmlTag);
|
BasicLit(x *ast.BasicLit) ([]byte, HTMLTag);
|
||||||
Ident(id *ast.Ident) ([]byte, HtmlTag);
|
Ident(id *ast.Ident) ([]byte, HTMLTag);
|
||||||
Token(tok token.Token) ([]byte, HtmlTag);
|
Token(tok token.Token) ([]byte, HTMLTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,11 +110,11 @@ func ReadResponse(r *bufio.Reader) (*Response, os.Error) {
|
||||||
// send() method is nonpublic because, when we refactor the code for persistent
|
// send() method is nonpublic because, when we refactor the code for persistent
|
||||||
// connections, it may no longer make sense to have a method with this signature.
|
// connections, it may no longer make sense to have a method with this signature.
|
||||||
func send(req *Request) (resp *Response, err os.Error) {
|
func send(req *Request) (resp *Response, err os.Error) {
|
||||||
if req.Url.Scheme != "http" {
|
if req.URL.Scheme != "http" {
|
||||||
return nil, &badStringError{"unsupported protocol scheme", req.Url.Scheme};
|
return nil, &badStringError{"unsupported protocol scheme", req.URL.Scheme};
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := req.Url.Host;
|
addr := req.URL.Host;
|
||||||
if !hasPort(addr) {
|
if !hasPort(addr) {
|
||||||
addr += ":http";
|
addr += ":http";
|
||||||
}
|
}
|
||||||
|
|
@ -169,7 +169,7 @@ func shouldRedirect(statusCode int) bool {
|
||||||
// 303 (See Other)
|
// 303 (See Other)
|
||||||
// 307 (Temporary Redirect)
|
// 307 (Temporary Redirect)
|
||||||
//
|
//
|
||||||
// finalUrl is the URL from which the response was fetched -- identical to the input
|
// finalURL is the URL from which the response was fetched -- identical to the input
|
||||||
// URL unless redirects were followed.
|
// URL unless redirects were followed.
|
||||||
//
|
//
|
||||||
// Caller should close r.Body when done reading it.
|
// Caller should close r.Body when done reading it.
|
||||||
|
|
@ -184,7 +184,7 @@ func Get(url string) (r *Response, finalURL string, err os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var req Request;
|
var req Request;
|
||||||
if req.Url, err = ParseURL(url); err != nil {
|
if req.URL, err = ParseURL(url); err != nil {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if r, err = send(&req); err != nil {
|
if r, err = send(&req); err != nil {
|
||||||
|
|
@ -219,7 +219,7 @@ func Post(url string, bodyType string, body io.Reader) (r *Response, err os.Erro
|
||||||
"Transfer-Encoding": "chunked",
|
"Transfer-Encoding": "chunked",
|
||||||
};
|
};
|
||||||
|
|
||||||
req.Url, err = ParseURL(url);
|
req.URL, err = ParseURL(url);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err;
|
return nil, err;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,8 @@ func serveFileInternal(c *Conn, r *Request, name string, redirect bool) {
|
||||||
|
|
||||||
if redirect {
|
if redirect {
|
||||||
// redirect to canonical path: / at end of directory url
|
// redirect to canonical path: / at end of directory url
|
||||||
// r.Url.Path always begins with /
|
// r.URL.Path always begins with /
|
||||||
url := r.Url.Path;
|
url := r.URL.Path;
|
||||||
if d.IsDirectory() {
|
if d.IsDirectory() {
|
||||||
if url[len(url)-1] != '/' {
|
if url[len(url)-1] != '/' {
|
||||||
Redirect(c, url+"/", StatusMovedPermanently);
|
Redirect(c, url+"/", StatusMovedPermanently);
|
||||||
|
|
@ -171,7 +171,7 @@ type fileHandler struct {
|
||||||
func FileServer(root, prefix string) Handler { return &fileHandler{root, prefix} }
|
func FileServer(root, prefix string) Handler { return &fileHandler{root, prefix} }
|
||||||
|
|
||||||
func (f *fileHandler) ServeHTTP(c *Conn, r *Request) {
|
func (f *fileHandler) ServeHTTP(c *Conn, r *Request) {
|
||||||
path := r.Url.Path;
|
path := r.URL.Path;
|
||||||
if !strings.HasPrefix(path, f.prefix) {
|
if !strings.HasPrefix(path, f.prefix) {
|
||||||
NotFound(c, r);
|
NotFound(c, r);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -48,8 +48,8 @@ func (e *badStringError) String() string { return fmt.Sprintf("%s %q", e.what, e
|
||||||
// A Request represents a parsed HTTP request header.
|
// A Request represents a parsed HTTP request header.
|
||||||
type Request struct {
|
type Request struct {
|
||||||
Method string; // GET, POST, PUT, etc.
|
Method string; // GET, POST, PUT, etc.
|
||||||
RawUrl string; // The raw URL given in the request.
|
RawURL string; // The raw URL given in the request.
|
||||||
Url *URL; // Parsed URL.
|
URL *URL; // Parsed URL.
|
||||||
Proto string; // "HTTP/1.0"
|
Proto string; // "HTTP/1.0"
|
||||||
ProtoMajor int; // 1
|
ProtoMajor int; // 1
|
||||||
ProtoMinor int; // 0
|
ProtoMinor int; // 0
|
||||||
|
|
@ -125,7 +125,7 @@ const defaultUserAgent = "http.Client"
|
||||||
|
|
||||||
// Write writes an HTTP/1.1 request -- header and body -- in wire format.
|
// Write writes an HTTP/1.1 request -- header and body -- in wire format.
|
||||||
// This method consults the following fields of req:
|
// This method consults the following fields of req:
|
||||||
// Url
|
// URL
|
||||||
// Method (defaults to "GET")
|
// Method (defaults to "GET")
|
||||||
// UserAgent (defaults to defaultUserAgent)
|
// UserAgent (defaults to defaultUserAgent)
|
||||||
// Referer
|
// Referer
|
||||||
|
|
@ -134,13 +134,13 @@ const defaultUserAgent = "http.Client"
|
||||||
//
|
//
|
||||||
// If Body is present, "Transfer-Encoding: chunked" is forced as a header.
|
// If Body is present, "Transfer-Encoding: chunked" is forced as a header.
|
||||||
func (req *Request) Write(w io.Writer) os.Error {
|
func (req *Request) Write(w io.Writer) os.Error {
|
||||||
uri := URLEscape(req.Url.Path);
|
uri := URLEscape(req.URL.Path);
|
||||||
if req.Url.RawQuery != "" {
|
if req.URL.RawQuery != "" {
|
||||||
uri += "?" + req.Url.RawQuery;
|
uri += "?" + req.URL.RawQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(w, "%s %s HTTP/1.1\r\n", valueOrDefault(req.Method, "GET"), uri);
|
fmt.Fprintf(w, "%s %s HTTP/1.1\r\n", valueOrDefault(req.Method, "GET"), uri);
|
||||||
fmt.Fprintf(w, "Host: %s\r\n", req.Url.Host);
|
fmt.Fprintf(w, "Host: %s\r\n", req.URL.Host);
|
||||||
fmt.Fprintf(w, "User-Agent: %s\r\n", valueOrDefault(req.UserAgent, defaultUserAgent));
|
fmt.Fprintf(w, "User-Agent: %s\r\n", valueOrDefault(req.UserAgent, defaultUserAgent));
|
||||||
|
|
||||||
if req.Referer != "" {
|
if req.Referer != "" {
|
||||||
|
|
@ -452,13 +452,13 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) {
|
||||||
if f = strings.Split(s, " ", 3); len(f) < 3 {
|
if f = strings.Split(s, " ", 3); len(f) < 3 {
|
||||||
return nil, &badStringError{"malformed HTTP request", s};
|
return nil, &badStringError{"malformed HTTP request", s};
|
||||||
}
|
}
|
||||||
req.Method, req.RawUrl, req.Proto = f[0], f[1], f[2];
|
req.Method, req.RawURL, req.Proto = f[0], f[1], f[2];
|
||||||
var ok bool;
|
var ok bool;
|
||||||
if req.ProtoMajor, req.ProtoMinor, ok = parseHTTPVersion(req.Proto); !ok {
|
if req.ProtoMajor, req.ProtoMinor, ok = parseHTTPVersion(req.Proto); !ok {
|
||||||
return nil, &badStringError{"malformed HTTP version", req.Proto};
|
return nil, &badStringError{"malformed HTTP version", req.Proto};
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Url, err = ParseURL(req.RawUrl); err != nil {
|
if req.URL, err = ParseURL(req.RawURL); err != nil {
|
||||||
return nil, err;
|
return nil, err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -497,7 +497,7 @@ func ReadRequest(b *bufio.Reader) (req *Request, err os.Error) {
|
||||||
// GET http://www.google.com/index.html HTTP/1.1
|
// GET http://www.google.com/index.html HTTP/1.1
|
||||||
// Host: doesntmatter
|
// Host: doesntmatter
|
||||||
// the same. In the second case, any Host line is ignored.
|
// the same. In the second case, any Host line is ignored.
|
||||||
if v, present := req.Header["Host"]; present && req.Url.Host == "" {
|
if v, present := req.Header["Host"]; present && req.URL.Host == "" {
|
||||||
req.Host = v;
|
req.Host = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -619,7 +619,7 @@ func (r *Request) ParseForm() (err os.Error) {
|
||||||
|
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "GET":
|
case "GET":
|
||||||
query = r.Url.RawQuery;
|
query = r.URL.RawQuery;
|
||||||
case "POST":
|
case "POST":
|
||||||
if r.Body == nil {
|
if r.Body == nil {
|
||||||
return os.ErrorString("missing form body");
|
return os.ErrorString("missing form body");
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ func TestParseForm(t *testing.T) {
|
||||||
|
|
||||||
func TestQuery(t *testing.T) {
|
func TestQuery(t *testing.T) {
|
||||||
req := &Request{Method: "GET"};
|
req := &Request{Method: "GET"};
|
||||||
req.Url, _ = ParseURL("http://www.google.com/search?q=foo&q=bar");
|
req.URL, _ = ParseURL("http://www.google.com/search?q=foo&q=bar");
|
||||||
if q := req.FormValue("q"); q != "foo" {
|
if q := req.FormValue("q"); q != "foo" {
|
||||||
t.Errorf(`req.FormValue("q") = %q, want "foo"`, q);
|
t.Errorf(`req.FormValue("q") = %q, want "foo"`, q);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -357,7 +357,7 @@ func Redirect(c *Conn, url string, code int) {
|
||||||
// Because of this problem, no one pays attention
|
// Because of this problem, no one pays attention
|
||||||
// to the RFC; they all send back just a new path.
|
// to the RFC; they all send back just a new path.
|
||||||
// So do we.
|
// So do we.
|
||||||
oldpath := c.Req.Url.Path;
|
oldpath := c.Req.URL.Path;
|
||||||
if oldpath == "" { // should not happen, but avoid a crash if it does
|
if oldpath == "" { // should not happen, but avoid a crash if it does
|
||||||
oldpath = "/";
|
oldpath = "/";
|
||||||
}
|
}
|
||||||
|
|
@ -468,7 +468,7 @@ func cleanPath(p string) string {
|
||||||
// pattern most closely matches the request URL.
|
// pattern most closely matches the request URL.
|
||||||
func (mux *ServeMux) ServeHTTP(c *Conn, req *Request) {
|
func (mux *ServeMux) ServeHTTP(c *Conn, req *Request) {
|
||||||
// Clean path to canonical form and redirect.
|
// Clean path to canonical form and redirect.
|
||||||
if p := cleanPath(req.Url.Path); p != req.Url.Path {
|
if p := cleanPath(req.URL.Path); p != req.URL.Path {
|
||||||
c.SetHeader("Location", p);
|
c.SetHeader("Location", p);
|
||||||
c.WriteHeader(StatusMovedPermanently);
|
c.WriteHeader(StatusMovedPermanently);
|
||||||
return;
|
return;
|
||||||
|
|
@ -478,7 +478,7 @@ func (mux *ServeMux) ServeHTTP(c *Conn, req *Request) {
|
||||||
var h Handler;
|
var h Handler;
|
||||||
var n = 0;
|
var n = 0;
|
||||||
for k, v := range mux.m {
|
for k, v := range mux.m {
|
||||||
if !pathMatch(k, req.Url.Path) {
|
if !pathMatch(k, req.URL.Path) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if h == nil || len(k) > n {
|
if h == nil || len(k) > n {
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,8 @@ var pathVar = expvar.NewMap("file-requests")
|
||||||
|
|
||||||
func FileServer(c *http.Conn, req *http.Request) {
|
func FileServer(c *http.Conn, req *http.Request) {
|
||||||
c.SetHeader("content-type", "text/plain; charset=utf-8");
|
c.SetHeader("content-type", "text/plain; charset=utf-8");
|
||||||
pathVar.Add(req.Url.Path, 1);
|
pathVar.Add(req.URL.Path, 1);
|
||||||
path := *webroot + req.Url.Path; // TODO: insecure: use os.CleanName
|
path := *webroot + req.URL.Path; // TODO: insecure: use os.CleanName
|
||||||
f, err := os.Open(path, os.O_RDONLY, 0);
|
f, err := os.Open(path, os.O_RDONLY, 0);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.WriteHeader(http.StatusNotFound);
|
c.WriteHeader(http.StatusNotFound);
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@ var (
|
||||||
esc_gt = strings.Bytes(">");
|
esc_gt = strings.Bytes(">");
|
||||||
)
|
)
|
||||||
|
|
||||||
// HtmlEscape writes to w the properly escaped HTML equivalent
|
// HTMLEscape writes to w the properly escaped HTML equivalent
|
||||||
// of the plain text data s.
|
// of the plain text data s.
|
||||||
func HtmlEscape(w io.Writer, s []byte) {
|
func HTMLEscape(w io.Writer, s []byte) {
|
||||||
var esc []byte;
|
var esc []byte;
|
||||||
last := 0;
|
last := 0;
|
||||||
for i, c := range s {
|
for i, c := range s {
|
||||||
|
|
@ -56,9 +56,9 @@ func HtmlEscape(w io.Writer, s []byte) {
|
||||||
w.Write(s[last:len(s)]);
|
w.Write(s[last:len(s)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// HtmlFormatter formats arbitrary values for HTML
|
// HTMLFormatter formats arbitrary values for HTML
|
||||||
func HtmlFormatter(w io.Writer, value interface{}, format string) {
|
func HTMLFormatter(w io.Writer, value interface{}, format string) {
|
||||||
var b bytes.Buffer;
|
var b bytes.Buffer;
|
||||||
fmt.Fprint(&b, value);
|
fmt.Fprint(&b, value);
|
||||||
HtmlEscape(w, b.Bytes());
|
HTMLEscape(w, b.Bytes());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ type FormatterMap map[string]func(io.Writer, interface{}, string)
|
||||||
|
|
||||||
// Built-in formatters.
|
// Built-in formatters.
|
||||||
var builtins = FormatterMap{
|
var builtins = FormatterMap{
|
||||||
"html": HtmlFormatter,
|
"html": HTMLFormatter,
|
||||||
"str": StringFormatter,
|
"str": StringFormatter,
|
||||||
"": StringFormatter,
|
"": StringFormatter,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func main() {
|
||||||
printCases();
|
printCases();
|
||||||
}
|
}
|
||||||
|
|
||||||
var dataUrl = flag.String("data", "", "full URL for UnicodeData.txt; defaults to --url/UnicodeData.txt")
|
var dataURL = flag.String("data", "", "full URL for UnicodeData.txt; defaults to --url/UnicodeData.txt")
|
||||||
var url = flag.String("url",
|
var url = flag.String("url",
|
||||||
"http://www.unicode.org/Public/5.1.0/ucd/",
|
"http://www.unicode.org/Public/5.1.0/ucd/",
|
||||||
"URL of Unicode database directory")
|
"URL of Unicode database directory")
|
||||||
|
|
@ -255,10 +255,10 @@ func letterOp(code int) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadChars() {
|
func loadChars() {
|
||||||
if *dataUrl == "" {
|
if *dataURL == "" {
|
||||||
flag.Set("data", *url + "UnicodeData.txt");
|
flag.Set("data", *url + "UnicodeData.txt");
|
||||||
}
|
}
|
||||||
resp, _, err := http.Get(*dataUrl);
|
resp, _, err := http.Get(*dataURL);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
die.Log(err);
|
die.Log(err);
|
||||||
}
|
}
|
||||||
|
|
@ -318,7 +318,7 @@ func printCategories() {
|
||||||
"// DO NOT EDIT\n\n"
|
"// DO NOT EDIT\n\n"
|
||||||
"package unicode\n\n",
|
"package unicode\n\n",
|
||||||
*tablelist,
|
*tablelist,
|
||||||
*dataUrl);
|
*dataURL);
|
||||||
|
|
||||||
fmt.Println("// Version is the Unicode edition from which the tables are derived.");
|
fmt.Println("// Version is the Unicode edition from which the tables are derived.");
|
||||||
fmt.Printf("const Version = %q\n\n", version());
|
fmt.Printf("const Version = %q\n\n", version());
|
||||||
|
|
@ -784,7 +784,7 @@ func printCases() {
|
||||||
"// non-self mappings.\n"
|
"// non-self mappings.\n"
|
||||||
"var CaseRanges = _CaseRanges\n"
|
"var CaseRanges = _CaseRanges\n"
|
||||||
"var _CaseRanges = []CaseRange {\n",
|
"var _CaseRanges = []CaseRange {\n",
|
||||||
*dataUrl);
|
*dataURL);
|
||||||
|
|
||||||
var startState *caseState; // the start of a run; nil for not active
|
var startState *caseState; // the start of a run; nil for not active
|
||||||
var prevState = &caseState{}; // the state of the previous character
|
var prevState = &caseState{}; // the state of the previous character
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue