Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

ochttp.Handler.ServeHTTP func param r * http.Request did not modify r.MultipartForm correctly #1292

Open
voctior opened this issue Mar 16, 2023 · 3 comments
Labels

Comments

@voctior
Copy link

voctior commented Mar 16, 2023

Please answer these questions before submitting a bug report.

What version of OpenCensus are you using?

v0.24.0

What version of Go are you using?

go version go1.19.2 darwin/arm64

What did you do?

// ochttp
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var tags addedTags
// ----- shallow copy
r, traceEnd := h.startTrace(w, r)
defer traceEnd()
w, statsEnd := h.startStats(w, r)
defer statsEnd(&tags)
handler := h.Handler
if handler == nil {
handler = http.DefaultServeMux
}
// ----- shallow copy
r = r.WithContext(context.WithValue(r.Context(), addedTagsKey{}, &tags))
handler.ServeHTTP(w, r)
}

// std http
func (c *conn) serve(ctx context.Context){
// w.req has not change
serverHandler{c.server}.ServeHTTP(w, w.req)
w.finishRequest()
}

What did you expect to see?

w.req has changed

What did you see instead?

Additional context

Add any other context about the problem here.

@voctior voctior added the bug label Mar 16, 2023
@voctior
Copy link
Author

voctior commented Mar 16, 2023

i have a demo like this. I guess it's this mistake

import "testing"

type TT struct {
	t *TT
	c int
}

func TestXxx(t *testing.T) {
	var a = TT{t: &TT{c: 1}}
	A(a.t)
	if a.t.c != 2 {
		panic(a.t.c)
	}
	B(a.t)
	if a.t.c != 6 {
		panic(a.t.c)
	}
}

func A(in *TT) {
	in.c++
	in = &TT{c: 6}
}

func B(in *TT) {
	in.c = 6
}

test has no panic

@voctior
Copy link
Author

voctior commented Mar 16, 2023

I want to use response-finishRequest to delete locally mixed files .like this
image

@voctior
Copy link
Author

voctior commented Mar 17, 2023

fix like this?

// ochttp
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var tags addedTags
r2, traceEnd := h.startTrace(w, r)
defer traceEnd()
w, statsEnd := h.startStats(w, r2)
defer statsEnd(&tags)
handler := h.Handler
if handler == nil {
handler = http.DefaultServeMux
}
r2 = r2.WithContext(context.WithValue(r.2Context(), addedTagsKey{}, &tags))
// value copy
*r = *r2

handler.ServeHTTP(w, r)
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant