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

fix: when multipartform no data,FormValue do not need panic #677

Merged
merged 1 commit into from
Oct 25, 2019

Conversation

alexDango
Copy link
Contributor

no need panic.

@alexDango alexDango changed the title fix: when multipartform no data,FormValue do not panic fix: when multipartform no data,FormValue do not need panic Oct 19, 2019
@erikdubbelboer
Copy link
Collaborator

I don't think this can ever happen? Can you add a test that panics before your change? Thanks.

@alexDango
Copy link
Contributor Author

alexDango commented Oct 23, 2019

sorry, i made a wrong description.
this panic always happen in my server, make my server restart always.

func TestClientGETNothingWithMultipartFormValue(t *testing.T) {
	t.Parallel()
	ln := fasthttputil.NewInmemoryListener()
	realPanic := "no"
	s := &Server{
		Handler: func(ctx *RequestCtx) {
			defer func() {
				if r := recover(); r != nil{
					realPanic = fmt.Sprintf("%v", r)
				}
			}()
			ctx.FormValue("a")
		},
	}
	go s.Serve(ln)

	c := &Client{
		Dial: func(addr string) (net.Conn, error) {
			return ln.Dial()
		},
	}
	req := AcquireRequest()
	res := AcquireResponse()

	req.SetRequestURI("http://example.com")
	req.Header.SetMethod(MethodGet)
	//this is use postman to start a request, use form-data
	req.Header.SetContentType("multipart/form-data;boundary=--------------------------530872294864144413907775")
	err := c.Do(req, res)
	if err != nil {
		t.Fatal(err)
	}
	if realPanic != "no" {
		t.Fatal("realPanic is: ",realPanic)
	}
} 

@erikdubbelboer erikdubbelboer merged commit 9bc6da1 into valyala:master Oct 25, 2019
@erikdubbelboer
Copy link
Collaborator

Thanks.

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

Successfully merging this pull request may close these issues.

2 participants