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

Is it possible to forward the client's response body to ctx response body? #807

Closed
dyrkin opened this issue May 11, 2020 · 1 comment
Closed

Comments

@dyrkin
Copy link

dyrkin commented May 11, 2020

Good day, guys,

Is it possible to forward the client's response body to ctx response body without reading it into memory?

I do HTTP requests from my go code when receiving external requests in RequestHandler.

var client *fasthttp.Client

func Handle(ctx *fasthttp.RequestCtx) {
	req := fasthttp.AcquireRequest()
	rsp := fasthttp.AcquireResponse()
	defer fasthttp.ReleaseRequest(req)
	defer fasthttp.ReleaseResponse(rsp)
	if err := client.Do(req, rsp); err !=nil {
		ctx.Response.SetStatusCode(fasthttp.StatusNotFound)
	}
	var body []byte
	body = append(body, rsp.Body()...) //need to copy it into a memory before exit the Handle function
	ctx.SetBody(body)
}

I would like to pass somehow rsp.Body() directly ctx.Response.
Thanks.

@erikdubbelboer
Copy link
Collaborator

I'm afraid not at the moment. fasthttp.Client will always read the whole body into memory. @kirillDanshin is working on changing this at #622

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