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

net/ghttp: MiddlewareHandlerResponse writes additional information #4108

Open
wlynxg opened this issue Jan 9, 2025 · 2 comments · May be fixed by #4109
Open

net/ghttp: MiddlewareHandlerResponse writes additional information #4108

wlynxg opened this issue Jan 9, 2025 · 2 comments · May be fixed by #4109
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@wlynxg
Copy link
Contributor

wlynxg commented Jan 9, 2025

Go version

go version go1.20.6 linux/amd64

GoFrame version

v2.8.3

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

package main

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
)

func main() {
	s := g.Server()
	s.Use(ghttp.MiddlewareHandlerResponse)
	s.BindHandler("/", func(r *ghttp.Request) {
		r.Response.Writer.Write([]byte("hello world"))
	})
	s.SetPort(8081)
	s.Run()
}

What did you see happen?

response: hello world{"code":0,"message":"","data":null}

What did you expect to see?

Before 2.7.0, it was: hello world

@wlynxg wlynxg added the bug It is confirmed a bug, but don't worry, we'll handle it. label Jan 9, 2025
@ninjashixuan
Copy link
Contributor

没用过 2.7以前的版本, 应该是直接调用r.Response.Writer.Write 而不是 r.Response.Write(这个有 buffer) 意味着没有中间件的Bufferlen 方法判断哪里还可以往下走。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I have never used versions before 2.7. You should call r.Response.Writer.Write directly instead of r.Response.Write (this one has buffer), which means there is no middleware Bufferlen method to determine where to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants