mirror of
https://github.com/golang/go
synced 2024-11-19 06:34:42 -07:00
undo CL 95760043 / b2131d729e52
Breaks Camlistore by introducing a datarace. See comments on https://golang.org/cl/95760043/ for details. I'll add a new test to lock-in the current behavior in a subsequent CL. I don't think Camlistore is particularly unique here: it's doing the obvious thing to stream a multipart body to a server using a goroutine feeding the multipart writer. ««« original CL description mime/multipart: delay reading random source If a user sets his/her own boundary string with SetBoundary, we don't need to call randomBoundary at all. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/95760043 »»» LGTM=ruiu R=ruiu CC=golang-codereviews, mathieu.lonjaret https://golang.org/cl/117600043
This commit is contained in:
parent
d0e255f259
commit
dab671b660
@ -25,15 +25,13 @@ type Writer struct {
|
|||||||
// writing to w.
|
// writing to w.
|
||||||
func NewWriter(w io.Writer) *Writer {
|
func NewWriter(w io.Writer) *Writer {
|
||||||
return &Writer{
|
return &Writer{
|
||||||
w: w,
|
w: w,
|
||||||
|
boundary: randomBoundary(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Boundary returns the Writer's boundary.
|
// Boundary returns the Writer's boundary.
|
||||||
func (w *Writer) Boundary() string {
|
func (w *Writer) Boundary() string {
|
||||||
if w.boundary == "" {
|
|
||||||
w.boundary = randomBoundary()
|
|
||||||
}
|
|
||||||
return w.boundary
|
return w.boundary
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +65,7 @@ func (w *Writer) SetBoundary(boundary string) error {
|
|||||||
// FormDataContentType returns the Content-Type for an HTTP
|
// FormDataContentType returns the Content-Type for an HTTP
|
||||||
// multipart/form-data with this Writer's Boundary.
|
// multipart/form-data with this Writer's Boundary.
|
||||||
func (w *Writer) FormDataContentType() string {
|
func (w *Writer) FormDataContentType() string {
|
||||||
return "multipart/form-data; boundary=" + w.Boundary()
|
return "multipart/form-data; boundary=" + w.boundary
|
||||||
}
|
}
|
||||||
|
|
||||||
func randomBoundary() string {
|
func randomBoundary() string {
|
||||||
@ -91,9 +89,9 @@ func (w *Writer) CreatePart(header textproto.MIMEHeader) (io.Writer, error) {
|
|||||||
}
|
}
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
if w.lastpart != nil {
|
if w.lastpart != nil {
|
||||||
fmt.Fprintf(&b, "\r\n--%s\r\n", w.Boundary())
|
fmt.Fprintf(&b, "\r\n--%s\r\n", w.boundary)
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(&b, "--%s\r\n", w.Boundary())
|
fmt.Fprintf(&b, "--%s\r\n", w.boundary)
|
||||||
}
|
}
|
||||||
// TODO(bradfitz): move this to textproto.MimeHeader.Write(w), have it sort
|
// TODO(bradfitz): move this to textproto.MimeHeader.Write(w), have it sort
|
||||||
// and clean, like http.Header.Write(w) does.
|
// and clean, like http.Header.Write(w) does.
|
||||||
@ -159,7 +157,7 @@ func (w *Writer) Close() error {
|
|||||||
}
|
}
|
||||||
w.lastpart = nil
|
w.lastpart = nil
|
||||||
}
|
}
|
||||||
_, err := fmt.Fprintf(w.w, "\r\n--%s--\r\n", w.Boundary())
|
_, err := fmt.Fprintf(w.w, "\r\n--%s--\r\n", w.boundary)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user