github.com/ader1990/go@v0.0.0-20140630135419-8c24447fa791/src/pkg/net/http/httputil/httputil.go (about)

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package httputil provides HTTP utility functions, complementing the
     6  // more common ones in the net/http package.
     7  package httputil
     8  
     9  import "io"
    10  
    11  // NewChunkedReader returns a new chunkedReader that translates the data read from r
    12  // out of HTTP "chunked" format before returning it.
    13  // The chunkedReader returns io.EOF when the final 0-length chunk is read.
    14  //
    15  // NewChunkedReader is not needed by normal applications. The http package
    16  // automatically decodes chunking when reading response bodies.
    17  func NewChunkedReader(r io.Reader) io.Reader {
    18  	return newChunkedReader(r)
    19  }
    20  
    21  // NewChunkedWriter returns a new chunkedWriter that translates writes into HTTP
    22  // "chunked" format before writing them to w. Closing the returned chunkedWriter
    23  // sends the final 0-length chunk that marks the end of the stream.
    24  //
    25  // NewChunkedWriter is not needed by normal applications. The http
    26  // package adds chunking automatically if handlers don't set a
    27  // Content-Length header. Using NewChunkedWriter inside a handler
    28  // would result in double chunking or chunking with a Content-Length
    29  // length, both of which are wrong.
    30  func NewChunkedWriter(w io.Writer) io.WriteCloser {
    31  	return newChunkedWriter(w)
    32  }