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: 403 return using JMeter #23251

Closed
XinhongWu opened this issue Dec 27, 2017 · 2 comments
Closed

x/net/websocket: 403 return using JMeter #23251

XinhongWu opened this issue Dec 27, 2017 · 2 comments

Comments

@XinhongWu
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.8.3 linux/amd64

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build244926751=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

I want to do websocket load test with JMeter.
My server code is as below:
`package main

import (
"golang.org/x/net/websocket"
"fmt"
"log"
"net/http"
)

func echoHandler(ws *websocket.Conn) {
msg := make([]byte, 512)
n, err := ws.Read(msg)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Receive: %s\n", msg[:n])

    send_msg := "[" + string(msg[:n]) + "]"
    m, err := ws.Write([]byte(send_msg))
    if err != nil {
            log.Fatal(err)
    }
    fmt.Printf("Send: %s\n", msg[:m])

}

func main() {
http.Handle("/echo", websocket.Handler(echoHandler))
http.Handle("/", http.FileServer(http.Dir(".")))

    err := http.ListenAndServe(":8080", nil)

    if err != nil {
            panic("ListenAndServe: " + err.Error())
    }

}
`
In JMeter,I have installed the websocket plugin according to the link:
https://www.blazemeter.com/blog/jmeter-websocket-samplers-a-practical-guide
When I want to do connect test , I set the configuration items:
Protocol: ws
ServeName Or IP: filled with my server address ipv4
Port:8080
Path: /echo

What did you expect to see?

JMeter show the connection is OK
a expample like:
`Thread Name: setUp Thread Group 1-1
Sample Start: 2017-12-27 09:33:25 CST
Load time: 103
Connect Time: 103
Latency: 0
Size in bytes: 129
Sent bytes:163
Headers size in bytes: 129
Body size in bytes: 0
Sample Count: 1
Error Count: 0
Data type ("text"|"bin"|""):
Response code: 101
Response message: Switching Protocols

Response headers:
Connection: Upgrade
Sec-WebSocket-Accept: +76XWcGrVMma7qmH7NbJCldDx1Y=
Upgrade: websocket

SampleResult fields:
ContentType:
DataEncoding: null`

What did you see instead?

Client receive 403 response
`Thread Name: setUp Thread Group 1-1
Sample Start: 2017-12-27 09:43:51 CST
Load time: 11
Connect Time: 0
Latency: 0
Size in bytes: 0
Sent bytes:0
Headers size in bytes: 0
Body size in bytes: 0
Sample Count: 1
Error Count: 1
Data type ("text"|"bin"|""):
Response code: 403
Response message: Http Upgrade failed with status code 403

Response headers:

SampleResult fields:
ContentType:
DataEncoding: null`

@gopherbot gopherbot added this to the Unreleased milestone Dec 27, 2017
@XinhongWu
Copy link
Author

At last I solved the problem using the following method:
details in the website:
https://stackoverflow.com/questions/19708330/serving-a-websocket-in-go
should disable the Origin check using the code like this:
http.HandleFunc("/echo",
func (w http.ResponseWriter, req *http.Request) {
s := websocket.Server{Handler: websocket.Handler(webHandler)}
s.ServeHTTP(w, req)
});
then the JMeter works OK

@XinhongWu XinhongWu changed the title x/net: websocket 403 return x/net: websocket 403 return using JMeter Dec 27, 2017
@bradfitz
Copy link
Contributor

Glad you got it working. In the future, for questions about Go, see https://golang.org/wiki/Questions.

@mikioh mikioh changed the title x/net: websocket 403 return using JMeter x/net/websocket: 403 return using JMeter Dec 27, 2017
@golang golang locked and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants