fasthttp icon indicating copy to clipboard operation
fasthttp copied to clipboard

Request loses host information after calling RequestURI method

Open rbretecher-fcms opened this issue 5 years ago • 3 comments

Hello,

First, I would like to thank you for this awesome library.

I'm not sure if this is an issue but I noticed this. On the Request struct, il you call the RequestURI method, the Host method won't return anything after that.

It is really easy to reproduce :

package main

import (
	"github.com/valyala/fasthttp"
)

func main() {
	request := &fasthttp.Request{}
	request.SetRequestURI("http://example.com/test-1")

	println(string(request.Host()))
	println(string(request.RequestURI()))
	println(string(request.Host()))
}

This outpouts :

example.com
/test-1

As it should oupout in my opinion :

example.com
/test-1
example.com

For those who could experience the same issue, a workaround is to call instead :

request.URI().RequestURI()

But I would like to know if this is an issue or if this is the normal behavior. If this is the normal behavior, it should probably be documented :) Otherwise, I might be able to send you a PR to fix this if you want.

Thank you in advance for your help.

rbretecher-fcms avatar Oct 28 '20 16:10 rbretecher-fcms

This is indeed expected behavior. I don't like it either but we can't change it without breaking backwards compatibility. If you can make a pull request to document this behavior that would be great!

erikdubbelboer avatar Oct 29 '20 19:10 erikdubbelboer

Can we do a fasthttp1.1 then? to streamline all codes for consistency.

fasthttp2 will be for the https2 fasthttp3 will be for quic / http3

gitmko0 avatar Nov 07 '20 21:11 gitmko0

fasthttp is already at 1.17. This would be something for fasthttp2 if that ever comes.

erikdubbelboer avatar Nov 10 '20 10:11 erikdubbelboer