mime/multipart and HTTP multipart/form-data support
Somewhat of a work-in-progress (in that MIME is a large spec), but this is
functional and enough for discussion and/or code review.
In addition to the unit tests, I've tested with curl and Chrome with
a variety of test files, making sure the digests of files are unaltered
when read via a multipart Part.
Maybe my brain is too warped into only understanding git, but I can't figure out ...
13 years, 10 months ago
(2010-07-01 04:45:39 UTC)
#1
Maybe my brain is too warped into only understanding git, but I can't figure out
hg or rietveld enough to add this file to this change...
diff -r f050c0ef2f1a src/pkg/http/request.go
--- a/src/pkg/http/request.go Wed Jun 30 20:45:50 2010 -0700
+++ b/src/pkg/http/request.go Wed Jun 30 21:44:52 2010 -0700
@@ -16,6 +16,8 @@
"fmt"
"io"
"io/ioutil"
+ "mime/multipart"
+ "mime/contentdisposition"
"os"
"strconv"
"strings"
@@ -139,6 +141,24 @@
r.ProtoMajor == major && r.ProtoMinor >= minor
}
+// Returns a MIME multipart reader if this is a multipart/form-data POST
request,
+// else returns nil.
+func (r *Request) MultipartReader() multipart.Reader {
+ v, ok := r.Header["Content-Disposition"]
+ if !ok {
+ return nil
+ }
+ d, params := contentdisposition.Parse(v)
+ if d != "form-data" {
+ return nil
+ }
+ boundary, ok := params["boundary"]
+ if !ok {
+ return nil
+ }
+ return multipart.NewReader(r.Body, boundary)
+}
+
// Return value if nonempty, def otherwise.
func valueOrDefault(value, def string) string {
if value != "" {
Just one quick thought. Let's see what Russ/Andrew have to say. http://codereview.appspot.com/1681049/diff/1/4 File src/pkg/mime/contentdisposition/contentdisposition.go (right): ...
13 years, 10 months ago
(2010-07-01 05:11:10 UTC)
#3
Just one quick thought. Let's see what Russ/Andrew have to say.
http://codereview.appspot.com/1681049/diff/1/4
File src/pkg/mime/contentdisposition/contentdisposition.go (right):
http://codereview.appspot.com/1681049/diff/1/4#newcode5
src/pkg/mime/contentdisposition/contentdisposition.go:5: package
contentdisposition
This doesn't feel like it warrants its own package. I think it would be fine as
part of the MIME package (though still in its own file).
On 2010/07/01 05:11:10, dsymonds1 wrote: > src/pkg/mime/contentdisposition/contentdisposition.go:5: package > contentdisposition > This doesn't feel like ...
13 years, 10 months ago
(2010-07-02 04:25:55 UTC)
#4
On 2010/07/01 05:11:10, dsymonds1 wrote:
> src/pkg/mime/contentdisposition/contentdisposition.go:5: package
> contentdisposition
> This doesn't feel like it warrants its own package. I think it would be fine
as
> part of the MIME package (though still in its own file).
That's how I had it for awhile, but it made package mime look a little funny in
godoc, having two random unrelated methods. (mime type lookups and one random
parsing method...)
I'm happy to move it wherever, though.
I'm going to do more browser and MUA testing now, adding more unit tests and
bug/compatibility fixes as necessary, and start on MIME charset decoding next
probably.
I'd probably put contentdisposition stuff in mime under the assumption that it will have other ...
13 years, 10 months ago
(2010-07-03 00:12:16 UTC)
#5
I'd probably put contentdisposition stuff in mime
under the assumption that it will have other things too.
About to head out the door for a week but I'll have
another look when I get back.
Have fun.
Russ
On Thu, Jul 1, 2010 at 21:25, <bradfitz@gmail.com> wrote:
> On 2010/07/01 05:11:10, dsymonds1 wrote:
>>
>> src/pkg/mime/contentdisposition/contentdisposition.go:5: package
>> contentdisposition
>> This doesn't feel like it warrants its own package. I think it would
>
> be fine as
>>
>> part of the MIME package (though still in its own file).
>
> That's how I had it for awhile, but it made package mime look a little
> funny in godoc, having two random unrelated methods. (mime type lookups
> and one random parsing method...)
>
> I'm happy to move it wherever, though.
>
> I'm going to do more browser and MUA testing now, adding more unit tests
> and bug/compatibility fixes as necessary, and start on MIME charset
> decoding next probably.
>
> http://codereview.appspot.com/1681049/show
>
Will address agl's comments in next CL. Most recent update was only cleaning up Makefiles ...
13 years, 9 months ago
(2010-07-07 15:40:01 UTC)
#15
Will address agl's comments in next CL. Most recent update was only
cleaning up Makefiles so all.bash and deps.bash would play together nicely.
On Wed, Jul 7, 2010 at 8:37 AM, <bradfitz@gmail.com> wrote:
> Hello rsc, adg, dsymonds1, agl1 (cc: golang-dev@googlegroups.com),
>
> Please take another look.
>
>
> http://codereview.appspot.com/1681049/show
>
On 2010/07/12 19:50:10, rsc1 wrote: > looks pretty good; thanks for tackling this. > a ...
13 years, 9 months ago
(2010-07-13 01:04:30 UTC)
#22
On 2010/07/12 19:50:10, rsc1 wrote:
> looks pretty good; thanks for tackling this.
> a bunch of comment style nits below.
> the recurring one is that unlike typical c++ or java
> conventions, the doc comments should be full
> sentences beginning with the function being
> described, to admit a variety of presentation formats.
Gotcha. Okay, all those comments addressed (locally). Let me do another read
over it all to make sure they're all in that style and then I'll upload again.
not sure how this slipped past the codereview extension on your side, but grammar.go is ...
13 years, 9 months ago
(2010-07-14 16:36:33 UTC)
#25
not sure how this slipped past the codereview
extension on your side, but grammar.go is not
gofmt'ed. please run
hg gofmt
hg mail 1681049
thanks. i could do it locally before submitting
but you'll get a merge conflict if i do.
russ
Oh, hg mail did show the warning about gofmt on that file it turns out, ...
13 years, 9 months ago
(2010-07-14 19:28:17 UTC)
#27
Oh, hg mail did show the warning about gofmt on that file it turns out, but
I'd apparently not seen it at the time.
Fixed and remailed.
On Wed, Jul 14, 2010 at 9:36 AM, Russ Cox <rsc@golang.org> wrote:
> not sure how this slipped past the codereview
> extension on your side, but grammar.go is not
> gofmt'ed. please run
>
> hg gofmt
> hg mail 1681049
>
> thanks. i could do it locally before submitting
> but you'll get a merge conflict if i do.
>
> russ
>
*** Submitted as http://code.google.com/p/go/source/detail?r=4ab63d961945 *** mime/multipart and HTTP multipart/form-data support Somewhat of a work-in-progress (in ...
13 years, 9 months ago
(2010-07-15 00:26:17 UTC)
#28
*** Submitted as http://code.google.com/p/go/source/detail?r=4ab63d961945 ***
mime/multipart and HTTP multipart/form-data support
Somewhat of a work-in-progress (in that MIME is a large spec), but this is
functional and enough for discussion and/or code review.
In addition to the unit tests, I've tested with curl and Chrome with
a variety of test files, making sure the digests of files are unaltered
when read via a multipart Part.
R=rsc, adg, dsymonds1, agl1
CC=golang-dev
http://codereview.appspot.com/1681049
Committer: Russ Cox <rsc@golang.org>
Issue 1681049: code review 1681049: mime/multipart and HTTP multipart/form-data support
(Closed)
Created 13 years, 10 months ago by brad_danga_com
Modified 13 years, 9 months ago
Reviewers:
Base URL:
Comments: 58