Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/net/websocket: The error message doesn't contain the expected string while websocket connect failed. #10126

Closed
runner-mei opened this issue Mar 10, 2015 · 5 comments
Milestone

Comments

@runner-mei
Copy link

@runner-mei runner-mei commented Mar 10, 2015

The error message doesn't contain the expected string while websocket connect failed.

package main

import (
    "errors"
    "fmt"
    "io"
    "net/http"
    "strings"

    "golang.org/x/net/websocket"
)

func main() {
    echo := websocket.Server{
        Handshake: func(config *websocket.Config, req *http.Request) error {
            return errors.New("handshakeError")
        },
        Handler: websocket.Handler(func(ws *websocket.Conn) {
            io.Copy(ws, ws)
        }),
    }
    http.Handle("/echo", echo)

    go http.ListenAndServe(":12345", nil)

    _, err := websocket.Dial("ws://localhost:12345/echo", "", "http://localhost/")
    if err == nil {
        fmt.Fatal("except failed.")
        return
    }

    if strings.Contains(err.Error(), "handshakeError") {
        fmt.Println("ok") // error message is contains excepted string 'handshakeError'
    } else {
        fmt.Println("failed") // error message don.t contains excepted string 'handshakeError'
    }
}
@adg adg changed the title websocket: error message isn't excepted while websocket handshake failed. net/websocket: error message isn't excepted while websocket handshake failed. Mar 11, 2015
@adg
Copy link
Contributor

@adg adg commented Mar 11, 2015

I don't understand the error report. What is the error string that is reported?

@mikioh mikioh changed the title net/websocket: error message isn't excepted while websocket handshake failed. websocket: error message isn't excepted while websocket handshake failed. Mar 11, 2015
@mikioh mikioh added the repo-net label Mar 11, 2015
@runner-mei runner-mei changed the title websocket: error message isn't excepted while websocket handshake failed. websocket: The error message doesn't contain the expected string while websocket connect failed. Mar 11, 2015
@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title websocket: The error message doesn't contain the expected string while websocket connect failed. x/net/websocket: The error message doesn't contain the expected string while websocket connect failed. Apr 14, 2015
@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015
@rsc rsc removed the repo-net label Apr 14, 2015
@mikioh
Copy link
Contributor

@mikioh mikioh commented Jul 30, 2015

See http://godoc.org/golang.org/x/net/websocket#Server. You need to implement your WebSocket protocol speaker at server-side. Otherwise client never gets anything you want to say.

@mikioh mikioh closed this Jul 30, 2015
@runner-mei
Copy link
Author

@runner-mei runner-mei commented Jul 30, 2015

Apparently, the error here, why not read error message from response.
https://github.com/golang/net/blob/master/websocket/hybi.go#L425

@mikioh
Copy link
Contributor

@mikioh mikioh commented Jul 30, 2015

I don't understand. Have you already taken a look at newServerConn in server.go?

@runner-mei
Copy link
Author

@runner-mei runner-mei commented Aug 4, 2015

Why not write error message into the http response.

@golang golang locked and limited conversation to collaborators Aug 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.