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

2023/05/19 20:21:07.463055 server.go:1928: [Error] HERTZ: HTTP2: write response body error when serving 123.123.123.123:63047: http: request method or response status code does not allow body #786

Closed
kolinfluence opened this issue May 19, 2023 · 16 comments
Labels
invalid issue invalid issue (not related to Hertz or described in document or not enough information provided) stale

Comments

@kolinfluence
Copy link

cannot set "consts.StatusNotModified"
how do set status not modified correctly?
using h2 and latest hertz.

how do i "delete" response body then? if the below is correct?

func CtxStatusNotModified(ctx *app.RequestContext) {
	ctx.SetStatusCode(consts.StatusNotModified)
	//with or without below line doesnt work
	//ctx.Response.Header.Set("Cache-Control", "no-transform") 
}
@kolinfluence kolinfluence changed the title 2023/05/19 20:21:07.463055 server.go:1928: [Error] HERTZ: HTTP2: write response body error when serving 180.74.224.229:63047: http: request method or response status code does not allow body 2023/05/19 20:21:07.463055 server.go:1928: [Error] HERTZ: HTTP2: write response body error when serving 123.123.123.123:63047: http: request method or response status code does not allow body May 19, 2023
@github-actions github-actions bot added the invalid issue invalid issue (not related to Hertz or described in document or not enough information provided) label May 19, 2023
@github-actions
Copy link

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 3 days if no further activity occurs.

@github-actions github-actions bot added the stale label May 19, 2023
@rogerogers
Copy link
Contributor

Please optimize the title to accurately reflect the gist of a problem, rather than being a log.

@rogerogers
Copy link
Contributor

Please give more information by following the issue template, help us better understand the problem.

@github-actions github-actions bot removed the stale label May 20, 2023
@github-actions
Copy link

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 3 days if no further activity occurs.

@rogerogers
Copy link
Contributor

It seems to be an issue with the http2 repository.

@github-actions github-actions bot removed the stale label May 20, 2023
@github-actions
Copy link

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 3 days if no further activity occurs.

@github-actions github-actions bot added the stale label May 20, 2023
@kolinfluence
Copy link
Author

@rogerogers @Duslia
what more information do you need? i think @Duslia will know and can solve this.

try doing this, return this will get error with h2 usage.
basically you cant return statusnotmodified without showing errors. because somehow it is setting the body or something when no body was set at all.

func CtxStatusNotModified(ctx *app.RequestContext) {
	ctx.SetStatusCode(consts.StatusNotModified)
	//with or without below line doesnt work
	//ctx.Response.Header.Set("Cache-Control", "no-transform") 
}

@kolinfluence
Copy link
Author

kolinfluence commented May 20, 2023

oops, i think i should use

ctx.Response.SetStatusCode(consts.StatusNotModified)

right? :D
will close this after testing. sorry

is there a difference between
a) ctx.Response.SetStatusCode(consts.StatusNotModified)
b) ctx.Response.Header.SetStatusCode(consts.StatusNotModified)
?

@kolinfluence
Copy link
Author

@li-jin-gou @Duslia @rogerogers
problem is still around whether i put ctx.SetStatusCode or ctx.Response.SetStatusCode or whatever
pls check the title and test what i mean. thx

@github-actions github-actions bot removed the stale label May 20, 2023
@github-actions
Copy link

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 3 days if no further activity occurs.

@github-actions github-actions bot added the stale label May 20, 2023
@kolinfluence
Copy link
Author

kolinfluence commented May 20, 2023

@Duslia , @li-jin-gou , @rogerogers
line 1922 gives 1928 error if ctx Status return code is 304 notmodified for:
https://github.com/hertz-contrib/http2
server.go file

                rw.WriteHeader(reqCtx.Response.StatusCode())
                err = writeResponseBody(rw, reqCtx) //SET BODY HERE WILL ERROR FOR status 304 etc! 
                //those without bodies! BUT... come to think of it, 
                //it should be OK to have custom body for any status. 
                //so i think should fix the code internal.

pls check. not sure how u would like to resolve this. maybe if status 304 (or all other statuses that does not have body) dont set body?

pls help fix this. thx

// Run on its own goroutine.
func (sc *serverConn) runHandler(rw *responseWriter, reqCtx *app.RequestContext, handler app.HandlerFunc) {
        didPanic := true
        defer func() {
                var err error

                defer func() {
                        if reqCtx.IsEnableTrace() {
                                Record(reqCtx.GetTraceInfo(), stats.ServerHandleFinish, err)
                        }
                }()

                if didPanic {
                        e := recover()
                        sc.writeFrameFromHandler(FrameWriteRequest{
                                write:  handlerPanicRST{rw.rws.stream.id},
                                stream: rw.rws.stream,
                        })
                        // Same as net/http:
                        if e != nil && e != http.ErrAbortHandler {
                                const size = 64 << 10
                                buf := make([]byte, size)
                                buf = buf[:runtime.Stack(buf, false)]
                                err = fmt.Errorf("HTTP2: panic serving %v: %v\n%s", sc.conn.RemoteAddr(), e, buf)
                                hlog.SystemLogger().Error(err.Error())
                        }
                        return
                }

                if writer := reqCtx.Response.GetHijackWriter(); writer != nil {
                        writer.Finalize()
                        return
                }

                rw.WriteHeader(reqCtx.Response.StatusCode())
                err = writeResponseBody(rw, reqCtx)
                if err != nil {
                        sc.writeFrameFromHandler(FrameWriteRequest{
                                write:  handlerPanicRST{rw.rws.stream.id},
                                stream: rw.rws.stream,
                        })
                        hlog.SystemLogger().Errorf("HTTP2: write response body error when serving %v: %v", sc.conn.RemoteAddr(), err)
                        return
                }

                rw.handlerDone()
        }()
        if reqCtx.IsEnableTrace() {
                Record(reqCtx.GetTraceInfo(), stats.ServerHandleStart, nil)
        }
        handler(rw.rws.stream.baseCtx, reqCtx)

        didPanic = false
}

@github-actions
Copy link

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 3 days if no further activity occurs.

@github-actions github-actions bot added stale and removed stale labels May 20, 2023
@github-actions
Copy link

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 3 days if no further activity occurs.

@github-actions github-actions bot added the stale label May 21, 2023
@li-jin-gou
Copy link
Member

Please follow the template and fill in the questions as others have done to help understand the questions and the issue will not be actively closed and refer to https://github.com/cloudwego/hertz/issues

@github-actions github-actions bot removed the stale label May 21, 2023
@github-actions
Copy link

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 3 days if no further activity occurs.

@github-actions github-actions bot added the stale label May 21, 2023
@kolinfluence
Copy link
Author

@li-jin-gou close this and reopened as you have suggested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid issue invalid issue (not related to Hertz or described in document or not enough information provided) stale
Development

No branches or pull requests

3 participants