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

why ctx.Request.URI().RequestURI() is missing? #597

Closed
59duncom opened this issue Jul 2, 2019 · 5 comments
Closed

why ctx.Request.URI().RequestURI() is missing? #597

59duncom opened this issue Jul 2, 2019 · 5 comments

Comments

@59duncom
Copy link

59duncom commented Jul 2, 2019

I had write a websocket proxy,but ctx.requesturi is miss and fmt.Println( ctx.Request.String()) is ok:

func Proxyhttp(ctx *fasthttp.RequestCtx){

fmt.Println( string(ctx.RequestURI())) //here is ok
if websocket.FastHTTPIsWebSocketUpgrade(ctx){
Dowebsocket(ctx, clientproxy.source)

}
}
func Dowebsocket( ctx *fasthttp.RequestCtx,sourcestr string){
upgrader := websocket.FastHTTPUpgrader{HandshakeTimeout: 15 * time.Second, CheckOrigin:func(ctx *fasthttp.RequestCtx) bool { return true }, }
upgrader.Upgrade(ctx,func(ws *websocket.Conn) {
wsURL := url.URL{Scheme: "ws", Host: sourcestr, Path:string(ctx.RequestURI())) }//here is miss
fmt.Println(string(ctx.URI().RequestURI())) //here is miss
dialer := websocket.Dialer{
Proxy: http.ProxyFromEnvironment,
HandshakeTimeout: 15 * time.Second,
}
server, _, err := dialer.Dial(wsURL.String(), nil)
...................
}

@59duncom
Copy link
Author

59duncom commented Jul 2, 2019

first ctx.RequestURI() is "/echo" ,missing is print "/"

@dgrr
Copy link
Contributor

dgrr commented Jul 2, 2019

Maybe there is any problem before you print the request URI.
As I checked by making a simple program which prints the ctx.URI().RequestURI() it should work. So I think maybe the websocket library is modifying the request uri or something else. Not a fasthttp issue

image

@59duncom
Copy link
Author

59duncom commented Jul 2, 2019

I had use "github.com/fasthttp/websocket"for websocket
I will write a demo and test

@dgrr
Copy link
Contributor

dgrr commented Jul 2, 2019

Ah, yep, I know where the error is. https://github.com/valyala/fasthttp/blob/master/server.go#L2063
The RequestCtx is reset when a connection is Hijacked.

@59duncom
Copy link
Author

59duncom commented Jul 2, 2019

ok thanks

@59duncom 59duncom closed this as completed Jul 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants