"hash/crc32"
"encoding/binary"
"io"
+ "io/ioutil"
"os"
)
r := io.NewSectionReader(f.zipr, off+f.bodyOffset, size)
switch f.Method {
case 0: // store (no compression)
- rc = nopCloser{r}
+ rc = ioutil.NopCloser(r)
case 8: // DEFLATE
rc = flate.NewReader(r)
default:
func (r *checksumReader) Close() os.Error { return r.rc.Close() }
-type nopCloser struct {
- io.Reader
-}
-
-func (f nopCloser) Close() os.Error { return nil }
-
func readFileHeader(f *File, r io.Reader) (err os.Error) {
defer func() {
if rerr, ok := recover().(os.Error); ok {
"fmt"
"http"
"io"
+ "io/ioutil"
"os"
"strconv"
"strings"
return nil, os.NewError("cgi: bad CONTENT_LENGTH in environment: " + lenstr)
}
r.ContentLength = clen
- r.Body = nopCloser{io.LimitReader(os.Stdin, clen)}
+ r.Body = ioutil.NopCloser(io.LimitReader(os.Stdin, clen))
}
// Copy "HTTP_FOO_BAR" variables to "Foo-Bar" Headers
return r, nil
}
-// TODO: move this to ioutil or something. It's copy/pasted way too often.
-type nopCloser struct {
- io.Reader
-}
-
-func (nopCloser) Close() os.Error { return nil }
-
// Serve executes the provided Handler on the currently active CGI
// request, if any. If there's no current CGI environment
// an error is returned. The provided handler may be nil to use
"encoding/base64"
"fmt"
"io"
+ "io/ioutil"
"os"
"strconv"
"strings"
req.ProtoMajor = 1
req.ProtoMinor = 1
req.Close = true
- req.Body = nopCloser{body}
+ req.Body = ioutil.NopCloser(body)
req.Header = Header{
"Content-Type": {bodyType},
}
req.ProtoMinor = 1
req.Close = true
body := urlencode(data)
- req.Body = nopCloser{body}
+ req.Body = ioutil.NopCloser(body)
req.Header = Header{
"Content-Type": {"application/x-www-form-urlencoded"},
"Content-Length": {strconv.Itoa(body.Len())},
}
return send(&req, c.Transport)
}
-
-type nopCloser struct {
- io.Reader
-}
-
-func (nopCloser) Close() os.Error { return nil }
import (
"bytes"
"io"
+ "io/ioutil"
"os"
)
-
// One of the copies, say from b to r2, could be avoided by using a more
// elaborate trick where the other copy is made during Request/Response.Write.
// This would complicate things too much, given that these functions are for
if err = b.Close(); err != nil {
return nil, nil, err
}
- return nopCloser{&buf}, nopCloser{bytes.NewBuffer(buf.Bytes())}, nil
+ return ioutil.NopCloser(&buf), ioutil.NopCloser(bytes.NewBuffer(buf.Bytes())), nil
}
// DumpRequest returns the wire representation of req,
import (
"bytes"
+ "io/ioutil"
"testing"
)
for i := range reqWriteTests {
tt := &reqWriteTests[i]
if tt.Body != nil {
- tt.Req.Body = nopCloser{bytes.NewBuffer(tt.Body)}
+ tt.Req.Body = ioutil.NopCloser(bytes.NewBuffer(tt.Body))
}
var braw bytes.Buffer
err := tt.Req.Write(&braw)
}
if tt.Body != nil {
- tt.Req.Body = nopCloser{bytes.NewBuffer(tt.Body)}
+ tt.Req.Body = ioutil.NopCloser(bytes.NewBuffer(tt.Body))
}
var praw bytes.Buffer
err = tt.Req.WriteProxy(&praw)
import (
"bytes"
+ "io/ioutil"
"testing"
)
ProtoMinor: 0,
RequestMethod: "GET",
Header: Header{},
- Body: nopCloser{bytes.NewBufferString("abcdef")},
+ Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")),
ContentLength: 6,
},
ProtoMinor: 0,
RequestMethod: "GET",
Header: Header{},
- Body: nopCloser{bytes.NewBufferString("abcdef")},
+ Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")),
ContentLength: -1,
},
"HTTP/1.0 200 OK\r\n" +
ProtoMinor: 1,
RequestMethod: "GET",
Header: Header{},
- Body: nopCloser{bytes.NewBufferString("abcdef")},
+ Body: ioutil.NopCloser(bytes.NewBufferString("abcdef")),
ContentLength: 6,
TransferEncoding: []string{"chunked"},
Close: true,
sort.Sort(fi)
return fi, nil
}
+
+type nopCloser struct {
+ io.Reader
+}
+
+func (nopCloser) Close() os.Error { return nil }
+
+// NopCloser returns a ReadCloser with a no-op Close method wrapping
+// the provided Reader r.
+func NopCloser(r io.Reader) io.ReadCloser {
+ return nopCloser{r}
+}