mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
Fixes breakage caused by semicolon restriction.
R=rsc APPROVED=rsc DELTA=50 (4 added, 0 deleted, 46 changed) OCL=16707 CL=16725
This commit is contained in:
parent
b4f8e01acb
commit
f4a8db667b
6 changed files with 50 additions and 46 deletions
|
|
@ -45,12 +45,16 @@ O4=\
|
||||||
$(PKG): a1 a2 a3 a4
|
$(PKG): a1 a2 a3 a4
|
||||||
a1: $(O1)
|
a1: $(O1)
|
||||||
$(AR) grc $(PKG) $(O1)
|
$(AR) grc $(PKG) $(O1)
|
||||||
|
rm -f $(O1)
|
||||||
a2: $(O2)
|
a2: $(O2)
|
||||||
$(AR) grc $(PKG) $(O2)
|
$(AR) grc $(PKG) $(O2)
|
||||||
|
rm -f $(O2)
|
||||||
a3: $(O3)
|
a3: $(O3)
|
||||||
$(AR) grc $(PKG) $(O3)
|
$(AR) grc $(PKG) $(O3)
|
||||||
|
rm -f $(O3)
|
||||||
a4: $(O4)
|
a4: $(O4)
|
||||||
$(AR) grc $(PKG) $(O4)
|
$(AR) grc $(PKG) $(O4)
|
||||||
|
rm -f $(O4)
|
||||||
|
|
||||||
$(O1): nuke
|
$(O1): nuke
|
||||||
$(O2): a1
|
$(O2): a1
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import (
|
||||||
type RWC interface {
|
type RWC interface {
|
||||||
Read(p *[]byte) (n int, err *os.Error);
|
Read(p *[]byte) (n int, err *os.Error);
|
||||||
Write(p *[]byte) (n int, err *os.Error);
|
Write(p *[]byte) (n int, err *os.Error);
|
||||||
Close() *os.Error
|
Close() *os.Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Active HTTP connection (server side).
|
// Active HTTP connection (server side).
|
||||||
|
|
@ -48,7 +48,7 @@ func (c *Conn) ReadRequest() (req *Request, err *os.Error) {
|
||||||
|
|
||||||
// TODO: Proper handling of (lack of) Connection: close,
|
// TODO: Proper handling of (lack of) Connection: close,
|
||||||
// and chunked transfer encoding on output.
|
// and chunked transfer encoding on output.
|
||||||
c.close = true
|
c.close = true;
|
||||||
return req, nil
|
return req, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ func ReadLineBytes(b *bufio.BufRead) (p *[]byte, err *os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chop off trailing white space.
|
// Chop off trailing white space.
|
||||||
var i int
|
var i int;
|
||||||
for i = len(p); i > 0; i-- {
|
for i = len(p); i > 0; i-- {
|
||||||
if c := p[i-1]; c != ' ' && c != '\r' && c != '\t' && c != '\n' {
|
if c := p[i-1]; c != ' ' && c != '\r' && c != '\t' && c != '\n' {
|
||||||
break
|
break
|
||||||
|
|
@ -69,7 +69,7 @@ func ReadLineBytes(b *bufio.BufRead) (p *[]byte, err *os.Error) {
|
||||||
|
|
||||||
// ReadLineByte, but convert the bytes into a string.
|
// ReadLineByte, but convert the bytes into a string.
|
||||||
func ReadLine(b *bufio.BufRead) (s string, err *os.Error) {
|
func ReadLine(b *bufio.BufRead) (s string, err *os.Error) {
|
||||||
p, e := ReadLineBytes(b)
|
p, e := ReadLineBytes(b);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return "", e
|
return "", e
|
||||||
}
|
}
|
||||||
|
|
@ -81,7 +81,7 @@ func ReadLine(b *bufio.BufRead) (s string, err *os.Error) {
|
||||||
// and the Value can continue on multiple lines if each continuation line
|
// and the Value can continue on multiple lines if each continuation line
|
||||||
// starts with a space.
|
// starts with a space.
|
||||||
func ReadKeyValue(b *bufio.BufRead) (key, value string, err *os.Error) {
|
func ReadKeyValue(b *bufio.BufRead) (key, value string, err *os.Error) {
|
||||||
line, e := ReadLineBytes(b)
|
line, e := ReadLineBytes(b);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return "", "", e
|
return "", "", e
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +94,7 @@ func ReadKeyValue(b *bufio.BufRead) (key, value string, err *os.Error) {
|
||||||
switch line[i] {
|
switch line[i] {
|
||||||
case ' ':
|
case ' ':
|
||||||
// Key field has space - no good.
|
// Key field has space - no good.
|
||||||
return "", "", BadHeader
|
return "", "", BadHeader;
|
||||||
case ':':
|
case ':':
|
||||||
key = string(line[0:i]);
|
key = string(line[0:i]);
|
||||||
// Skip initial space before value.
|
// Skip initial space before value.
|
||||||
|
|
@ -103,7 +103,7 @@ func ReadKeyValue(b *bufio.BufRead) (key, value string, err *os.Error) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = string(line[i:len(line)])
|
value = string(line[i:len(line)]);
|
||||||
|
|
||||||
// Look for extension lines, which must begin with space.
|
// Look for extension lines, which must begin with space.
|
||||||
for {
|
for {
|
||||||
|
|
@ -114,7 +114,7 @@ func ReadKeyValue(b *bufio.BufRead) (key, value string, err *os.Error) {
|
||||||
}
|
}
|
||||||
if c != ' ' {
|
if c != ' ' {
|
||||||
// Not leading space; stop.
|
// Not leading space; stop.
|
||||||
b.UnreadByte()
|
b.UnreadByte();
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,13 +124,13 @@ func ReadKeyValue(b *bufio.BufRead) (key, value string, err *os.Error) {
|
||||||
return "", "", e
|
return "", "", e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.UnreadByte()
|
b.UnreadByte();
|
||||||
|
|
||||||
// Read the rest of the line and add to value.
|
// Read the rest of the line and add to value.
|
||||||
if line, e = ReadLineBytes(b); e != nil {
|
if line, e = ReadLineBytes(b); e != nil {
|
||||||
return "", "", e
|
return "", "", e
|
||||||
}
|
}
|
||||||
value += " " + string(line)
|
value += " " + string(line);
|
||||||
|
|
||||||
if len(value) >= MaxValueLength {
|
if len(value) >= MaxValueLength {
|
||||||
return "", "", ValueTooLong
|
return "", "", ValueTooLong
|
||||||
|
|
@ -148,13 +148,13 @@ func ReadKeyValue(b *bufio.BufRead) (key, value string, err *os.Error) {
|
||||||
// returning value, string position where the digits stopped,
|
// returning value, string position where the digits stopped,
|
||||||
// and whether there was a valid number (digits, not too big).
|
// and whether there was a valid number (digits, not too big).
|
||||||
func atoi(s string, i int) (n, i1 int, ok bool) {
|
func atoi(s string, i int) (n, i1 int, ok bool) {
|
||||||
const Big = 1000000
|
const Big = 1000000;
|
||||||
if i >= len(s) || s[i] < '0' || s[i] > '9' {
|
if i >= len(s) || s[i] < '0' || s[i] > '9' {
|
||||||
return 0, 0, false
|
return 0, 0, false
|
||||||
}
|
}
|
||||||
n = 0
|
n = 0;
|
||||||
for ; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
|
for ; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
|
||||||
n = n*10 + int(s[i]-'0')
|
n = n*10 + int(s[i]-'0');
|
||||||
if n > Big {
|
if n > Big {
|
||||||
return 0, 0, false
|
return 0, 0, false
|
||||||
}
|
}
|
||||||
|
|
@ -167,12 +167,12 @@ func ParseHTTPVersion(vers string) (int, int, bool) {
|
||||||
if vers[0:5] != "HTTP/" {
|
if vers[0:5] != "HTTP/" {
|
||||||
return 0, 0, false
|
return 0, 0, false
|
||||||
}
|
}
|
||||||
major, i, ok := atoi(vers, 5)
|
major, i, ok := atoi(vers, 5);
|
||||||
if !ok || i >= len(vers) || vers[i] != '.' {
|
if !ok || i >= len(vers) || vers[i] != '.' {
|
||||||
return 0, 0, false
|
return 0, 0, false
|
||||||
}
|
}
|
||||||
var minor int;
|
var minor int;
|
||||||
minor, i, ok = atoi(vers, i+1)
|
minor, i, ok = atoi(vers, i+1);
|
||||||
if !ok || i != len(vers) {
|
if !ok || i != len(vers) {
|
||||||
return 0, 0, false
|
return 0, 0, false
|
||||||
}
|
}
|
||||||
|
|
@ -184,16 +184,16 @@ export func ReadRequest(b *bufio.BufRead) (req *Request, err *os.Error) {
|
||||||
req = new(Request);
|
req = new(Request);
|
||||||
|
|
||||||
// First line: GET /index.html HTTP/1.0
|
// First line: GET /index.html HTTP/1.0
|
||||||
var s string
|
var s string;
|
||||||
if s, err = ReadLine(b); err != nil {
|
if s, err = ReadLine(b); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var f *[]string
|
var f *[]string;
|
||||||
if f = strings.split(s, " "); len(f) != 3 {
|
if f = strings.split(s, " "); len(f) != 3 {
|
||||||
return nil, BadRequest
|
return nil, BadRequest
|
||||||
}
|
}
|
||||||
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.pmajor, req.pminor, ok = ParseHTTPVersion(req.proto); !ok {
|
if req.pmajor, req.pminor, ok = ParseHTTPVersion(req.proto); !ok {
|
||||||
return nil, BadHTTPVersion
|
return nil, BadHTTPVersion
|
||||||
|
|
@ -205,9 +205,9 @@ export func ReadRequest(b *bufio.BufRead) (req *Request, err *os.Error) {
|
||||||
|
|
||||||
// Subsequent lines: Key: value.
|
// Subsequent lines: Key: value.
|
||||||
nheader := 0;
|
nheader := 0;
|
||||||
req.header = new(map[string] string)
|
req.header = new(map[string] string);
|
||||||
for {
|
for {
|
||||||
var key, value string
|
var key, value string;
|
||||||
if key, value, err = ReadKeyValue(b); err != nil {
|
if key, value, err = ReadKeyValue(b); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -221,7 +221,7 @@ export func ReadRequest(b *bufio.BufRead) (req *Request, err *os.Error) {
|
||||||
// RFC 2616 says that if you send the same header key
|
// RFC 2616 says that if you send the same header key
|
||||||
// multiple times, it has to be semantically equivalent
|
// multiple times, it has to be semantically equivalent
|
||||||
// to concatenating the values separated by commas.
|
// to concatenating the values separated by commas.
|
||||||
oldvalue, present := req.header[key]
|
oldvalue, present := req.header[key];
|
||||||
if present {
|
if present {
|
||||||
req.header[key] = oldvalue+","+value
|
req.header[key] = oldvalue+","+value
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -18,16 +18,16 @@ import (
|
||||||
|
|
||||||
// Serve a new connection.
|
// Serve a new connection.
|
||||||
func ServeConnection(fd net.Conn, raddr string, f *(*Conn, *Request)) {
|
func ServeConnection(fd net.Conn, raddr string, f *(*Conn, *Request)) {
|
||||||
c, err := NewConn(fd)
|
c, err := NewConn(fd);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
req, err := c.ReadRequest()
|
req, err := c.ReadRequest();
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
f(c, req)
|
f(c, req);
|
||||||
if c.close {
|
if c.close {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -44,7 +44,7 @@ export func Serve(l net.Listener, f *(*Conn, *Request)) *os.Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
rw, raddr, e := l.Accept()
|
rw, raddr, e := l.Accept();
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
@ -55,11 +55,11 @@ export func Serve(l net.Listener, f *(*Conn, *Request)) *os.Error {
|
||||||
|
|
||||||
// Web server: listen on address, call f for each request.
|
// Web server: listen on address, call f for each request.
|
||||||
export func ListenAndServe(addr string, f *(*Conn, *Request)) *os.Error {
|
export func ListenAndServe(addr string, f *(*Conn, *Request)) *os.Error {
|
||||||
l, e := net.Listen("tcp", addr)
|
l, e := net.Listen("tcp", addr);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
e = Serve(l, f);
|
e = Serve(l, f);
|
||||||
l.Close()
|
l.Close();
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ func Echo(conn *http.Conn, req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := http.ListenAndServe("0.0.0.0:12345", &Echo)
|
err := http.ListenAndServe("0.0.0.0:12345", &Echo);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("ListenAndServe: ", err.String())
|
panic("ListenAndServe: ", err.String())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,11 @@ export var (
|
||||||
func IsHex(c byte) bool {
|
func IsHex(c byte) bool {
|
||||||
switch {
|
switch {
|
||||||
case '0' <= c && c <= '9':
|
case '0' <= c && c <= '9':
|
||||||
return true
|
return true;
|
||||||
case 'a' <= c && c <= 'f':
|
case 'a' <= c && c <= 'f':
|
||||||
return true
|
return true;
|
||||||
case 'A' <= c && c <= 'F':
|
case 'A' <= c && c <= 'F':
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
@ -29,11 +29,11 @@ func IsHex(c byte) bool {
|
||||||
func UnHex(c byte) byte {
|
func UnHex(c byte) byte {
|
||||||
switch {
|
switch {
|
||||||
case '0' <= c && c <= '9':
|
case '0' <= c && c <= '9':
|
||||||
return c - '0'
|
return c - '0';
|
||||||
case 'a' <= c && c <= 'f':
|
case 'a' <= c && c <= 'f':
|
||||||
return c - 'a' + 10
|
return c - 'a' + 10;
|
||||||
case 'A' <= c && c <= 'F':
|
case 'A' <= c && c <= 'F':
|
||||||
return c - 'A' + 10
|
return c - 'A' + 10;
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
@ -41,12 +41,12 @@ func UnHex(c byte) byte {
|
||||||
// Unescape %xx into hex.
|
// Unescape %xx into hex.
|
||||||
export func URLUnescape(s string) (string, *os.Error) {
|
export func URLUnescape(s string) (string, *os.Error) {
|
||||||
// Count %, check that they're well-formed.
|
// Count %, check that they're well-formed.
|
||||||
n := 0
|
n := 0;
|
||||||
for i := 0; i < len(s); {
|
for i := 0; i < len(s); {
|
||||||
if s[i] == '%' {
|
if s[i] == '%' {
|
||||||
n++
|
n++;
|
||||||
if !IsHex(s[i+1]) || !IsHex(s[i+2]) {
|
if !IsHex(s[i+1]) || !IsHex(s[i+2]) {
|
||||||
return "", BadURL
|
return "", BadURL;
|
||||||
}
|
}
|
||||||
i += 3
|
i += 3
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -59,19 +59,19 @@ export func URLUnescape(s string) (string, *os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t := new([]byte, len(s)-2*n);
|
t := new([]byte, len(s)-2*n);
|
||||||
j := 0
|
j := 0;
|
||||||
for i := 0; i < len(s); {
|
for i := 0; i < len(s); {
|
||||||
if s[i] == '%' {
|
if s[i] == '%' {
|
||||||
t[j] = UnHex(s[i+1]) << 4 | UnHex(s[i+2]);
|
t[j] = UnHex(s[i+1]) << 4 | UnHex(s[i+2]);
|
||||||
j++
|
j++;
|
||||||
i += 3
|
i += 3;
|
||||||
} else {
|
} else {
|
||||||
t[j] = s[i];
|
t[j] = s[i];
|
||||||
j++
|
j++;
|
||||||
i++
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return string(t), nil
|
return string(t), nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type URL struct {
|
export type URL struct {
|
||||||
|
|
@ -130,14 +130,14 @@ export func ParseURL(rawurl string) (url *URL, err *os.Error) {
|
||||||
return nil, BadURL
|
return nil, BadURL
|
||||||
}
|
}
|
||||||
url = new(URL);
|
url = new(URL);
|
||||||
url.raw = rawurl
|
url.raw = rawurl;
|
||||||
|
|
||||||
// Split off possible leading "http:", "mailto:", etc.
|
// Split off possible leading "http:", "mailto:", etc.
|
||||||
var path string
|
var path string;
|
||||||
if url.scheme, path, err = GetScheme(rawurl); err != nil {
|
if url.scheme, path, err = GetScheme(rawurl); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
url.rawpath = path
|
url.rawpath = path;
|
||||||
|
|
||||||
// RFC 2396: a relative URI (no scheme) has a ?query,
|
// RFC 2396: a relative URI (no scheme) has a ?query,
|
||||||
// but absolute URIs only have query if path begins with /
|
// but absolute URIs only have query if path begins with /
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue