Standard library / net/http/httputil
httputil.NewClientConn()
Wrap an existing connection in the deprecated client connection API. Nil reader selects an internal buffered reader. Legacy-only: use net/http Client or Server for new code. Expected stdout: '0\n'.
Formal Syntax & Structure
go syntaxgo
func NewClientConn(c net.Conn, r *bufio.Reader) *ClientConnParameters & Attributes
| Name | Type | Description |
|---|---|---|
| c | net.Conn | Connection transferred to the legacy wrapper. |
| r | *bufio.Reader | Buffered reader or underlying stream as specified by its type; nil selects the default for legacy connections. |
Return Value
*ClientConn
Deprecated wrapper around the supplied connection.
Working Example
Example Snippetgo
package main
import ( "fmt" "net" "net/http/httputil" "time")
func main() { c, s := net.Pipe() defer c.Close() defer s.Close() check(c.SetDeadline(time.Now().Add(3 * time.Second))) check(s.SetDeadline(time.Now().Add(3 * time.Second))) cc := httputil.NewClientConn(c, nil) fmt.Println(cc.Pending()) check(cc.Close())}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}