mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
1) Change default gofmt default settings for
parsing and printing to new syntax. Use -oldparser to parse the old syntax, use -oldprinter to print the old syntax. 2) Change default gofmt formatting settings to use tabs for indentation only and to use spaces for alignment. This will make the code alignment insensitive to an editor's tabwidth. Use -spaces=false to use tabs for alignment. 3) Manually changed src/exp/parser/parser_test.go so that it doesn't try to parse the parser's source files using the old syntax (they have new syntax now). 4) gofmt -w src misc test/bench 5th and last set of files. R=rsc CC=golang-dev https://golang.org/cl/180050
This commit is contained in:
parent
d65a5cce89
commit
45ca9f7a9e
59 changed files with 5907 additions and 5907 deletions
|
|
@ -5,40 +5,40 @@
|
|||
package websocket
|
||||
|
||||
import (
|
||||
"bufio";
|
||||
"http";
|
||||
"io";
|
||||
"net";
|
||||
"os";
|
||||
"bufio"
|
||||
"http"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
)
|
||||
|
||||
type ProtocolError struct {
|
||||
os.ErrorString;
|
||||
os.ErrorString
|
||||
}
|
||||
|
||||
var (
|
||||
ErrBadStatus = &ProtocolError{"bad status"};
|
||||
ErrNoUpgrade = &ProtocolError{"no upgrade"};
|
||||
ErrBadUpgrade = &ProtocolError{"bad upgrade"};
|
||||
ErrNoWebSocketOrigin = &ProtocolError{"no WebSocket-Origin"};
|
||||
ErrBadWebSocketOrigin = &ProtocolError{"bad WebSocket-Origin"};
|
||||
ErrNoWebSocketLocation = &ProtocolError{"no WebSocket-Location"};
|
||||
ErrBadWebSocketLocation = &ProtocolError{"bad WebSocket-Location"};
|
||||
ErrNoWebSocketProtocol = &ProtocolError{"no WebSocket-Protocol"};
|
||||
ErrBadWebSocketProtocol = &ProtocolError{"bad WebSocket-Protocol"};
|
||||
ErrBadStatus = &ProtocolError{"bad status"}
|
||||
ErrNoUpgrade = &ProtocolError{"no upgrade"}
|
||||
ErrBadUpgrade = &ProtocolError{"bad upgrade"}
|
||||
ErrNoWebSocketOrigin = &ProtocolError{"no WebSocket-Origin"}
|
||||
ErrBadWebSocketOrigin = &ProtocolError{"bad WebSocket-Origin"}
|
||||
ErrNoWebSocketLocation = &ProtocolError{"no WebSocket-Location"}
|
||||
ErrBadWebSocketLocation = &ProtocolError{"bad WebSocket-Location"}
|
||||
ErrNoWebSocketProtocol = &ProtocolError{"no WebSocket-Protocol"}
|
||||
ErrBadWebSocketProtocol = &ProtocolError{"bad WebSocket-Protocol"}
|
||||
)
|
||||
|
||||
// newClient creates a new Web Socket client connection.
|
||||
func newClient(resourceName, host, origin, location, protocol string, rwc io.ReadWriteCloser) (ws *Conn, err os.Error) {
|
||||
br := bufio.NewReader(rwc);
|
||||
bw := bufio.NewWriter(rwc);
|
||||
err = handshake(resourceName, host, origin, location, protocol, br, bw);
|
||||
br := bufio.NewReader(rwc)
|
||||
bw := bufio.NewWriter(rwc)
|
||||
err = handshake(resourceName, host, origin, location, protocol, br, bw)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
buf := bufio.NewReadWriter(br, bw);
|
||||
ws = newConn(origin, location, protocol, buf, rwc);
|
||||
return;
|
||||
buf := bufio.NewReadWriter(br, bw)
|
||||
ws = newConn(origin, location, protocol, buf, rwc)
|
||||
return
|
||||
}
|
||||
|
||||
// Dial opens new Web Socket client connection.
|
||||
|
|
@ -68,55 +68,55 @@ func newClient(resourceName, host, origin, location, protocol string, rwc io.Rea
|
|||
// }
|
||||
|
||||
func Dial(url, protocol, origin string) (ws *Conn, err os.Error) {
|
||||
parsedUrl, err := http.ParseURL(url);
|
||||
parsedUrl, err := http.ParseURL(url)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
client, err := net.Dial("tcp", "", parsedUrl.Host);
|
||||
client, err := net.Dial("tcp", "", parsedUrl.Host)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return newClient(parsedUrl.Path, parsedUrl.Host, origin, url, protocol, client);
|
||||
return newClient(parsedUrl.Path, parsedUrl.Host, origin, url, protocol, client)
|
||||
}
|
||||
|
||||
func handshake(resourceName, host, origin, location, protocol string, br *bufio.Reader, bw *bufio.Writer) (err os.Error) {
|
||||
bw.WriteString("GET " + resourceName + " HTTP/1.1\r\n");
|
||||
bw.WriteString("Upgrade: WebSocket\r\n");
|
||||
bw.WriteString("Connection: Upgrade\r\n");
|
||||
bw.WriteString("Host: " + host + "\r\n");
|
||||
bw.WriteString("Origin: " + origin + "\r\n");
|
||||
bw.WriteString("GET " + resourceName + " HTTP/1.1\r\n")
|
||||
bw.WriteString("Upgrade: WebSocket\r\n")
|
||||
bw.WriteString("Connection: Upgrade\r\n")
|
||||
bw.WriteString("Host: " + host + "\r\n")
|
||||
bw.WriteString("Origin: " + origin + "\r\n")
|
||||
if protocol != "" {
|
||||
bw.WriteString("WebSocket-Protocol: " + protocol + "\r\n")
|
||||
}
|
||||
bw.WriteString("\r\n");
|
||||
bw.Flush();
|
||||
resp, err := http.ReadResponse(br);
|
||||
bw.WriteString("\r\n")
|
||||
bw.Flush()
|
||||
resp, err := http.ReadResponse(br)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if resp.Status != "101 Web Socket Protocol Handshake" {
|
||||
return ErrBadStatus
|
||||
}
|
||||
upgrade, found := resp.Header["Upgrade"];
|
||||
upgrade, found := resp.Header["Upgrade"]
|
||||
if !found {
|
||||
return ErrNoUpgrade
|
||||
}
|
||||
if upgrade != "WebSocket" {
|
||||
return ErrBadUpgrade
|
||||
}
|
||||
connection, found := resp.Header["Connection"];
|
||||
connection, found := resp.Header["Connection"]
|
||||
if !found || connection != "Upgrade" {
|
||||
return ErrBadUpgrade
|
||||
}
|
||||
|
||||
ws_origin, found := resp.Header["Websocket-Origin"];
|
||||
ws_origin, found := resp.Header["Websocket-Origin"]
|
||||
if !found {
|
||||
return ErrNoWebSocketOrigin
|
||||
}
|
||||
if ws_origin != origin {
|
||||
return ErrBadWebSocketOrigin
|
||||
}
|
||||
ws_location, found := resp.Header["Websocket-Location"];
|
||||
ws_location, found := resp.Header["Websocket-Location"]
|
||||
if !found {
|
||||
return ErrNoWebSocketLocation
|
||||
}
|
||||
|
|
@ -124,7 +124,7 @@ func handshake(resourceName, host, origin, location, protocol string, br *bufio.
|
|||
return ErrBadWebSocketLocation
|
||||
}
|
||||
if protocol != "" {
|
||||
ws_protocol, found := resp.Header["Websocket-Protocol"];
|
||||
ws_protocol, found := resp.Header["Websocket-Protocol"]
|
||||
if !found {
|
||||
return ErrNoWebSocketProtocol
|
||||
}
|
||||
|
|
@ -132,5 +132,5 @@ func handshake(resourceName, host, origin, location, protocol string, br *bufio.
|
|||
return ErrBadWebSocketProtocol
|
||||
}
|
||||
}
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue