gitee.com/ks-custle/core-gm@v0.0.0-20230922171213-b83bdd97b62c/gmhttp/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 (
    10  	"io"
    11  
    12  	"gitee.com/ks-custle/core-gm/gmhttp/internal"
    13  )
    14  
    15  // NewChunkedReader returns a new chunkedReader that translates the data read from r
    16  // out of HTTP "chunked" format before returning it.
    17  // The chunkedReader returns io.EOF when the final 0-length chunk is read.
    18  //
    19  // NewChunkedReader is not needed by normal applications. The http package
    20  // automatically decodes chunking when reading response bodies.
    21  //
    22  //goland:noinspection GoUnusedExportedFunction
    23  func NewChunkedReader(r io.Reader) io.Reader {
    24  	return internal.NewChunkedReader(r)
    25  }
    26  
    27  // NewChunkedWriter returns a new chunkedWriter that translates writes into HTTP
    28  // "chunked" format before writing them to w. Closing the returned chunkedWriter
    29  // sends the final 0-length chunk that marks the end of the stream but does
    30  // not send the final CRLF that appears after trailers; trailers and the last
    31  // CRLF must be written separately.
    32  //
    33  // NewChunkedWriter is not needed by normal applications. The http
    34  // package adds chunking automatically if handlers don't set a
    35  // Content-Length header. Using NewChunkedWriter inside a handler
    36  // would result in double chunking or chunking with a Content-Length
    37  // length, both of which are wrong.
    38  func NewChunkedWriter(w io.Writer) io.WriteCloser {
    39  	return internal.NewChunkedWriter(w)
    40  }
    41  
    42  // ErrLineTooLong is returned when reading malformed chunked data
    43  // with lines that are too long.
    44  //
    45  //goland:noinspection GoUnusedGlobalVariable
    46  var ErrLineTooLong = internal.ErrLineTooLong