-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Align the semantics of http.request.size with http.response.size #7100
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
base: master
Are you sure you want to change the base?
Conversation
2. make metrics records accurate reqeust size by read from req.Body. ( metrics read from Content-Length field, which not applicable to web socket or chunked Body) 3. cache RequestRecorder to handle records in multiple moudles. ( logRequest and metrics creates its own ResponseRecorder.)
modules/caddyhttp/responsewriter.go
Outdated
Source io.ReadCloser | ||
Length int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just at first glance, is there any need for these fields to be exported? If not, could you lowercase them please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure.
There are 2 things that are unclear to me: |
modules/caddyhttp/responsewriter.go
Outdated
@@ -134,12 +141,27 @@ type responseRecorder struct { | |||
// As a special case, 1xx responses are not buffered nor recorded | |||
// because they are not the final response; they are passed through | |||
// directly to the underlying ResponseWriter. | |||
func NewResponseRecorder(w http.ResponseWriter, buf *bytes.Buffer, shouldBuffer ShouldBufferFunc) ResponseRecorder { | |||
return &responseRecorder{ | |||
func NewResponseRecorder(w http.ResponseWriter, req **http.Request, buf *bytes.Buffer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should/can change this signature at this point. I'm also not clear as to why this signature is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some thinking as below.
As for the import, it shocks me too🤣. It was mostly generated by the goland IDE. I am sorry I didn't check formattings before checking in. As for the double pointer, the http.Request.WithContext works in a immutable way, it should returns a new instance when change the context. It looks cohensive to make the change inside the c := context.WithValue(r.Context(), ResponseRecorderVarKey, rr)
*req = r.WithContext(c) A alternative way is to let the invoker to take care of the new r . The side effect is not obvious for the invoker(The input r changed??) func NewResponseRecorder(w http.ResponseWriter, req *http.Request, buf *bytes.Buffer,
shouldBuffer ShouldBufferFunc) (wrec ResponseRecorder, newReq *http.Request , cached bool)
// ....
wrec, r, cached := NewResponseRecorder(w, r, nil, nil) It's weird to input a double pointer but it's may get the invoker's attention as I had thought. What's your opinion on the alternatives ? |
2. do not export internal fields of lengthReader
I converted this PR to draft. During review the caching of |
This PR is for Issue #7087
lengthReader
as a member ofResponseRecorder
. it takes quite a time to understand when they separated and share a commonint
pointer.