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 there a way to change Response.Body() without memory copying? #1600

Open
hiqsociety opened this issue Aug 1, 2023 · 1 comment
Open

Comments

@hiqsociety
Copy link

hiqsociety commented Aug 1, 2023

i'm using minify https://github.com/tdewolff/minify to minify ctx.Response.Body() but trying to reduce GC pressure by doing arena but was wondering if i can just somehow modify the Response Body w/o mem copying... which will be better. is this possible?

mem := arena.NewArena()
o := arena.New[H](mem)

o.Data, o.Err = m.Bytes("text/html", ctx.Response.Body()) //minified here
if o.Err != nil {
	log.Printf("minify1 %s", o.Err)
} else {
	log.Printf("o.Data = %s", o.Data)
	ctx.Response.SetBody(o.Data)
}
ctx.Response.Header.SetStatusCode(200)
ctx.Response.Header.SetContentType("text/html")
mem.Free()
@erikdubbelboer
Copy link
Collaborator

Have you tried using Response.SetBodyRaw?

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