diff --git a/README.md b/README.md index c7e8d4d..74acd78 100644 --- a/README.md +++ b/README.md @@ -310,16 +310,16 @@ func main() { if string(host) == "github.com" { return nil } - return &ws.RejectConnectionError( + return ws.RejectConnectionError( ws.RejectionStatus(403), ws.RejectionHeader(ws.HandshakeHeaderString( - "X-Want-Host: github.com", + "X-Want-Host: github.com\r\n", )), ) }, OnHeader: func(key, value []byte) error { if string(key) != "Cookie" { - return + return nil } ok := httphead.ScanCookie(value, func(key, value []byte) bool { // Check session here or do some other stuff with cookies. @@ -329,12 +329,12 @@ func main() { if ok { return nil } - return &ws.RejectConnectionError( + return ws.RejectConnectionError( ws.RejectionReason("bad cookie"), ws.RejectionStatus(400), ) }, - OnBeforeUpgrade: func() (HandshakeHeader, error) { + OnBeforeUpgrade: func() (ws.HandshakeHeader, error) { return header, nil }, } diff --git a/dialer_test.go b/dialer_test.go index f7d8bd0..58fb90f 100644 --- a/dialer_test.go +++ b/dialer_test.go @@ -574,7 +574,7 @@ func TestDialerHandshake(t *testing.T) { } } -// Used to emulate net.Error behaviour, which is usually returned when +// Used to emulate net.Error behavior, which is usually returned when // connection deadline exceeds. type errTimeout struct { error diff --git a/server.go b/server.go index 1759b73..7c7f63c 100644 --- a/server.go +++ b/server.go @@ -133,7 +133,7 @@ type HTTPUpgrader struct { // Upgrade upgrades http connection to the websocket connection. // -// It hijacks net.Conn from w and returns recevied net.Conn and +// It hijacks net.Conn from w and returns received net.Conn and // bufio.ReadWriter. On successful handshake it returns Handshake struct // describing handshake info. func (u HTTPUpgrader) Upgrade(r *http.Request, w http.ResponseWriter) (conn net.Conn, rw *bufio.ReadWriter, hs Handshake, err error) { diff --git a/wsutil/cipher.go b/wsutil/cipher.go index 162767f..f234be7 100644 --- a/wsutil/cipher.go +++ b/wsutil/cipher.go @@ -38,7 +38,7 @@ func (c *CipherReader) Read(p []byte) (n int, err error) { } // CipherWriter implements io.Writer that applies xor-cipher to the bytes -// written to the destination writer. It does not modifiy the original bytes. +// written to the destination writer. It does not modify the original bytes. type CipherWriter struct { w io.Writer mask [4]byte @@ -57,7 +57,7 @@ func (c *CipherWriter) Reset(w io.Writer, mask [4]byte) { c.pos = 0 } -// Write implements io.Writer interface. It applies mask vien during +// Write implements io.Writer interface. It applies masking during // initialization to every sent byte. It does not modify original slice. func (c *CipherWriter) Write(p []byte) (n int, err error) { cp := pbytes.GetLen(len(p)) diff --git a/wsutil/dialer.go b/wsutil/dialer.go index 64cf3d3..91c03d5 100644 --- a/wsutil/dialer.go +++ b/wsutil/dialer.go @@ -19,7 +19,7 @@ import ( // Note that it must not be used in production applications that requires // Dial() to be efficient. type DebugDialer struct { - // Dialer contains WebSocket connection establishement options. + // Dialer contains WebSocket connection establishment options. Dialer ws.Dialer // OnRequest and OnResponse are the callbacks that will be called with the @@ -70,7 +70,7 @@ func (d *DebugDialer) Dial(ctx context.Context, urlstr string) (conn net.Conn, b onRequest(reqBuf.Bytes()) } if onResponse := d.OnResponse; onResponse != nil { - // We must split response iniside buffered bytes from other received + // We must split response inside buffered bytes from other received // bytes from server. p := resBuf.Bytes() n := bytes.Index(p, headEnd) diff --git a/wsutil/handler.go b/wsutil/handler.go index 4578bc4..a8f499f 100644 --- a/wsutil/handler.go +++ b/wsutil/handler.go @@ -49,7 +49,7 @@ type ControlHandler struct { // header could not be handled. var ErrNotControlFrame = errors.New("not a control frame") -// Handle handles control framse regarding to the c.State and writes responses +// Handle handles control frames regarding to the c.State and writes responses // to the c.Dst when needed. // // It returns ErrNotControlFrame when given header is not of ws.OpClose, diff --git a/wsutil/helper.go b/wsutil/helper.go index 0aca245..0a63def 100644 --- a/wsutil/helper.go +++ b/wsutil/helper.go @@ -47,7 +47,7 @@ func ReadMessage(r io.Reader, s ws.State, m []Message) ([]Message, error) { // No more frames will be read. Use fixed sized buffer to read payload. p = make([]byte, h.Length) // It is not possible to receive io.EOF here because Reader does not - // return EOF if frame payload was successfuly fetched. + // return EOF if frame payload was successfully fetched. // Thus we consistent here with io.Reader behavior. _, err = io.ReadFull(&rd, p) } else { diff --git a/wsutil/reader.go b/wsutil/reader.go index 1bffdc5..f3f9c23 100644 --- a/wsutil/reader.go +++ b/wsutil/reader.go @@ -124,7 +124,7 @@ func (r *Reader) Read(p []byte) (n int, err error) { } // Discard discards current message unread bytes. -// It discards all frames of fragmeneted message. +// It discards all frames of fragmented message. func (r *Reader) Discard() (err error) { for { _, err = io.Copy(ioutil.Discard, &r.raw) diff --git a/wsutil/upgrader.go b/wsutil/upgrader.go index e6d4335..2ed351e 100644 --- a/wsutil/upgrader.go +++ b/wsutil/upgrader.go @@ -27,7 +27,7 @@ type DebugUpgrader struct { // Upgrade calls Upgrade() on underlying ws.Upgrader and tracks I/O on conn. func (d *DebugUpgrader) Upgrade(conn io.ReadWriter) (hs ws.Handshake, err error) { var ( - // Take the Reader and Writer partst from conn to be probably replaced + // Take the Reader and Writer parts from conn to be probably replaced // below. r io.Reader = conn w io.Writer = conn diff --git a/wsutil/utf8.go b/wsutil/utf8.go index 5f510aa..d877be0 100644 --- a/wsutil/utf8.go +++ b/wsutil/utf8.go @@ -5,7 +5,7 @@ import ( "io" ) -// ErrInvalidUTF8 is returned by UTF8 reader on invalid utf8 sequnce. +// ErrInvalidUTF8 is returned by UTF8 reader on invalid utf8 sequence. var ErrInvalidUTF8 = fmt.Errorf("invalid utf8") // UTF8Reader implements io.Reader that calculates utf8 validity state after diff --git a/wsutil/writer.go b/wsutil/writer.go index 5fd5620..c76b0b4 100644 --- a/wsutil/writer.go +++ b/wsutil/writer.go @@ -289,7 +289,7 @@ func (w *Writer) Write(p []byte) (n int, err error) { // this could bring unwanted fragmentation. That is, user could create // buffer with size that fits exactly all further Write() call, and then // call Flush(), excepting that single and not fragmented frame will be - // sent. With preemtive flush this case will produce two frames – last one + // sent. With preemptive flush this case will produce two frames – last one // will be empty and just to set fin = true. return n, w.err @@ -347,7 +347,7 @@ func (w *Writer) ReadFrom(src io.Reader) (n int64, err error) { n += int64(nn) } if err == io.EOF { - // NOTE: Do not flush preemtively. + // NOTE: Do not flush preemptively. // See the Write() sources for more info. err = nil w.dirty = true diff --git a/wsutil/wsutil.go b/wsutil/wsutil.go index 5a5f0d9..ffd4336 100644 --- a/wsutil/wsutil.go +++ b/wsutil/wsutil.go @@ -9,7 +9,7 @@ Overview: // handle err } - // Preapre to read payload. + // Prepare to read payload. r := io.LimitReader(conn, header.Length) r = wsutil.NewCipherReader(r, header.Mask) r = wsutil.NewUTF8Reader(r)