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/http: http request lost data when a lot of data is submitted from a form #14272

Closed
ghost opened this issue Feb 9, 2016 · 9 comments
Closed

Comments

@ghost
Copy link

ghost commented Feb 9, 2016

I have a template with multiple drop down lists in a form:

<form action="/orderinfo" method="post">

    <select name="Item">
      {{range .Items}}
        <option>{{.}}</option>
      {{end}}
    </select>

    <select name="Item">
      {{range .Items}}
        <option>{{.}}</option>
      {{end}}
    </select>

... a lot more of the same drop down list....

    <select name="Item">
      {{range .Items}}
        <option>{{.}}</option>
      {{end}}
    </select>

   <input type="submit" value="Save & Proceed">
 </form>

Where

Items: []string{"Apple", "Banana", "Orange", "Cabbage"},

The problem is, when I have 9 drop down lists, r.Form is

map[Item:[Apple Apple Apple Apple Apple Apple Apple Apple Apple]]

But when I have 10 or more drop down lists, r.Form becomes

map[]

p.s. This happens with Go 1.5.3

@ghost ghost changed the title http request lost data when a lot of data is submitted from a form net/http: http request lost data when a lot of data is submitted from a form Feb 9, 2016
@davecheney
Copy link
Contributor

Thank you for your report. There are several issues here, the first is the repeated values in the 9 value case and the missing value in the 10 value case.

Can you please provide a small runnable sample with a http handler and template that demonstrate this problem so we can investigate.

@bradfitz bradfitz added this to the Unplanned milestone Feb 9, 2016
@ghost
Copy link
Author

ghost commented Feb 9, 2016

Here is the link:

https://play.golang.org/p/ZUcoPCQKmK

Please copy and run on local machine with port 8080. It will print out r.Form after the button is clicked.

The above code has 2 drop down lists in the template, please copy and paste to more then 10 of them and you will see r.Form is empty.

Thanks!

@davecheney
Copy link
Contributor

Please check the error from your template executions. This is probably the
source of your error.

On Tue, 9 Feb 2016, 17:07 kyle11rd notifications@github.com wrote:

Here is the link:

https://play.golang.org/p/ZUcoPCQKmK

Please copy and run on local machine with port 8080. It will print out
r.Form after the button is clicked.

The above code has 2 drop down lists in the template, please copy and
paste to more then 10 of them and you will see r.Form is empty.

Thanks!


Reply to this email directly or view it on GitHub
#14272 (comment).

@davecheney
Copy link
Contributor

And the parse

On Tue, 9 Feb 2016, 17:10 Dave Cheney dave@cheney.net wrote:

Please check the error from your template executions. This is probably the
source of your error.

On Tue, 9 Feb 2016, 17:07 kyle11rd notifications@github.com wrote:

Here is the link:

https://play.golang.org/p/ZUcoPCQKmK

Please copy and run on local machine with port 8080. It will print out
r.Form after the button is clicked.

The above code has 2 drop down lists in the template, please copy and
paste to more then 10 of them and you will see r.Form is empty.

Thanks!


Reply to this email directly or view it on GitHub
#14272 (comment).

@ghost
Copy link
Author

ghost commented Feb 9, 2016

There are no errors from err functions. So I use "_" in this example.

@cespare
Copy link
Contributor

cespare commented Feb 9, 2016

@kyle11rd r.ParseForm() is returning a non-nil error that you're not checking.

@ghost
Copy link
Author

ghost commented Feb 9, 2016

https://play.golang.org/p/O0OqEkGFLI

Here I have included error checks, unfortunately no error on my side.

@cespare
Copy link
Contributor

cespare commented Feb 9, 2016

@kyle11rd no, you're not checking the ParseForm error, and it is not nil.

The problem is that you're reading the request body (with ParseForm) after you've written the response. You need to read first, then write.

@ghost
Copy link
Author

ghost commented Feb 9, 2016

!!!!!!!!!!!!!!!!!!!!!
You are right.. Never thought ParseForm can return this error:

http: invalid Read on closed Body

Strange that with only a few drop down lists no error is returned...

@ghost ghost closed this as completed Feb 9, 2016
@golang golang locked and limited conversation to collaborators Feb 28, 2017
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants