2 <!-- saved from url=(0032)https://golang.org/pkg/net/http/ -->
3 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1">
6 <meta name="theme-color" content="#375EAB">
8 <title>http - The Go Programming Language</title>
10 <link type="text/css" rel="stylesheet" href="./http - The Go Programming Language_files/style.css">
12 <link rel="search" type="application/opensearchdescription+xml" title="godoc" href="https://golang.org/opensearch.xml">
14 <link rel="stylesheet" href="./http - The Go Programming Language_files/jquery.treeview.css">
15 <script type="text/javascript" async="" src="./http - The Go Programming Language_files/ga.js"></script><script type="text/javascript">window.initFuncs = [];</script>
16 <script type="text/javascript">
17 var _gaq = _gaq || [];
18 _gaq.push(["_setAccount", "UA-11222381-2"]);
19 _gaq.push(["b._setAccount", "UA-49880327-6"]);
20 window.trackPageview = function() {
21 _gaq.push(["_trackPageview", location.pathname+location.hash]);
22 _gaq.push(["b._trackPageview", location.pathname+location.hash]);
24 window.trackPageview();
25 window.trackEvent = function(category, action, opt_label, opt_value, opt_noninteraction) {
26 _gaq.push(["_trackEvent", category, action, opt_label, opt_value, opt_noninteraction]);
27 _gaq.push(["b._trackEvent", category, action, opt_label, opt_value, opt_noninteraction]);
33 <div id="lowframe" style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
35 </div><!-- #lowframe -->
37 <div id="topbar" class="wide"><div class="container">
38 <div class="top-heading" id="heading-wide"><a href="https://golang.org/">The Go Programming Language</a></div>
39 <div class="top-heading" id="heading-narrow"><a href="https://golang.org/">Go</a></div>
40 <a href="https://golang.org/pkg/net/http/#" id="menu-button"><span id="menu-button-arrow">▽</span></a>
41 <form method="GET" action="https://golang.org/search">
42 <div id="menu" style="min-width: 60px;">
43 <a href="https://golang.org/doc/">Documents</a>
44 <a href="https://golang.org/pkg/">Packages</a>
45 <a href="https://golang.org/project/">The Project</a>
46 <a href="https://golang.org/help/">Help</a>
47 <a href="https://golang.org/blog/">Blog</a>
49 <a id="playgroundButton" href="http://play.golang.org/" title="Show Go Playground" style="display: inline;">Play</a>
51 <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
58 <div id="playground" class="play">
59 <div class="input"><textarea class="code">package main
64 fmt.Println("Hello, 世界")
66 <div class="output"></div>
68 <a class="run" title="Run this code [shift-enter]">Run</a>
69 <a class="fmt" title="Format this code">Format</a>
75 <div id="page" class="wide" tabindex="-1" style="outline: 0px;">
76 <div class="container">
88 Copyright 2009 The Go Authors. All rights reserved.
89 Use of this source code is governed by a BSD-style
90 license that can be found in the LICENSE file.
93 Note: Static (i.e., not template-generated) href and id
94 attributes start with "pkg-" to make it impossible for
95 them to conflict with generated attributes (some of which
96 correspond to Go identifiers).
99 <script type="text/javascript">
100 document.ANALYSIS_DATA = null;
101 document.CALLGRAPH = null;
108 <dd><code>import "net/http"</code></dd>
111 <dd><a href="https://golang.org/pkg/net/http/#pkg-overview" class="overviewLink">Overview</a></dd>
112 <dd><a href="https://golang.org/pkg/net/http/#pkg-index" class="indexLink">Index</a></dd>
114 <dd><a href="https://golang.org/pkg/net/http/#pkg-examples" class="examplesLink">Examples</a></dd>
117 <dd><a href="https://golang.org/pkg/net/http/#pkg-subdirectories">Subdirectories</a></dd>
121 <!-- The package's Name is printed as title by the top-level template -->
122 <div id="pkg-overview" class="toggleVisible">
123 <div class="collapsed">
124 <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
126 <div class="expanded">
127 <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
129 Package http provides HTTP client and server implementations.
132 Get, Head, Post, and PostForm make HTTP (or HTTPS) requests:
134 <pre>resp, err := http.Get("<a href="http://example.com/">http://example.com/</a>")
136 resp, err := http.Post("<a href="http://example.com/upload">http://example.com/upload</a>", "image/jpeg", &buf)
138 resp, err := http.PostForm("<a href="http://example.com/form">http://example.com/form</a>",
139 url.Values{"key": {"Value"}, "id": {"123"}})
142 The client must close the response body when finished with it:
144 <pre>resp, err := http.Get("<a href="http://example.com/">http://example.com/</a>")
148 defer resp.Body.Close()
149 body, err := ioutil.ReadAll(resp.Body)
153 For control over HTTP client headers, redirect policy, and other
154 settings, create a Client:
156 <pre>client := &http.Client{
157 CheckRedirect: redirectPolicyFunc,
160 resp, err := client.Get("<a href="http://example.com/">http://example.com</a>")
163 req, err := http.NewRequest("GET", "<a href="http://example.com/">http://example.com</a>", nil)
165 req.Header.Add("If-None-Match", `W/"wyzzy"`)
166 resp, err := client.Do(req)
170 For control over proxies, TLS configuration, keep-alives,
171 compression, and other settings, create a Transport:
173 <pre>tr := &http.Transport{
174 TLSClientConfig: &tls.Config{RootCAs: pool},
175 DisableCompression: true,
177 client := &http.Client{Transport: tr}
178 resp, err := client.Get("<a href="https://example.com/">https://example.com</a>")
181 Clients and Transports are safe for concurrent use by multiple
182 goroutines and for efficiency should only be created once and re-used.
185 ListenAndServe starts an HTTP server with a given address and handler.
186 The handler is usually nil, which means to use DefaultServeMux.
187 Handle and HandleFunc add handlers to DefaultServeMux:
189 <pre>http.Handle("/foo", fooHandler)
191 http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
192 fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
195 log.Fatal(http.ListenAndServe(":8080", nil))
198 More control over the server's behavior is available by creating a
201 <pre>s := &http.Server{
204 ReadTimeout: 10 * time.Second,
205 WriteTimeout: 10 * time.Second,
206 MaxHeaderBytes: 1 << 20,
208 log.Fatal(s.ListenAndServe())
215 <div id="pkg-index" class="toggleVisible">
216 <div class="collapsed">
217 <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
219 <div class="expanded">
220 <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
222 <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
223 <div id="manual-nav">
226 <dd><a href="https://golang.org/pkg/net/http/#pkg-constants">Constants</a></dd>
229 <dd><a href="https://golang.org/pkg/net/http/#pkg-variables">Variables</a></dd>
233 <dd><a href="https://golang.org/pkg/net/http/#CanonicalHeaderKey">func CanonicalHeaderKey(s string) string</a></dd>
236 <dd><a href="https://golang.org/pkg/net/http/#DetectContentType">func DetectContentType(data []byte) string</a></dd>
239 <dd><a href="https://golang.org/pkg/net/http/#Error">func Error(w ResponseWriter, error string, code int)</a></dd>
242 <dd><a href="https://golang.org/pkg/net/http/#Handle">func Handle(pattern string, handler Handler)</a></dd>
245 <dd><a href="https://golang.org/pkg/net/http/#HandleFunc">func HandleFunc(pattern string, handler func(ResponseWriter, *Request))</a></dd>
248 <dd><a href="https://golang.org/pkg/net/http/#ListenAndServe">func ListenAndServe(addr string, handler Handler) error</a></dd>
251 <dd><a href="https://golang.org/pkg/net/http/#ListenAndServeTLS">func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler) error</a></dd>
254 <dd><a href="https://golang.org/pkg/net/http/#MaxBytesReader">func MaxBytesReader(w ResponseWriter, r io.ReadCloser, n int64) io.ReadCloser</a></dd>
257 <dd><a href="https://golang.org/pkg/net/http/#NotFound">func NotFound(w ResponseWriter, r *Request)</a></dd>
260 <dd><a href="https://golang.org/pkg/net/http/#ParseHTTPVersion">func ParseHTTPVersion(vers string) (major, minor int, ok bool)</a></dd>
263 <dd><a href="https://golang.org/pkg/net/http/#ParseTime">func ParseTime(text string) (t time.Time, err error)</a></dd>
266 <dd><a href="https://golang.org/pkg/net/http/#ProxyFromEnvironment">func ProxyFromEnvironment(req *Request) (*url.URL, error)</a></dd>
269 <dd><a href="https://golang.org/pkg/net/http/#ProxyURL">func ProxyURL(fixedURL *url.URL) func(*Request) (*url.URL, error)</a></dd>
272 <dd><a href="https://golang.org/pkg/net/http/#Redirect">func Redirect(w ResponseWriter, r *Request, urlStr string, code int)</a></dd>
275 <dd><a href="https://golang.org/pkg/net/http/#Serve">func Serve(l net.Listener, handler Handler) error</a></dd>
278 <dd><a href="https://golang.org/pkg/net/http/#ServeContent">func ServeContent(w ResponseWriter, req *Request, name string, modtime time.Time, content io.ReadSeeker)</a></dd>
281 <dd><a href="https://golang.org/pkg/net/http/#ServeFile">func ServeFile(w ResponseWriter, r *Request, name string)</a></dd>
284 <dd><a href="https://golang.org/pkg/net/http/#SetCookie">func SetCookie(w ResponseWriter, cookie *Cookie)</a></dd>
287 <dd><a href="https://golang.org/pkg/net/http/#StatusText">func StatusText(code int) string</a></dd>
291 <dd><a href="https://golang.org/pkg/net/http/#Client">type Client</a></dd>
295 <dd> <a href="https://golang.org/pkg/net/http/#Client.Do">func (c *Client) Do(req *Request) (resp *Response, err error)</a></dd>
298 <dd> <a href="https://golang.org/pkg/net/http/#Client.Get">func (c *Client) Get(url string) (resp *Response, err error)</a></dd>
301 <dd> <a href="https://golang.org/pkg/net/http/#Client.Head">func (c *Client) Head(url string) (resp *Response, err error)</a></dd>
304 <dd> <a href="https://golang.org/pkg/net/http/#Client.Post">func (c *Client) Post(url string, bodyType string, body io.Reader) (resp *Response, err error)</a></dd>
307 <dd> <a href="https://golang.org/pkg/net/http/#Client.PostForm">func (c *Client) PostForm(url string, data url.Values) (resp *Response, err error)</a></dd>
311 <dd><a href="https://golang.org/pkg/net/http/#CloseNotifier">type CloseNotifier</a></dd>
316 <dd><a href="https://golang.org/pkg/net/http/#ConnState">type ConnState</a></dd>
320 <dd> <a href="https://golang.org/pkg/net/http/#ConnState.String">func (c ConnState) String() string</a></dd>
324 <dd><a href="https://golang.org/pkg/net/http/#Cookie">type Cookie</a></dd>
328 <dd> <a href="https://golang.org/pkg/net/http/#Cookie.String">func (c *Cookie) String() string</a></dd>
332 <dd><a href="https://golang.org/pkg/net/http/#CookieJar">type CookieJar</a></dd>
337 <dd><a href="https://golang.org/pkg/net/http/#Dir">type Dir</a></dd>
341 <dd> <a href="https://golang.org/pkg/net/http/#Dir.Open">func (d Dir) Open(name string) (File, error)</a></dd>
345 <dd><a href="https://golang.org/pkg/net/http/#File">type File</a></dd>
350 <dd><a href="https://golang.org/pkg/net/http/#FileSystem">type FileSystem</a></dd>
355 <dd><a href="https://golang.org/pkg/net/http/#Flusher">type Flusher</a></dd>
360 <dd><a href="https://golang.org/pkg/net/http/#Handler">type Handler</a></dd>
363 <dd> <a href="https://golang.org/pkg/net/http/#FileServer">func FileServer(root FileSystem) Handler</a></dd>
366 <dd> <a href="https://golang.org/pkg/net/http/#NotFoundHandler">func NotFoundHandler() Handler</a></dd>
369 <dd> <a href="https://golang.org/pkg/net/http/#RedirectHandler">func RedirectHandler(url string, code int) Handler</a></dd>
372 <dd> <a href="https://golang.org/pkg/net/http/#StripPrefix">func StripPrefix(prefix string, h Handler) Handler</a></dd>
375 <dd> <a href="https://golang.org/pkg/net/http/#TimeoutHandler">func TimeoutHandler(h Handler, dt time.Duration, msg string) Handler</a></dd>
380 <dd><a href="https://golang.org/pkg/net/http/#HandlerFunc">type HandlerFunc</a></dd>
384 <dd> <a href="https://golang.org/pkg/net/http/#HandlerFunc.ServeHTTP">func (f HandlerFunc) ServeHTTP(w ResponseWriter, r *Request)</a></dd>
388 <dd><a href="https://golang.org/pkg/net/http/#Header">type Header</a></dd>
392 <dd> <a href="https://golang.org/pkg/net/http/#Header.Add">func (h Header) Add(key, value string)</a></dd>
395 <dd> <a href="https://golang.org/pkg/net/http/#Header.Del">func (h Header) Del(key string)</a></dd>
398 <dd> <a href="https://golang.org/pkg/net/http/#Header.Get">func (h Header) Get(key string) string</a></dd>
401 <dd> <a href="https://golang.org/pkg/net/http/#Header.Set">func (h Header) Set(key, value string)</a></dd>
404 <dd> <a href="https://golang.org/pkg/net/http/#Header.Write">func (h Header) Write(w io.Writer) error</a></dd>
407 <dd> <a href="https://golang.org/pkg/net/http/#Header.WriteSubset">func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) error</a></dd>
411 <dd><a href="https://golang.org/pkg/net/http/#Hijacker">type Hijacker</a></dd>
416 <dd><a href="https://golang.org/pkg/net/http/#ProtocolError">type ProtocolError</a></dd>
420 <dd> <a href="https://golang.org/pkg/net/http/#ProtocolError.Error">func (err *ProtocolError) Error() string</a></dd>
424 <dd><a href="https://golang.org/pkg/net/http/#Request">type Request</a></dd>
427 <dd> <a href="https://golang.org/pkg/net/http/#NewRequest">func NewRequest(method, urlStr string, body io.Reader) (*Request, error)</a></dd>
430 <dd> <a href="https://golang.org/pkg/net/http/#ReadRequest">func ReadRequest(b *bufio.Reader) (req *Request, err error)</a></dd>
434 <dd> <a href="https://golang.org/pkg/net/http/#Request.AddCookie">func (r *Request) AddCookie(c *Cookie)</a></dd>
437 <dd> <a href="https://golang.org/pkg/net/http/#Request.BasicAuth">func (r *Request) BasicAuth() (username, password string, ok bool)</a></dd>
440 <dd> <a href="https://golang.org/pkg/net/http/#Request.Cookie">func (r *Request) Cookie(name string) (*Cookie, error)</a></dd>
443 <dd> <a href="https://golang.org/pkg/net/http/#Request.Cookies">func (r *Request) Cookies() []*Cookie</a></dd>
446 <dd> <a href="https://golang.org/pkg/net/http/#Request.FormFile">func (r *Request) FormFile(key string) (multipart.File, *multipart.FileHeader, error)</a></dd>
449 <dd> <a href="https://golang.org/pkg/net/http/#Request.FormValue">func (r *Request) FormValue(key string) string</a></dd>
452 <dd> <a href="https://golang.org/pkg/net/http/#Request.MultipartReader">func (r *Request) MultipartReader() (*multipart.Reader, error)</a></dd>
455 <dd> <a href="https://golang.org/pkg/net/http/#Request.ParseForm">func (r *Request) ParseForm() error</a></dd>
458 <dd> <a href="https://golang.org/pkg/net/http/#Request.ParseMultipartForm">func (r *Request) ParseMultipartForm(maxMemory int64) error</a></dd>
461 <dd> <a href="https://golang.org/pkg/net/http/#Request.PostFormValue">func (r *Request) PostFormValue(key string) string</a></dd>
464 <dd> <a href="https://golang.org/pkg/net/http/#Request.ProtoAtLeast">func (r *Request) ProtoAtLeast(major, minor int) bool</a></dd>
467 <dd> <a href="https://golang.org/pkg/net/http/#Request.Referer">func (r *Request) Referer() string</a></dd>
470 <dd> <a href="https://golang.org/pkg/net/http/#Request.SetBasicAuth">func (r *Request) SetBasicAuth(username, password string)</a></dd>
473 <dd> <a href="https://golang.org/pkg/net/http/#Request.UserAgent">func (r *Request) UserAgent() string</a></dd>
476 <dd> <a href="https://golang.org/pkg/net/http/#Request.Write">func (r *Request) Write(w io.Writer) error</a></dd>
479 <dd> <a href="https://golang.org/pkg/net/http/#Request.WriteProxy">func (r *Request) WriteProxy(w io.Writer) error</a></dd>
483 <dd><a href="https://golang.org/pkg/net/http/#Response">type Response</a></dd>
486 <dd> <a href="https://golang.org/pkg/net/http/#Get">func Get(url string) (resp *Response, err error)</a></dd>
489 <dd> <a href="https://golang.org/pkg/net/http/#Head">func Head(url string) (resp *Response, err error)</a></dd>
492 <dd> <a href="https://golang.org/pkg/net/http/#Post">func Post(url string, bodyType string, body io.Reader) (resp *Response, err error)</a></dd>
495 <dd> <a href="https://golang.org/pkg/net/http/#PostForm">func PostForm(url string, data url.Values) (resp *Response, err error)</a></dd>
498 <dd> <a href="https://golang.org/pkg/net/http/#ReadResponse">func ReadResponse(r *bufio.Reader, req *Request) (*Response, error)</a></dd>
502 <dd> <a href="https://golang.org/pkg/net/http/#Response.Cookies">func (r *Response) Cookies() []*Cookie</a></dd>
505 <dd> <a href="https://golang.org/pkg/net/http/#Response.Location">func (r *Response) Location() (*url.URL, error)</a></dd>
508 <dd> <a href="https://golang.org/pkg/net/http/#Response.ProtoAtLeast">func (r *Response) ProtoAtLeast(major, minor int) bool</a></dd>
511 <dd> <a href="https://golang.org/pkg/net/http/#Response.Write">func (r *Response) Write(w io.Writer) error</a></dd>
515 <dd><a href="https://golang.org/pkg/net/http/#ResponseWriter">type ResponseWriter</a></dd>
520 <dd><a href="https://golang.org/pkg/net/http/#RoundTripper">type RoundTripper</a></dd>
523 <dd> <a href="https://golang.org/pkg/net/http/#NewFileTransport">func NewFileTransport(fs FileSystem) RoundTripper</a></dd>
528 <dd><a href="https://golang.org/pkg/net/http/#ServeMux">type ServeMux</a></dd>
531 <dd> <a href="https://golang.org/pkg/net/http/#NewServeMux">func NewServeMux() *ServeMux</a></dd>
535 <dd> <a href="https://golang.org/pkg/net/http/#ServeMux.Handle">func (mux *ServeMux) Handle(pattern string, handler Handler)</a></dd>
538 <dd> <a href="https://golang.org/pkg/net/http/#ServeMux.HandleFunc">func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Request))</a></dd>
541 <dd> <a href="https://golang.org/pkg/net/http/#ServeMux.Handler">func (mux *ServeMux) Handler(r *Request) (h Handler, pattern string)</a></dd>
544 <dd> <a href="https://golang.org/pkg/net/http/#ServeMux.ServeHTTP">func (mux *ServeMux) ServeHTTP(w ResponseWriter, r *Request)</a></dd>
548 <dd><a href="https://golang.org/pkg/net/http/#Server">type Server</a></dd>
552 <dd> <a href="https://golang.org/pkg/net/http/#Server.ListenAndServe">func (srv *Server) ListenAndServe() error</a></dd>
555 <dd> <a href="https://golang.org/pkg/net/http/#Server.ListenAndServeTLS">func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error</a></dd>
558 <dd> <a href="https://golang.org/pkg/net/http/#Server.Serve">func (srv *Server) Serve(l net.Listener) error</a></dd>
561 <dd> <a href="https://golang.org/pkg/net/http/#Server.SetKeepAlivesEnabled">func (srv *Server) SetKeepAlivesEnabled(v bool)</a></dd>
565 <dd><a href="https://golang.org/pkg/net/http/#Transport">type Transport</a></dd>
569 <dd> <a href="https://golang.org/pkg/net/http/#Transport.CancelRequest">func (t *Transport) CancelRequest(req *Request)</a></dd>
572 <dd> <a href="https://golang.org/pkg/net/http/#Transport.CloseIdleConnections">func (t *Transport) CloseIdleConnections()</a></dd>
575 <dd> <a href="https://golang.org/pkg/net/http/#Transport.RegisterProtocol">func (t *Transport) RegisterProtocol(scheme string, rt RoundTripper)</a></dd>
578 <dd> <a href="https://golang.org/pkg/net/http/#Transport.RoundTrip">func (t *Transport) RoundTrip(req *Request) (resp *Response, err error)</a></dd>
583 </div><!-- #manual-nav -->
586 <div id="pkg-examples">
590 <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_FileServer">FileServer</a></dd>
592 <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_FileServer_stripPrefix">FileServer (StripPrefix)</a></dd>
594 <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_Get">Get</a></dd>
596 <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_Hijacker">Hijacker</a></dd>
598 <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_ResponseWriter_trailers">ResponseWriter (Trailers)</a></dd>
600 <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_ServeMux_Handle">ServeMux.Handle</a></dd>
602 <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_StripPrefix">StripPrefix</a></dd>
609 <h4>Package files</h4>
611 <span style="font-size:90%">
613 <a href="https://golang.org/src/net/http/client.go">client.go</a>
615 <a href="https://golang.org/src/net/http/cookie.go">cookie.go</a>
617 <a href="https://golang.org/src/net/http/doc.go">doc.go</a>
619 <a href="https://golang.org/src/net/http/filetransport.go">filetransport.go</a>
621 <a href="https://golang.org/src/net/http/fs.go">fs.go</a>
623 <a href="https://golang.org/src/net/http/header.go">header.go</a>
625 <a href="https://golang.org/src/net/http/jar.go">jar.go</a>
627 <a href="https://golang.org/src/net/http/lex.go">lex.go</a>
629 <a href="https://golang.org/src/net/http/request.go">request.go</a>
631 <a href="https://golang.org/src/net/http/response.go">response.go</a>
633 <a href="https://golang.org/src/net/http/server.go">server.go</a>
635 <a href="https://golang.org/src/net/http/sniff.go">sniff.go</a>
637 <a href="https://golang.org/src/net/http/status.go">status.go</a>
639 <a href="https://golang.org/src/net/http/transfer.go">transfer.go</a>
641 <a href="https://golang.org/src/net/http/transport.go">transport.go</a>
646 </div><!-- .expanded -->
647 </div><!-- #pkg-index -->
649 <div id="pkg-callgraph" class="toggle" style="display: none">
650 <div class="collapsed">
651 <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
652 </div> <!-- .expanded -->
653 <div class="expanded">
654 <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
656 In the call graph viewer below, each node
657 is a function belonging to this package
658 and its children are the functions it
659 calls—perhaps dynamically.
662 The root nodes are the entry points of the
663 package: functions that may be called from
665 There may be non-exported or anonymous
666 functions among them if they are called
667 dynamically from another package.
670 Click a node to visit that function's source code.
671 From there you can visit its callers by
672 clicking its declaring <code>func</code>
676 Functions may be omitted if they were
677 determined to be unreachable in the
678 particular programs or tests that were
681 <!-- Zero means show all package entry points. -->
682 <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
684 </div> <!-- #pkg-callgraph -->
687 <h2 id="pkg-constants">Constants</h2>
690 <span id="StatusContinue">StatusContinue</span> = 100
691 <span id="StatusSwitchingProtocols">StatusSwitchingProtocols</span> = 101
693 <span id="StatusOK">StatusOK</span> = 200
694 <span id="StatusCreated">StatusCreated</span> = 201
695 <span id="StatusAccepted">StatusAccepted</span> = 202
696 <span id="StatusNonAuthoritativeInfo">StatusNonAuthoritativeInfo</span> = 203
697 <span id="StatusNoContent">StatusNoContent</span> = 204
698 <span id="StatusResetContent">StatusResetContent</span> = 205
699 <span id="StatusPartialContent">StatusPartialContent</span> = 206
701 <span id="StatusMultipleChoices">StatusMultipleChoices</span> = 300
702 <span id="StatusMovedPermanently">StatusMovedPermanently</span> = 301
703 <span id="StatusFound">StatusFound</span> = 302
704 <span id="StatusSeeOther">StatusSeeOther</span> = 303
705 <span id="StatusNotModified">StatusNotModified</span> = 304
706 <span id="StatusUseProxy">StatusUseProxy</span> = 305
707 <span id="StatusTemporaryRedirect">StatusTemporaryRedirect</span> = 307
709 <span id="StatusBadRequest">StatusBadRequest</span> = 400
710 <span id="StatusUnauthorized">StatusUnauthorized</span> = 401
711 <span id="StatusPaymentRequired">StatusPaymentRequired</span> = 402
712 <span id="StatusForbidden">StatusForbidden</span> = 403
713 <span id="StatusNotFound">StatusNotFound</span> = 404
714 <span id="StatusMethodNotAllowed">StatusMethodNotAllowed</span> = 405
715 <span id="StatusNotAcceptable">StatusNotAcceptable</span> = 406
716 <span id="StatusProxyAuthRequired">StatusProxyAuthRequired</span> = 407
717 <span id="StatusRequestTimeout">StatusRequestTimeout</span> = 408
718 <span id="StatusConflict">StatusConflict</span> = 409
719 <span id="StatusGone">StatusGone</span> = 410
720 <span id="StatusLengthRequired">StatusLengthRequired</span> = 411
721 <span id="StatusPreconditionFailed">StatusPreconditionFailed</span> = 412
722 <span id="StatusRequestEntityTooLarge">StatusRequestEntityTooLarge</span> = 413
723 <span id="StatusRequestURITooLong">StatusRequestURITooLong</span> = 414
724 <span id="StatusUnsupportedMediaType">StatusUnsupportedMediaType</span> = 415
725 <span id="StatusRequestedRangeNotSatisfiable">StatusRequestedRangeNotSatisfiable</span> = 416
726 <span id="StatusExpectationFailed">StatusExpectationFailed</span> = 417
727 <span id="StatusTeapot">StatusTeapot</span> = 418
729 <span id="StatusInternalServerError">StatusInternalServerError</span> = 500
730 <span id="StatusNotImplemented">StatusNotImplemented</span> = 501
731 <span id="StatusBadGateway">StatusBadGateway</span> = 502
732 <span id="StatusServiceUnavailable">StatusServiceUnavailable</span> = 503
733 <span id="StatusGatewayTimeout">StatusGatewayTimeout</span> = 504
734 <span id="StatusHTTPVersionNotSupported">StatusHTTPVersionNotSupported</span> = 505
737 HTTP status codes, defined in RFC 2616.
741 <pre>const <span id="DefaultMaxHeaderBytes">DefaultMaxHeaderBytes</span> = 1 << 20 <span class="comment">// 1 MB</span>
744 DefaultMaxHeaderBytes is the maximum permitted size of the headers
746 This can be overridden by setting Server.MaxHeaderBytes.
750 <pre>const <span id="DefaultMaxIdleConnsPerHost">DefaultMaxIdleConnsPerHost</span> = 2</pre>
752 DefaultMaxIdleConnsPerHost is the default value of Transport's
757 <pre>const <span id="TimeFormat">TimeFormat</span> = "Mon, 02 Jan 2006 15:04:05 GMT"</pre>
759 TimeFormat is the time format to use with
760 time.Parse and time.Time.Format when parsing
761 or generating times in HTTP headers.
762 It is like time.RFC1123 but hard codes GMT as the time zone.
768 <h2 id="pkg-variables">Variables</h2>
771 <span id="ErrHeaderTooLong">ErrHeaderTooLong</span> = &<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"header too long"}
772 <span id="ErrShortBody">ErrShortBody</span> = &<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"entity body too short"}
773 <span id="ErrNotSupported">ErrNotSupported</span> = &<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"feature not supported"}
774 <span id="ErrUnexpectedTrailer">ErrUnexpectedTrailer</span> = &<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"trailer header without chunked transfer encoding"}
775 <span id="ErrMissingContentLength">ErrMissingContentLength</span> = &<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"missing ContentLength in HEAD response"}
776 <span id="ErrNotMultipart">ErrNotMultipart</span> = &<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"request Content-Type isn't multipart/form-data"}
777 <span id="ErrMissingBoundary">ErrMissingBoundary</span> = &<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"no multipart boundary param in Content-Type"}
782 <span id="ErrWriteAfterFlush">ErrWriteAfterFlush</span> = <a href="https://golang.org/pkg/errors/">errors</a>.<a href="https://golang.org/pkg/errors/#New">New</a>("Conn.Write called after Flush")
783 <span id="ErrBodyNotAllowed">ErrBodyNotAllowed</span> = <a href="https://golang.org/pkg/errors/">errors</a>.<a href="https://golang.org/pkg/errors/#New">New</a>("http: request method or response status code does not allow body")
784 <span id="ErrHijacked">ErrHijacked</span> = <a href="https://golang.org/pkg/errors/">errors</a>.<a href="https://golang.org/pkg/errors/#New">New</a>("Conn has been hijacked")
785 <span id="ErrContentLength">ErrContentLength</span> = <a href="https://golang.org/pkg/errors/">errors</a>.<a href="https://golang.org/pkg/errors/#New">New</a>("Conn.Write wrote more than the declared Content-Length")
788 Errors introduced by the HTTP server.
792 <pre>var <span id="DefaultClient">DefaultClient</span> = &<a href="https://golang.org/pkg/net/http/#Client">Client</a>{}</pre>
794 DefaultClient is the default Client and is used by Get, Head, and Post.
798 <pre>var <span id="DefaultServeMux">DefaultServeMux</span> = <a href="https://golang.org/pkg/net/http/#NewServeMux">NewServeMux</a>()</pre>
800 DefaultServeMux is the default ServeMux used by Serve.
804 <pre>var <span id="ErrBodyReadAfterClose">ErrBodyReadAfterClose</span> = <a href="https://golang.org/pkg/errors/">errors</a>.<a href="https://golang.org/pkg/errors/#New">New</a>("http: invalid Read on closed Body")</pre>
806 ErrBodyReadAfterClose is returned when reading a Request or Response
807 Body after the body has been closed. This typically happens when the body is
808 read after an HTTP Handler calls WriteHeader or Write on its
813 <pre>var <span id="ErrHandlerTimeout">ErrHandlerTimeout</span> = <a href="https://golang.org/pkg/errors/">errors</a>.<a href="https://golang.org/pkg/errors/#New">New</a>("http: Handler timeout")</pre>
815 ErrHandlerTimeout is returned on ResponseWriter Write calls
816 in handlers which have timed out.
820 <pre>var <span id="ErrLineTooLong">ErrLineTooLong</span> = <a href="https://golang.org/pkg/net/http/internal/">internal</a>.<a href="https://golang.org/pkg/net/http/internal/#ErrLineTooLong">ErrLineTooLong</a></pre>
822 ErrLineTooLong is returned when reading request or response bodies
823 with malformed chunked encoding.
827 <pre>var <span id="ErrMissingFile">ErrMissingFile</span> = <a href="https://golang.org/pkg/errors/">errors</a>.<a href="https://golang.org/pkg/errors/#New">New</a>("http: no such file")</pre>
829 ErrMissingFile is returned by FormFile when the provided file field name
830 is either not present in the request or not a file field.
834 <pre>var <span id="ErrNoCookie">ErrNoCookie</span> = <a href="https://golang.org/pkg/errors/">errors</a>.<a href="https://golang.org/pkg/errors/#New">New</a>("http: named cookie not present")</pre>
836 ErrNoCookie is returned by Request's Cookie method when a cookie is not found.
840 <pre>var <span id="ErrNoLocation">ErrNoLocation</span> = <a href="https://golang.org/pkg/errors/">errors</a>.<a href="https://golang.org/pkg/errors/#New">New</a>("http: no Location header in response")</pre>
842 ErrNoLocation is returned by Response's Location method
843 when no Location header is present.
851 <h2 id="CanonicalHeaderKey">func <a href="https://golang.org/src/net/http/header.go?s=4562:4602#L163">CanonicalHeaderKey</a></h2>
852 <pre>func CanonicalHeaderKey(s <a href="https://golang.org/pkg/builtin/#string">string</a>) <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
854 CanonicalHeaderKey returns the canonical format of the
855 header key s. The canonicalization converts the first
856 letter and any letter following a hyphen to upper case;
857 the rest are converted to lowercase. For example, the
858 canonical key for "accept-encoding" is "Accept-Encoding".
859 If s contains a space or invalid header field bytes, it is
860 returned without modifications.
869 <h2 id="DetectContentType">func <a href="https://golang.org/src/net/http/sniff.go?s=648:690#L11">DetectContentType</a></h2>
870 <pre>func DetectContentType(data []<a href="https://golang.org/pkg/builtin/#byte">byte</a>) <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
872 DetectContentType implements the algorithm described
873 at <a href="http://mimesniff.spec.whatwg.org/">http://mimesniff.spec.whatwg.org/</a> to determine the
874 Content-Type of the given data. It considers at most the
875 first 512 bytes of data. DetectContentType always returns
876 a valid MIME type: if it cannot determine a more specific one, it
877 returns "application/octet-stream".
886 <h2 id="Error">func <a href="https://golang.org/src/net/http/server.go?s=41562:41614#L1419">Error</a></h2>
887 <pre>func Error(w <a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, error <a href="https://golang.org/pkg/builtin/#string">string</a>, code <a href="https://golang.org/pkg/builtin/#int">int</a>)</pre>
889 Error replies to the request with the specified error message and HTTP code.
890 The error message should be plain text.
899 <h2 id="Handle">func <a href="https://golang.org/src/net/http/server.go?s=51434:51478#L1740">Handle</a></h2>
900 <pre>func Handle(pattern <a href="https://golang.org/pkg/builtin/#string">string</a>, handler <a href="https://golang.org/pkg/net/http/#Handler">Handler</a>)</pre>
902 Handle registers the handler for the given pattern
903 in the DefaultServeMux.
904 The documentation for ServeMux explains how patterns are matched.
913 <h2 id="HandleFunc">func <a href="https://golang.org/src/net/http/server.go?s=51688:51759#L1745">HandleFunc</a></h2>
914 <pre>func HandleFunc(pattern <a href="https://golang.org/pkg/builtin/#string">string</a>, handler func(<a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, *<a href="https://golang.org/pkg/net/http/#Request">Request</a>))</pre>
916 HandleFunc registers the handler function for the given pattern
917 in the DefaultServeMux.
918 The documentation for ServeMux explains how patterns are matched.
927 <h2 id="ListenAndServe">func <a href="https://golang.org/src/net/http/server.go?s=58314:58369#L1955">ListenAndServe</a></h2>
928 <pre>func ListenAndServe(addr <a href="https://golang.org/pkg/builtin/#string">string</a>, handler <a href="https://golang.org/pkg/net/http/#Handler">Handler</a>) <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
930 ListenAndServe listens on the TCP network address addr
931 and then calls Serve with handler to handle requests
932 on incoming connections. Handler is typically nil,
933 in which case the DefaultServeMux is used.
936 A trivial example server is:
946 // hello world, the web server
947 func HelloServer(w http.ResponseWriter, req *http.Request) {
948 io.WriteString(w, "hello, world!\n")
952 http.HandleFunc("/hello", HelloServer)
953 err := http.ListenAndServe(":12345", nil)
955 log.Fatal("ListenAndServe: ", err)
966 <h2 id="ListenAndServeTLS">func <a href="https://golang.org/src/net/http/server.go?s=59426:59517#L1988">ListenAndServeTLS</a></h2>
967 <pre>func ListenAndServeTLS(addr <a href="https://golang.org/pkg/builtin/#string">string</a>, certFile <a href="https://golang.org/pkg/builtin/#string">string</a>, keyFile <a href="https://golang.org/pkg/builtin/#string">string</a>, handler <a href="https://golang.org/pkg/net/http/#Handler">Handler</a>) <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
969 ListenAndServeTLS acts identically to ListenAndServe, except that it
970 expects HTTPS connections. Additionally, files containing a certificate and
971 matching private key for the server must be provided. If the certificate
972 is signed by a certificate authority, the certFile should be the concatenation
973 of the server's certificate, any intermediates, and the CA's certificate.
976 A trivial example server is:
983 func handler(w http.ResponseWriter, req *http.Request) {
984 w.Header().Set("Content-Type", "text/plain")
985 w.Write([]byte("This is an example server.\n"))
989 http.HandleFunc("/", handler)
990 log.Printf("About to listen on 10443. Go to <a href="https://127.0.0.1:10443/">https://127.0.0.1:10443/</a>")
991 err := http.ListenAndServeTLS(":10443", "cert.pem", "key.pem", nil)
998 One can use generate_cert.go in crypto/tls to generate cert.pem and key.pem.
1007 <h2 id="MaxBytesReader">func <a href="https://golang.org/src/net/http/request.go?s=22939:23016#L726">MaxBytesReader</a></h2>
1008 <pre>func MaxBytesReader(w <a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, r <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#ReadCloser">ReadCloser</a>, n <a href="https://golang.org/pkg/builtin/#int64">int64</a>) <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#ReadCloser">ReadCloser</a></pre>
1010 MaxBytesReader is similar to io.LimitReader but is intended for
1011 limiting the size of incoming request bodies. In contrast to
1012 io.LimitReader, MaxBytesReader's result is a ReadCloser, returns a
1013 non-EOF error for a Read beyond the limit, and closes the
1014 underlying reader when its Close method is called.
1017 MaxBytesReader prevents clients from accidentally or maliciously
1018 sending a large request and wasting server resources.
1027 <h2 id="NotFound">func <a href="https://golang.org/src/net/http/server.go?s=41848:41891#L1427">NotFound</a></h2>
1028 <pre>func NotFound(w <a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>)</pre>
1030 NotFound replies to the request with an HTTP 404 not found error.
1039 <h2 id="ParseHTTPVersion">func <a href="https://golang.org/src/net/http/request.go?s=16539:16601#L498">ParseHTTPVersion</a></h2>
1040 <pre>func ParseHTTPVersion(vers <a href="https://golang.org/pkg/builtin/#string">string</a>) (major, minor <a href="https://golang.org/pkg/builtin/#int">int</a>, ok <a href="https://golang.org/pkg/builtin/#bool">bool</a>)</pre>
1042 ParseHTTPVersion parses a HTTP version string.
1043 "HTTP/1.0" returns (1, 0, true).
1052 <h2 id="ParseTime">func <a href="https://golang.org/src/net/http/header.go?s=1908:1960#L69">ParseTime</a></h2>
1053 <pre>func ParseTime(text <a href="https://golang.org/pkg/builtin/#string">string</a>) (t <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Time">Time</a>, err <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
1055 ParseTime parses a time header (such as the Date: header),
1056 trying each of the three formats allowed by HTTP/1.1:
1057 TimeFormat, time.RFC850, and time.ANSIC.
1066 <h2 id="ProxyFromEnvironment">func <a href="https://golang.org/src/net/http/transport.go?s=4805:4862#L126">ProxyFromEnvironment</a></h2>
1067 <pre>func ProxyFromEnvironment(req *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) (*<a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#URL">URL</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
1069 ProxyFromEnvironment returns the URL of the proxy to use for a
1070 given request, as indicated by the environment variables
1071 HTTP_PROXY, HTTPS_PROXY and NO_PROXY (or the lowercase versions
1072 thereof). HTTPS_PROXY takes precedence over HTTP_PROXY for https
1076 The environment values may be either a complete URL or a
1077 "host[:port]", in which case the "http" scheme is assumed.
1078 An error is returned if the value is a different form.
1081 A nil URL and nil error are returned if no proxy is defined in the
1082 environment, or a proxy should not be used for the given request,
1083 as defined by NO_PROXY.
1086 As a special case, if req.URL.Host is "localhost" (with or without
1087 a port number), then a nil URL and nil error will be returned.
1096 <h2 id="ProxyURL">func <a href="https://golang.org/src/net/http/transport.go?s=5664:5729#L157">ProxyURL</a></h2>
1097 <pre>func ProxyURL(fixedURL *<a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#URL">URL</a>) func(*<a href="https://golang.org/pkg/net/http/#Request">Request</a>) (*<a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#URL">URL</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
1099 ProxyURL returns a proxy function (for use in a Transport)
1100 that always returns the same URL.
1109 <h2 id="Redirect">func <a href="https://golang.org/src/net/http/server.go?s=42815:42883#L1454">Redirect</a></h2>
1110 <pre>func Redirect(w <a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>, urlStr <a href="https://golang.org/pkg/builtin/#string">string</a>, code <a href="https://golang.org/pkg/builtin/#int">int</a>)</pre>
1112 Redirect replies to the request with a redirect to url,
1113 which may be a path relative to the request path.
1122 <h2 id="Serve">func <a href="https://golang.org/src/net/http/server.go?s=52072:52121#L1753">Serve</a></h2>
1123 <pre>func Serve(l <a href="https://golang.org/pkg/net/">net</a>.<a href="https://golang.org/pkg/net/#Listener">Listener</a>, handler <a href="https://golang.org/pkg/net/http/#Handler">Handler</a>) <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
1125 Serve accepts incoming HTTP connections on the listener l,
1126 creating a new service goroutine for each. The service goroutines
1127 read requests and then call handler to reply to them.
1128 Handler is typically nil, in which case the DefaultServeMux is used.
1137 <h2 id="ServeContent">func <a href="https://golang.org/src/net/http/fs.go?s=3535:3639#L107">ServeContent</a></h2>
1138 <pre>func ServeContent(w <a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, req *<a href="https://golang.org/pkg/net/http/#Request">Request</a>, name <a href="https://golang.org/pkg/builtin/#string">string</a>, modtime <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Time">Time</a>, content <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#ReadSeeker">ReadSeeker</a>)</pre>
1140 ServeContent replies to the request using the content in the
1141 provided ReadSeeker. The main benefit of ServeContent over io.Copy
1142 is that it handles Range requests properly, sets the MIME type, and
1143 handles If-Modified-Since requests.
1146 If the response's Content-Type header is not set, ServeContent
1147 first tries to deduce the type from name's file extension and,
1148 if that fails, falls back to reading the first block of the content
1149 and passing it to DetectContentType.
1150 The name is otherwise unused; in particular it can be empty and is
1151 never sent in the response.
1154 If modtime is not the zero time or Unix epoch, ServeContent
1155 includes it in a Last-Modified header in the response. If the
1156 request includes an If-Modified-Since header, ServeContent uses
1157 modtime to decide whether the content needs to be sent at all.
1160 The content's Seek method must work: ServeContent uses
1161 a seek to the end of the content to determine its size.
1164 If the caller has set w's ETag header, ServeContent uses it to
1165 handle requests using If-Range and If-None-Match.
1168 Note that *os.File implements the io.ReadSeeker interface.
1177 <h2 id="ServeFile">func <a href="https://golang.org/src/net/http/fs.go?s=13941:13998#L443">ServeFile</a></h2>
1178 <pre>func ServeFile(w <a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>, name <a href="https://golang.org/pkg/builtin/#string">string</a>)</pre>
1180 ServeFile replies to the request with the contents of the named
1184 As a special case, ServeFile redirects any request where r.URL.Path
1185 ends in "/index.html" to the same path, without the final
1186 "index.html". To avoid such redirects either modify the path or
1196 <h2 id="SetCookie">func <a href="https://golang.org/src/net/http/cookie.go?s=3059:3107#L120">SetCookie</a></h2>
1197 <pre>func SetCookie(w <a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, cookie *<a href="https://golang.org/pkg/net/http/#Cookie">Cookie</a>)</pre>
1199 SetCookie adds a Set-Cookie header to the provided ResponseWriter's headers.
1200 The provided cookie must have a valid Name. Invalid cookies may be
1210 <h2 id="StatusText">func <a href="https://golang.org/src/net/http/status.go?s=4602:4634#L108">StatusText</a></h2>
1211 <pre>func StatusText(code <a href="https://golang.org/pkg/builtin/#int">int</a>) <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
1213 StatusText returns a text for the HTTP status code. It returns the empty
1214 string if the code is unknown.
1224 <h2 id="Client">type <a href="https://golang.org/src/net/http/client.go?s=897:2420#L26">Client</a></h2>
1225 <pre>type Client struct {
1226 <span class="comment">// Transport specifies the mechanism by which individual</span>
1227 <span class="comment">// HTTP requests are made.</span>
1228 <span class="comment">// If nil, DefaultTransport is used.</span>
1229 Transport <a href="https://golang.org/pkg/net/http/#RoundTripper">RoundTripper</a>
1231 <span class="comment">// CheckRedirect specifies the policy for handling redirects.</span>
1232 <span class="comment">// If CheckRedirect is not nil, the client calls it before</span>
1233 <span class="comment">// following an HTTP redirect. The arguments req and via are</span>
1234 <span class="comment">// the upcoming request and the requests made already, oldest</span>
1235 <span class="comment">// first. If CheckRedirect returns an error, the Client's Get</span>
1236 <span class="comment">// method returns both the previous Response and</span>
1237 <span class="comment">// CheckRedirect's error (wrapped in a url.Error) instead of</span>
1238 <span class="comment">// issuing the Request req.</span>
1239 <span class="comment">//</span>
1240 <span class="comment">// If CheckRedirect is nil, the Client uses its default policy,</span>
1241 <span class="comment">// which is to stop after 10 consecutive requests.</span>
1242 CheckRedirect func(req *<a href="https://golang.org/pkg/net/http/#Request">Request</a>, via []*<a href="https://golang.org/pkg/net/http/#Request">Request</a>) <a href="https://golang.org/pkg/builtin/#error">error</a>
1244 <span class="comment">// Jar specifies the cookie jar.</span>
1245 <span class="comment">// If Jar is nil, cookies are not sent in requests and ignored</span>
1246 <span class="comment">// in responses.</span>
1247 Jar <a href="https://golang.org/pkg/net/http/#CookieJar">CookieJar</a>
1249 <span class="comment">// Timeout specifies a time limit for requests made by this</span>
1250 <span class="comment">// Client. The timeout includes connection time, any</span>
1251 <span class="comment">// redirects, and reading the response body. The timer remains</span>
1252 <span class="comment">// running after Get, Head, Post, or Do return and will</span>
1253 <span class="comment">// interrupt reading of the Response.Body.</span>
1254 <span class="comment">//</span>
1255 <span class="comment">// A Timeout of zero means no timeout.</span>
1256 <span class="comment">//</span>
1257 <span class="comment">// The Client's Transport must support the CancelRequest</span>
1258 <span class="comment">// method or Client will return errors when attempting to make</span>
1259 <span class="comment">// a request with Get, Head, Post, or Do. Client's default</span>
1260 <span class="comment">// Transport (DefaultTransport) supports CancelRequest.</span>
1261 Timeout <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Duration">Duration</a>
1264 A Client is an HTTP client. Its zero value (DefaultClient) is a
1265 usable client that uses DefaultTransport.
1268 The Client's Transport typically has internal state (cached TCP
1269 connections), so Clients should be reused instead of created as
1270 needed. Clients are safe for concurrent use by multiple goroutines.
1273 A Client is higher-level than a RoundTripper (such as Transport)
1274 and additionally handles HTTP details such as cookies and
1291 <h3 id="Client.Do">func (*Client) <a href="https://golang.org/src/net/http/client.go?s=6009:6070#L163">Do</a></h3>
1292 <pre>func (c *<a href="https://golang.org/pkg/net/http/#Client">Client</a>) Do(req *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) (resp *<a href="https://golang.org/pkg/net/http/#Response">Response</a>, err <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
1294 Do sends an HTTP request and returns an HTTP response, following
1295 policy (e.g. redirects, cookies, auth) as configured on the client.
1298 An error is returned if caused by client policy (such as
1299 CheckRedirect), or if there was an HTTP protocol error.
1300 A non-2xx response doesn't cause an error.
1303 When err is nil, resp always contains a non-nil resp.Body.
1306 Callers should close resp.Body when done reading from it. If
1307 resp.Body is not closed, the Client's underlying RoundTripper
1308 (typically Transport) may not be able to re-use a persistent TCP
1309 connection to the server for a subsequent "keep-alive" request.
1312 The request Body, if non-nil, will be closed by the underlying
1313 Transport, even on errors.
1316 Generally Get, Post, or PostForm will be used instead of Do.
1324 <h3 id="Client.Get">func (*Client) <a href="https://golang.org/src/net/http/client.go?s=9928:9988#L291">Get</a></h3>
1325 <pre>func (c *<a href="https://golang.org/pkg/net/http/#Client">Client</a>) Get(url <a href="https://golang.org/pkg/builtin/#string">string</a>) (resp *<a href="https://golang.org/pkg/net/http/#Response">Response</a>, err <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
1327 Get issues a GET to the specified URL. If the response is one of the
1328 following redirect codes, Get follows the redirect after calling the
1329 Client's CheckRedirect function:
1331 <pre>301 (Moved Permanently)
1334 307 (Temporary Redirect)
1337 An error is returned if the Client's CheckRedirect function fails
1338 or if there was an HTTP protocol error. A non-2xx response doesn't
1342 When err is nil, resp always contains a non-nil resp.Body.
1343 Caller should close resp.Body when done reading from it.
1346 To make a request with custom headers, use NewRequest and Client.Do.
1354 <h3 id="Client.Head">func (*Client) <a href="https://golang.org/src/net/http/client.go?s=16276:16337#L512">Head</a></h3>
1355 <pre>func (c *<a href="https://golang.org/pkg/net/http/#Client">Client</a>) Head(url <a href="https://golang.org/pkg/builtin/#string">string</a>) (resp *<a href="https://golang.org/pkg/net/http/#Response">Response</a>, err <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
1357 Head issues a HEAD to the specified URL. If the response is one of the
1358 following redirect codes, Head follows the redirect after calling the
1359 Client's CheckRedirect function:
1361 <pre>301 (Moved Permanently)
1364 307 (Temporary Redirect)
1372 <h3 id="Client.Post">func (*Client) <a href="https://golang.org/src/net/http/client.go?s=14197:14291#L455">Post</a></h3>
1373 <pre>func (c *<a href="https://golang.org/pkg/net/http/#Client">Client</a>) Post(url <a href="https://golang.org/pkg/builtin/#string">string</a>, bodyType <a href="https://golang.org/pkg/builtin/#string">string</a>, body <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#Reader">Reader</a>) (resp *<a href="https://golang.org/pkg/net/http/#Response">Response</a>, err <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
1375 Post issues a POST to the specified URL.
1378 Caller should close resp.Body when done reading from it.
1381 If the provided body is an io.Closer, it is closed after the
1385 To set custom headers, use NewRequest and Client.Do.
1393 <h3 id="Client.PostForm">func (*Client) <a href="https://golang.org/src/net/http/client.go?s=15401:15483#L486">PostForm</a></h3>
1394 <pre>func (c *<a href="https://golang.org/pkg/net/http/#Client">Client</a>) PostForm(url <a href="https://golang.org/pkg/builtin/#string">string</a>, data <a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#Values">Values</a>) (resp *<a href="https://golang.org/pkg/net/http/#Response">Response</a>, err <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
1396 PostForm issues a POST to the specified URL,
1397 with data's keys and values URL-encoded as the request body.
1400 The Content-Type header is set to application/x-www-form-urlencoded.
1401 To set other headers, use NewRequest and DefaultClient.Do.
1404 When err is nil, resp always contains a non-nil resp.Body.
1405 Caller should close resp.Body when done reading from it.
1415 <h2 id="CloseNotifier">type <a href="https://golang.org/src/net/http/server.go?s=3931:4099#L106">CloseNotifier</a></h2>
1416 <pre>type CloseNotifier interface {
1417 <span class="comment">// CloseNotify returns a channel that receives a single value</span>
1418 <span class="comment">// when the client connection has gone away.</span>
1419 CloseNotify() <-chan <a href="https://golang.org/pkg/builtin/#bool">bool</a>
1422 The CloseNotifier interface is implemented by ResponseWriters which
1423 allow detecting when the underlying connection has gone away.
1426 This mechanism can be used to cancel long operations on the server
1427 if the client has disconnected before the response is ready.
1445 <h2 id="ConnState">type <a href="https://golang.org/src/net/http/server.go?s=53915:53933#L1793">ConnState</a></h2>
1446 <pre>type ConnState <a href="https://golang.org/pkg/builtin/#int">int</a></pre>
1448 A ConnState represents the state of a client connection to a server.
1449 It's used by the optional Server.ConnState hook.
1455 <span class="comment">// StateNew represents a new connection that is expected to</span>
1456 <span class="comment">// send a request immediately. Connections begin at this</span>
1457 <span class="comment">// state and then transition to either StateActive or</span>
1458 <span class="comment">// StateClosed.</span>
1459 <span id="StateNew">StateNew</span> <a href="https://golang.org/pkg/net/http/#ConnState">ConnState</a> = <a href="https://golang.org/pkg/builtin/#iota">iota</a>
1461 <span class="comment">// StateActive represents a connection that has read 1 or more</span>
1462 <span class="comment">// bytes of a request. The Server.ConnState hook for</span>
1463 <span class="comment">// StateActive fires before the request has entered a handler</span>
1464 <span class="comment">// and doesn't fire again until the request has been</span>
1465 <span class="comment">// handled. After the request is handled, the state</span>
1466 <span class="comment">// transitions to StateClosed, StateHijacked, or StateIdle.</span>
1467 <span id="StateActive">StateActive</span>
1469 <span class="comment">// StateIdle represents a connection that has finished</span>
1470 <span class="comment">// handling a request and is in the keep-alive state, waiting</span>
1471 <span class="comment">// for a new request. Connections transition from StateIdle</span>
1472 <span class="comment">// to either StateActive or StateClosed.</span>
1473 <span id="StateIdle">StateIdle</span>
1475 <span class="comment">// StateHijacked represents a hijacked connection.</span>
1476 <span class="comment">// This is a terminal state. It does not transition to StateClosed.</span>
1477 <span id="StateHijacked">StateHijacked</span>
1479 <span class="comment">// StateClosed represents a closed connection.</span>
1480 <span class="comment">// This is a terminal state. Hijacked connections do not</span>
1481 <span class="comment">// transition to StateClosed.</span>
1482 <span id="StateClosed">StateClosed</span>
1497 <h3 id="ConnState.String">func (ConnState) <a href="https://golang.org/src/net/http/server.go?s=55217:55251#L1834">String</a></h3>
1498 <pre>func (c <a href="https://golang.org/pkg/net/http/#ConnState">ConnState</a>) String() <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
1507 <h2 id="Cookie">type <a href="https://golang.org/src/net/http/cookie.go?s=439:952#L11">Cookie</a></h2>
1508 <pre>type Cookie struct {
1509 Name <a href="https://golang.org/pkg/builtin/#string">string</a>
1510 Value <a href="https://golang.org/pkg/builtin/#string">string</a>
1512 Path <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// optional</span>
1513 Domain <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// optional</span>
1514 Expires <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Time">Time</a> <span class="comment">// optional</span>
1515 RawExpires <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// for reading cookies only</span>
1517 <span class="comment">// MaxAge=0 means no 'Max-Age' attribute specified.</span>
1518 <span class="comment">// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'</span>
1519 <span class="comment">// MaxAge>0 means Max-Age attribute present and given in seconds</span>
1520 MaxAge <a href="https://golang.org/pkg/builtin/#int">int</a>
1521 Secure <a href="https://golang.org/pkg/builtin/#bool">bool</a>
1522 HttpOnly <a href="https://golang.org/pkg/builtin/#bool">bool</a>
1523 Raw <a href="https://golang.org/pkg/builtin/#string">string</a>
1524 Unparsed []<a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// Raw text of unparsed attribute-value pairs</span>
1527 A Cookie represents an HTTP cookie as sent in the Set-Cookie header of an
1528 HTTP response or the Cookie header of an HTTP request.
1531 See <a href="http://tools.ietf.org/html/rfc6265">http://tools.ietf.org/html/rfc6265</a> for details.
1547 <h3 id="Cookie.String">func (*Cookie) <a href="https://golang.org/src/net/http/cookie.go?s=3428:3460#L130">String</a></h3>
1548 <pre>func (c *<a href="https://golang.org/pkg/net/http/#Cookie">Cookie</a>) String() <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
1550 String returns the serialization of the cookie for use in a Cookie
1551 header (if only Name and Value are set) or a Set-Cookie response
1552 header (if other fields are set).
1553 If c is nil or c.Name is invalid, the empty string is returned.
1563 <h2 id="CookieJar">type <a href="https://golang.org/src/net/http/jar.go?s=433:899#L7">CookieJar</a></h2>
1564 <pre>type CookieJar interface {
1565 <span class="comment">// SetCookies handles the receipt of the cookies in a reply for the</span>
1566 <span class="comment">// given URL. It may or may not choose to save the cookies, depending</span>
1567 <span class="comment">// on the jar's policy and implementation.</span>
1568 SetCookies(u *<a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#URL">URL</a>, cookies []*<a href="https://golang.org/pkg/net/http/#Cookie">Cookie</a>)
1570 <span class="comment">// Cookies returns the cookies to send in a request for the given URL.</span>
1571 <span class="comment">// It is up to the implementation to honor the standard cookie use</span>
1572 <span class="comment">// restrictions such as in RFC 6265.</span>
1573 Cookies(u *<a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#URL">URL</a>) []*<a href="https://golang.org/pkg/net/http/#Cookie">Cookie</a>
1576 A CookieJar manages storage and use of cookies in HTTP requests.
1579 Implementations of CookieJar must be safe for concurrent use by multiple
1583 The net/http/cookiejar package provides a CookieJar implementation.
1601 <h2 id="Dir">type <a href="https://golang.org/src/net/http/fs.go?s=719:734#L23">Dir</a></h2>
1602 <pre>type Dir <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
1604 A Dir implements FileSystem using the native file system restricted to a
1605 specific directory tree.
1608 While the FileSystem.Open method takes '/'-separated paths, a Dir's string
1609 value is a filename on the native file system, not a URL, so it is separated
1610 by filepath.Separator, which isn't necessarily '/'.
1613 An empty Dir is treated as ".".
1629 <h3 id="Dir.Open">func (Dir) <a href="https://golang.org/src/net/http/fs.go?s=736:780#L25">Open</a></h3>
1630 <pre>func (d <a href="https://golang.org/pkg/net/http/#Dir">Dir</a>) Open(name <a href="https://golang.org/pkg/builtin/#string">string</a>) (<a href="https://golang.org/pkg/net/http/#File">File</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
1639 <h2 id="File">type <a href="https://golang.org/src/net/http/fs.go?s=1591:1755#L52">File</a></h2>
1640 <pre>type File interface {
1641 <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#Closer">Closer</a>
1642 <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#Reader">Reader</a>
1643 Readdir(count <a href="https://golang.org/pkg/builtin/#int">int</a>) ([]<a href="https://golang.org/pkg/os/">os</a>.<a href="https://golang.org/pkg/os/#FileInfo">FileInfo</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)
1644 Seek(offset <a href="https://golang.org/pkg/builtin/#int64">int64</a>, whence <a href="https://golang.org/pkg/builtin/#int">int</a>) (<a href="https://golang.org/pkg/builtin/#int64">int64</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)
1645 Stat() (<a href="https://golang.org/pkg/os/">os</a>.<a href="https://golang.org/pkg/os/#FileInfo">FileInfo</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)
1648 A File is returned by a FileSystem's Open method and can be
1649 served by the FileServer implementation.
1652 The methods should behave the same as those on an *os.File.
1670 <h2 id="FileSystem">type <a href="https://golang.org/src/net/http/fs.go?s=1354:1416#L44">FileSystem</a></h2>
1671 <pre>type FileSystem interface {
1672 Open(name <a href="https://golang.org/pkg/builtin/#string">string</a>) (<a href="https://golang.org/pkg/net/http/#File">File</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)
1675 A FileSystem implements access to a collection of named files.
1676 The elements in a file path are separated by slash ('/', U+002F)
1677 characters, regardless of host operating system convention.
1695 <h2 id="Flusher">type <a href="https://golang.org/src/net/http/server.go?s=2921:3005#L79">Flusher</a></h2>
1696 <pre>type Flusher interface {
1697 <span class="comment">// Flush sends any buffered data to the client.</span>
1701 The Flusher interface is implemented by ResponseWriters that allow
1702 an HTTP handler to flush buffered data to the client.
1705 Note that even for ResponseWriters that support Flush,
1706 if the client is connected through an HTTP proxy,
1707 the buffered data may not reach the client until the response
1726 <h2 id="Handler">type <a href="https://golang.org/src/net/http/server.go?s=1361:1424#L42">Handler</a></h2>
1727 <pre>type Handler interface {
1728 ServeHTTP(<a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, *<a href="https://golang.org/pkg/net/http/#Request">Request</a>)
1731 Objects implementing the Handler interface can be
1732 registered to serve a particular path or subtree
1736 ServeHTTP should write reply headers and data to the ResponseWriter
1737 and then return. Returning signals that the request is finished
1738 and that the HTTP server can move on to the next request on
1742 If ServeHTTP panics, the server (the caller of ServeHTTP) assumes
1743 that the effect of the panic was isolated to the active request.
1744 It recovers the panic, logs a stack trace to the server error log,
1745 and hangs up the connection.
1759 <h3 id="FileServer">func <a href="https://golang.org/src/net/http/fs.go?s=14534:14574#L463">FileServer</a></h3>
1760 <pre>func FileServer(root <a href="https://golang.org/pkg/net/http/#FileSystem">FileSystem</a>) <a href="https://golang.org/pkg/net/http/#Handler">Handler</a></pre>
1762 FileServer returns a handler that serves HTTP requests
1763 with the contents of the file system rooted at root.
1766 To use the operating system's file system implementation,
1769 <pre>http.Handle("/", http.FileServer(http.Dir("/tmp")))
1772 As a special case, the returned file server redirects any request
1773 ending in "/index.html" to the same path, without the final
1777 <div id="example_FileServer" class="toggle">
1778 <div class="collapsed">
1779 <p class="exampleHeading toggleButton">▹ <span class="text">Example</span></p>
1781 <div class="expanded">
1782 <p class="exampleHeading toggleButton">▾ <span class="text">Example</span></p>
1787 <div class="input"><textarea class="code">package main
1795 // Simple static webserver:
1796 log.Fatal(http.ListenAndServe(":8080", http.FileServer(http.Dir("/usr/share/doc"))))
1799 <div class="output"><pre></pre></div>
1800 <div class="buttons">
1801 <a class="run" title="Run this code [shift-enter]">Run</a>
1802 <a class="fmt" title="Format this code">Format</a>
1809 <div id="example_FileServer_stripPrefix" class="toggle">
1810 <div class="collapsed">
1811 <p class="exampleHeading toggleButton">▹ <span class="text">Example (StripPrefix)</span></p>
1813 <div class="expanded">
1814 <p class="exampleHeading toggleButton">▾ <span class="text">Example (StripPrefix)</span></p>
1819 <div class="input"><textarea class="code">package main
1826 // To serve a directory on disk (/tmp) under an alternate URL
1827 // path (/tmpfiles/), use StripPrefix to modify the request
1828 // URL's path before the FileServer sees it:
1829 http.Handle("/tmpfiles/", http.StripPrefix("/tmpfiles/", http.FileServer(http.Dir("/tmp"))))
1832 <div class="output"><pre></pre></div>
1833 <div class="buttons">
1834 <a class="run" title="Run this code [shift-enter]">Run</a>
1835 <a class="fmt" title="Format this code">Format</a>
1846 <h3 id="NotFoundHandler">func <a href="https://golang.org/src/net/http/server.go?s=42065:42095#L1431">NotFoundHandler</a></h3>
1847 <pre>func NotFoundHandler() <a href="https://golang.org/pkg/net/http/#Handler">Handler</a></pre>
1849 NotFoundHandler returns a simple request handler
1850 that replies to each request with a “404 page not found” reply.
1857 <h3 id="RedirectHandler">func <a href="https://golang.org/src/net/http/server.go?s=45249:45299#L1538">RedirectHandler</a></h3>
1858 <pre>func RedirectHandler(url <a href="https://golang.org/pkg/builtin/#string">string</a>, code <a href="https://golang.org/pkg/builtin/#int">int</a>) <a href="https://golang.org/pkg/net/http/#Handler">Handler</a></pre>
1860 RedirectHandler returns a request handler that redirects
1861 each request it receives to the given url using the given
1869 <h3 id="StripPrefix">func <a href="https://golang.org/src/net/http/server.go?s=42404:42454#L1438">StripPrefix</a></h3>
1870 <pre>func StripPrefix(prefix <a href="https://golang.org/pkg/builtin/#string">string</a>, h <a href="https://golang.org/pkg/net/http/#Handler">Handler</a>) <a href="https://golang.org/pkg/net/http/#Handler">Handler</a></pre>
1872 StripPrefix returns a handler that serves HTTP requests
1873 by removing the given prefix from the request URL's Path
1874 and invoking the handler h. StripPrefix handles a
1875 request for a path that doesn't begin with prefix by
1876 replying with an HTTP 404 not found error.
1879 <div id="example_StripPrefix" class="toggle">
1880 <div class="collapsed">
1881 <p class="exampleHeading toggleButton">▹ <span class="text">Example</span></p>
1883 <div class="expanded">
1884 <p class="exampleHeading toggleButton">▾ <span class="text">Example</span></p>
1889 <div class="input"><textarea class="code">package main
1896 // To serve a directory on disk (/tmp) under an alternate URL
1897 // path (/tmpfiles/), use StripPrefix to modify the request
1898 // URL's path before the FileServer sees it:
1899 http.Handle("/tmpfiles/", http.StripPrefix("/tmpfiles/", http.FileServer(http.Dir("/tmp"))))
1902 <div class="output"><pre></pre></div>
1903 <div class="buttons">
1904 <a class="run" title="Run this code [shift-enter]">Run</a>
1905 <a class="fmt" title="Format this code">Format</a>
1916 <h3 id="TimeoutHandler">func <a href="https://golang.org/src/net/http/server.go?s=61275:61343#L2039">TimeoutHandler</a></h3>
1917 <pre>func TimeoutHandler(h <a href="https://golang.org/pkg/net/http/#Handler">Handler</a>, dt <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Duration">Duration</a>, msg <a href="https://golang.org/pkg/builtin/#string">string</a>) <a href="https://golang.org/pkg/net/http/#Handler">Handler</a></pre>
1919 TimeoutHandler returns a Handler that runs h with the given time limit.
1922 The new Handler calls h.ServeHTTP to handle each request, but if a
1923 call runs for longer than its time limit, the handler responds with
1924 a 503 Service Unavailable error and the given message in its body.
1925 (If msg is empty, a suitable default message will be sent.)
1926 After such a timeout, writes by h to its ResponseWriter will return
1938 <h2 id="HandlerFunc">type <a href="https://golang.org/src/net/http/server.go?s=41267:41314#L1408">HandlerFunc</a></h2>
1939 <pre>type HandlerFunc func(<a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, *<a href="https://golang.org/pkg/net/http/#Request">Request</a>)</pre>
1941 The HandlerFunc type is an adapter to allow the use of
1942 ordinary functions as HTTP handlers. If f is a function
1943 with the appropriate signature, HandlerFunc(f) is a
1944 Handler object that calls f.
1960 <h3 id="HandlerFunc.ServeHTTP">func (HandlerFunc) <a href="https://golang.org/src/net/http/server.go?s=41344:41404#L1411">ServeHTTP</a></h3>
1961 <pre>func (f <a href="https://golang.org/pkg/net/http/#HandlerFunc">HandlerFunc</a>) ServeHTTP(w <a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>)</pre>
1963 ServeHTTP calls f(w, r).
1973 <h2 id="Header">type <a href="https://golang.org/src/net/http/header.go?s=350:381#L9">Header</a></h2>
1974 <pre>type Header map[<a href="https://golang.org/pkg/builtin/#string">string</a>][]<a href="https://golang.org/pkg/builtin/#string">string</a></pre>
1976 A Header represents the key-value pairs in an HTTP header.
1992 <h3 id="Header.Add">func (Header) <a href="https://golang.org/src/net/http/header.go?s=488:526#L13">Add</a></h3>
1993 <pre>func (h <a href="https://golang.org/pkg/net/http/#Header">Header</a>) Add(key, value <a href="https://golang.org/pkg/builtin/#string">string</a>)</pre>
1995 Add adds the key, value pair to the header.
1996 It appends to any existing values associated with key.
2004 <h3 id="Header.Del">func (Header) <a href="https://golang.org/src/net/http/header.go?s=1321:1352#L41">Del</a></h3>
2005 <pre>func (h <a href="https://golang.org/pkg/net/http/#Header">Header</a>) Del(key <a href="https://golang.org/pkg/builtin/#string">string</a>)</pre>
2007 Del deletes the values associated with key.
2015 <h3 id="Header.Get">func (Header) <a href="https://golang.org/src/net/http/header.go?s=1015:1053#L28">Get</a></h3>
2016 <pre>func (h <a href="https://golang.org/pkg/net/http/#Header">Header</a>) Get(key <a href="https://golang.org/pkg/builtin/#string">string</a>) <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
2018 Get gets the first value associated with the given key.
2019 If there are no values associated with the key, Get returns "".
2020 To access multiple values of a key, access the map directly
2021 with CanonicalHeaderKey.
2029 <h3 id="Header.Set">func (Header) <a href="https://golang.org/src/net/http/header.go?s=713:751#L20">Set</a></h3>
2030 <pre>func (h <a href="https://golang.org/pkg/net/http/#Header">Header</a>) Set(key, value <a href="https://golang.org/pkg/builtin/#string">string</a>)</pre>
2032 Set sets the header entries associated with key to
2033 the single element value. It replaces any existing
2034 values associated with key.
2042 <h3 id="Header.Write">func (Header) <a href="https://golang.org/src/net/http/header.go?s=1433:1473#L46">Write</a></h3>
2043 <pre>func (h <a href="https://golang.org/pkg/net/http/#Header">Header</a>) Write(w <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#Writer">Writer</a>) <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
2045 Write writes a header in wire format.
2053 <h3 id="Header.WriteSubset">func (Header) <a href="https://golang.org/src/net/http/header.go?s=3676:3747#L135">WriteSubset</a></h3>
2054 <pre>func (h <a href="https://golang.org/pkg/net/http/#Header">Header</a>) WriteSubset(w <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#Writer">Writer</a>, exclude map[<a href="https://golang.org/pkg/builtin/#string">string</a>]<a href="https://golang.org/pkg/builtin/#bool">bool</a>) <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
2056 WriteSubset writes a header in wire format.
2057 If exclude is not nil, keys where exclude[key] == true are not written.
2067 <h2 id="Hijacker">type <a href="https://golang.org/src/net/http/server.go?s=3126:3656#L86">Hijacker</a></h2>
2068 <pre>type Hijacker interface {
2069 <span class="comment">// Hijack lets the caller take over the connection.</span>
2070 <span class="comment">// After a call to Hijack(), the HTTP server library</span>
2071 <span class="comment">// will not do anything else with the connection.</span>
2072 <span class="comment">//</span>
2073 <span class="comment">// It becomes the caller's responsibility to manage</span>
2074 <span class="comment">// and close the connection.</span>
2075 <span class="comment">//</span>
2076 <span class="comment">// The returned net.Conn may have read or write deadlines</span>
2077 <span class="comment">// already set, depending on the configuration of the</span>
2078 <span class="comment">// Server. It is the caller's responsibility to set</span>
2079 <span class="comment">// or clear those deadlines as needed.</span>
2080 Hijack() (<a href="https://golang.org/pkg/net/">net</a>.<a href="https://golang.org/pkg/net/#Conn">Conn</a>, *<a href="https://golang.org/pkg/bufio/">bufio</a>.<a href="https://golang.org/pkg/bufio/#ReadWriter">ReadWriter</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)
2083 The Hijacker interface is implemented by ResponseWriters that allow
2084 an HTTP handler to take over the connection.
2092 <div id="example_Hijacker" class="toggle">
2093 <div class="collapsed">
2094 <p class="exampleHeading toggleButton">▹ <span class="text">Example</span></p>
2096 <div class="expanded">
2097 <p class="exampleHeading toggleButton">▾ <span class="text">Example</span></p>
2102 <div class="input"><textarea class="code">package main
2111 http.HandleFunc("/hijack", func(w http.ResponseWriter, r *http.Request) {
2112 hj, ok := w.(http.Hijacker)
2114 http.Error(w, "webserver doesn't support hijacking", http.StatusInternalServerError)
2117 conn, bufrw, err := hj.Hijack()
2119 http.Error(w, err.Error(), http.StatusInternalServerError)
2122 // Don't forget to close the connection:
2124 bufrw.WriteString("Now we're speaking raw TCP. Say hi: ")
2126 s, err := bufrw.ReadString('\n')
2128 log.Printf("error reading string: %v", err)
2131 fmt.Fprintf(bufrw, "You said: %q\nBye.\n", s)
2136 <div class="output"><pre></pre></div>
2137 <div class="buttons">
2138 <a class="run" title="Run this code [shift-enter]">Run</a>
2139 <a class="fmt" title="Format this code">Format</a>
2156 <h2 id="ProtocolError">type <a href="https://golang.org/src/net/http/request.go?s=668:717#L26">ProtocolError</a></h2>
2157 <pre>type ProtocolError struct {
2158 ErrorString <a href="https://golang.org/pkg/builtin/#string">string</a>
2161 HTTP request parsing errors.
2177 <h3 id="ProtocolError.Error">func (*ProtocolError) <a href="https://golang.org/src/net/http/request.go?s=719:759#L30">Error</a></h3>
2178 <pre>func (err *<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>) Error() <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
2187 <h2 id="Request">type <a href="https://golang.org/src/net/http/request.go?s=2057:8270#L64">Request</a></h2>
2188 <pre>type Request struct {
2189 <span class="comment">// Method specifies the HTTP method (GET, POST, PUT, etc.).</span>
2190 <span class="comment">// For client requests an empty string means GET.</span>
2191 Method <a href="https://golang.org/pkg/builtin/#string">string</a>
2193 <span class="comment">// URL specifies either the URI being requested (for server</span>
2194 <span class="comment">// requests) or the URL to access (for client requests).</span>
2195 <span class="comment">//</span>
2196 <span class="comment">// For server requests the URL is parsed from the URI</span>
2197 <span class="comment">// supplied on the Request-Line as stored in RequestURI. For</span>
2198 <span class="comment">// most requests, fields other than Path and RawQuery will be</span>
2199 <span class="comment">// empty. (See RFC 2616, Section 5.1.2)</span>
2200 <span class="comment">//</span>
2201 <span class="comment">// For client requests, the URL's Host specifies the server to</span>
2202 <span class="comment">// connect to, while the Request's Host field optionally</span>
2203 <span class="comment">// specifies the Host header value to send in the HTTP</span>
2204 <span class="comment">// request.</span>
2205 URL *<a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#URL">URL</a>
2207 <span class="comment">// The protocol version for incoming requests.</span>
2208 <span class="comment">// Client requests always use HTTP/1.1.</span>
2209 Proto <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// "HTTP/1.0"</span>
2210 ProtoMajor <a href="https://golang.org/pkg/builtin/#int">int</a> <span class="comment">// 1</span>
2211 ProtoMinor <a href="https://golang.org/pkg/builtin/#int">int</a> <span class="comment">// 0</span>
2213 <span class="comment">// A header maps request lines to their values.</span>
2214 <span class="comment">// If the header says</span>
2215 <span class="comment">//</span>
2216 <span class="comment">// accept-encoding: gzip, deflate</span>
2217 <span class="comment">// Accept-Language: en-us</span>
2218 <span class="comment">// Connection: keep-alive</span>
2219 <span class="comment">//</span>
2220 <span class="comment">// then</span>
2221 <span class="comment">//</span>
2222 <span class="comment">// Header = map[string][]string{</span>
2223 <span class="comment">// "Accept-Encoding": {"gzip, deflate"},</span>
2224 <span class="comment">// "Accept-Language": {"en-us"},</span>
2225 <span class="comment">// "Connection": {"keep-alive"},</span>
2226 <span class="comment">// }</span>
2227 <span class="comment">//</span>
2228 <span class="comment">// HTTP defines that header names are case-insensitive.</span>
2229 <span class="comment">// The request parser implements this by canonicalizing the</span>
2230 <span class="comment">// name, making the first character and any characters</span>
2231 <span class="comment">// following a hyphen uppercase and the rest lowercase.</span>
2232 <span class="comment">//</span>
2233 <span class="comment">// For client requests certain headers are automatically</span>
2234 <span class="comment">// added and may override values in Header.</span>
2235 <span class="comment">//</span>
2236 <span class="comment">// See the documentation for the Request.Write method.</span>
2237 Header <a href="https://golang.org/pkg/net/http/#Header">Header</a>
2239 <span class="comment">// Body is the request's body.</span>
2240 <span class="comment">//</span>
2241 <span class="comment">// For client requests a nil body means the request has no</span>
2242 <span class="comment">// body, such as a GET request. The HTTP Client's Transport</span>
2243 <span class="comment">// is responsible for calling the Close method.</span>
2244 <span class="comment">//</span>
2245 <span class="comment">// For server requests the Request Body is always non-nil</span>
2246 <span class="comment">// but will return EOF immediately when no body is present.</span>
2247 <span class="comment">// The Server will close the request body. The ServeHTTP</span>
2248 <span class="comment">// Handler does not need to.</span>
2249 Body <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#ReadCloser">ReadCloser</a>
2251 <span class="comment">// ContentLength records the length of the associated content.</span>
2252 <span class="comment">// The value -1 indicates that the length is unknown.</span>
2253 <span class="comment">// Values >= 0 indicate that the given number of bytes may</span>
2254 <span class="comment">// be read from Body.</span>
2255 <span class="comment">// For client requests, a value of 0 means unknown if Body is not nil.</span>
2256 ContentLength <a href="https://golang.org/pkg/builtin/#int64">int64</a>
2258 <span class="comment">// TransferEncoding lists the transfer encodings from outermost to</span>
2259 <span class="comment">// innermost. An empty list denotes the "identity" encoding.</span>
2260 <span class="comment">// TransferEncoding can usually be ignored; chunked encoding is</span>
2261 <span class="comment">// automatically added and removed as necessary when sending and</span>
2262 <span class="comment">// receiving requests.</span>
2263 TransferEncoding []<a href="https://golang.org/pkg/builtin/#string">string</a>
2265 <span class="comment">// Close indicates whether to close the connection after</span>
2266 <span class="comment">// replying to this request (for servers) or after sending</span>
2267 <span class="comment">// the request (for clients).</span>
2268 Close <a href="https://golang.org/pkg/builtin/#bool">bool</a>
2270 <span class="comment">// For server requests Host specifies the host on which the</span>
2271 <span class="comment">// URL is sought. Per RFC 2616, this is either the value of</span>
2272 <span class="comment">// the "Host" header or the host name given in the URL itself.</span>
2273 <span class="comment">// It may be of the form "host:port".</span>
2274 <span class="comment">//</span>
2275 <span class="comment">// For client requests Host optionally overrides the Host</span>
2276 <span class="comment">// header to send. If empty, the Request.Write method uses</span>
2277 <span class="comment">// the value of URL.Host.</span>
2278 Host <a href="https://golang.org/pkg/builtin/#string">string</a>
2280 <span class="comment">// Form contains the parsed form data, including both the URL</span>
2281 <span class="comment">// field's query parameters and the POST or PUT form data.</span>
2282 <span class="comment">// This field is only available after ParseForm is called.</span>
2283 <span class="comment">// The HTTP client ignores Form and uses Body instead.</span>
2284 Form <a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#Values">Values</a>
2286 <span class="comment">// PostForm contains the parsed form data from POST, PATCH,</span>
2287 <span class="comment">// or PUT body parameters.</span>
2288 <span class="comment">//</span>
2289 <span class="comment">// This field is only available after ParseForm is called.</span>
2290 <span class="comment">// The HTTP client ignores PostForm and uses Body instead.</span>
2291 PostForm <a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#Values">Values</a>
2293 <span class="comment">// MultipartForm is the parsed multipart form, including file uploads.</span>
2294 <span class="comment">// This field is only available after ParseMultipartForm is called.</span>
2295 <span class="comment">// The HTTP client ignores MultipartForm and uses Body instead.</span>
2296 MultipartForm *<a href="https://golang.org/pkg/mime/multipart/">multipart</a>.<a href="https://golang.org/pkg/mime/multipart/#Form">Form</a>
2298 <span class="comment">// Trailer specifies additional headers that are sent after the request</span>
2299 <span class="comment">// body.</span>
2300 <span class="comment">//</span>
2301 <span class="comment">// For server requests the Trailer map initially contains only the</span>
2302 <span class="comment">// trailer keys, with nil values. (The client declares which trailers it</span>
2303 <span class="comment">// will later send.) While the handler is reading from Body, it must</span>
2304 <span class="comment">// not reference Trailer. After reading from Body returns EOF, Trailer</span>
2305 <span class="comment">// can be read again and will contain non-nil values, if they were sent</span>
2306 <span class="comment">// by the client.</span>
2307 <span class="comment">//</span>
2308 <span class="comment">// For client requests Trailer must be initialized to a map containing</span>
2309 <span class="comment">// the trailer keys to later send. The values may be nil or their final</span>
2310 <span class="comment">// values. The ContentLength must be 0 or -1, to send a chunked request.</span>
2311 <span class="comment">// After the HTTP request is sent the map values can be updated while</span>
2312 <span class="comment">// the request body is read. Once the body returns EOF, the caller must</span>
2313 <span class="comment">// not mutate Trailer.</span>
2314 <span class="comment">//</span>
2315 <span class="comment">// Few HTTP clients, servers, or proxies support HTTP trailers.</span>
2316 Trailer <a href="https://golang.org/pkg/net/http/#Header">Header</a>
2318 <span class="comment">// RemoteAddr allows HTTP servers and other software to record</span>
2319 <span class="comment">// the network address that sent the request, usually for</span>
2320 <span class="comment">// logging. This field is not filled in by ReadRequest and</span>
2321 <span class="comment">// has no defined format. The HTTP server in this package</span>
2322 <span class="comment">// sets RemoteAddr to an "IP:port" address before invoking a</span>
2323 <span class="comment">// handler.</span>
2324 <span class="comment">// This field is ignored by the HTTP client.</span>
2325 RemoteAddr <a href="https://golang.org/pkg/builtin/#string">string</a>
2327 <span class="comment">// RequestURI is the unmodified Request-URI of the</span>
2328 <span class="comment">// Request-Line (RFC 2616, Section 5.1) as sent by the client</span>
2329 <span class="comment">// to a server. Usually the URL field should be used instead.</span>
2330 <span class="comment">// It is an error to set this field in an HTTP client request.</span>
2331 RequestURI <a href="https://golang.org/pkg/builtin/#string">string</a>
2333 <span class="comment">// TLS allows HTTP servers and other software to record</span>
2334 <span class="comment">// information about the TLS connection on which the request</span>
2335 <span class="comment">// was received. This field is not filled in by ReadRequest.</span>
2336 <span class="comment">// The HTTP server in this package sets the field for</span>
2337 <span class="comment">// TLS-enabled connections before invoking a handler;</span>
2338 <span class="comment">// otherwise it leaves the field nil.</span>
2339 <span class="comment">// This field is ignored by the HTTP client.</span>
2340 TLS *<a href="https://golang.org/pkg/crypto/tls/">tls</a>.<a href="https://golang.org/pkg/crypto/tls/#ConnectionState">ConnectionState</a>
2342 <span class="comment">// Cancel is an optional channel whose closure indicates that the client</span>
2343 <span class="comment">// request should be regarded as canceled. Not all implementations of</span>
2344 <span class="comment">// RoundTripper may support Cancel.</span>
2345 <span class="comment">//</span>
2346 <span class="comment">// For server requests, this field is not applicable.</span>
2347 Cancel <-chan struct{}
2350 A Request represents an HTTP request received by a server
2351 or to be sent by a client.
2354 The field semantics differ slightly between client and server
2355 usage. In addition to the notes on the fields below, see the
2356 documentation for Request.Write and RoundTripper.
2370 <h3 id="NewRequest">func <a href="https://golang.org/src/net/http/request.go?s=17718:17790#L536">NewRequest</a></h3>
2371 <pre>func NewRequest(method, urlStr <a href="https://golang.org/pkg/builtin/#string">string</a>, body <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#Reader">Reader</a>) (*<a href="https://golang.org/pkg/net/http/#Request">Request</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
2373 NewRequest returns a new Request given a method, URL, and optional body.
2376 If the provided body is also an io.Closer, the returned
2377 Request.Body is set to body and will be closed by the Client
2378 methods Do, Post, and PostForm, and Transport.RoundTrip.
2381 NewRequest returns a Request suitable for use with Client.Do or
2382 Transport.RoundTrip.
2383 To create a request for use with testing a Server Handler use either
2384 ReadRequest or manually update the Request fields. See the Request
2385 type's documentation for the difference between inbound and outbound
2393 <h3 id="ReadRequest">func <a href="https://golang.org/src/net/http/request.go?s=20301:20360#L636">ReadRequest</a></h3>
2394 <pre>func ReadRequest(b *<a href="https://golang.org/pkg/bufio/">bufio</a>.<a href="https://golang.org/pkg/bufio/#Reader">Reader</a>) (req *<a href="https://golang.org/pkg/net/http/#Request">Request</a>, err <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
2396 ReadRequest reads and parses an incoming request from b.
2405 <h3 id="Request.AddCookie">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=9423:9461#L259">AddCookie</a></h3>
2406 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) AddCookie(c *<a href="https://golang.org/pkg/net/http/#Cookie">Cookie</a>)</pre>
2408 AddCookie adds a cookie to the request. Per RFC 6265 section 5.4,
2409 AddCookie does not attach more than one Cookie header field. That
2410 means all cookies, if any, are written into the same line,
2411 separated by semicolon.
2419 <h3 id="Request.BasicAuth">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=18567:18633#L572">BasicAuth</a></h3>
2420 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) BasicAuth() (username, password <a href="https://golang.org/pkg/builtin/#string">string</a>, ok <a href="https://golang.org/pkg/builtin/#bool">bool</a>)</pre>
2422 BasicAuth returns the username and password provided in the request's
2423 Authorization header, if the request uses HTTP Basic Authentication.
2424 See RFC 2617, Section 2.
2432 <h3 id="Request.Cookie">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=9041:9095#L248">Cookie</a></h3>
2433 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) Cookie(name <a href="https://golang.org/pkg/builtin/#string">string</a>) (*<a href="https://golang.org/pkg/net/http/#Cookie">Cookie</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
2435 Cookie returns the named cookie provided in the request or
2436 ErrNoCookie if not found.
2444 <h3 id="Request.Cookies">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=8727:8764#L239">Cookies</a></h3>
2445 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) Cookies() []*<a href="https://golang.org/pkg/net/http/#Cookie">Cookie</a></pre>
2447 Cookies parses and returns the HTTP cookies sent with the request.
2455 <h3 id="Request.FormFile">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=29076:29161#L960">FormFile</a></h3>
2456 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) FormFile(key <a href="https://golang.org/pkg/builtin/#string">string</a>) (<a href="https://golang.org/pkg/mime/multipart/">multipart</a>.<a href="https://golang.org/pkg/mime/multipart/#File">File</a>, *<a href="https://golang.org/pkg/mime/multipart/">multipart</a>.<a href="https://golang.org/pkg/mime/multipart/#FileHeader">FileHeader</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
2458 FormFile returns the first file for the provided form key.
2459 FormFile calls ParseMultipartForm and ParseForm if necessary.
2467 <h3 id="Request.FormValue">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=28248:28294#L933">FormValue</a></h3>
2468 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) FormValue(key <a href="https://golang.org/pkg/builtin/#string">string</a>) <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
2470 FormValue returns the first value for the named component of the query.
2471 POST and PUT body parameters take precedence over URL query string values.
2472 FormValue calls ParseMultipartForm and ParseForm if necessary and ignores
2473 any errors returned by these functions.
2474 If key is not present, FormValue returns the empty string.
2475 To access multiple values of the same key, call ParseForm and
2476 then inspect Request.Form directly.
2484 <h3 id="Request.MultipartReader">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=10760:10822#L292">MultipartReader</a></h3>
2485 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) MultipartReader() (*<a href="https://golang.org/pkg/mime/multipart/">multipart</a>.<a href="https://golang.org/pkg/mime/multipart/#Reader">Reader</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
2487 MultipartReader returns a MIME multipart reader if this is a
2488 multipart/form-data POST request, else returns nil and an error.
2489 Use this function instead of ParseMultipartForm to
2490 process the request body as a stream.
2498 <h3 id="Request.ParseForm">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=26212:26247#L854">ParseForm</a></h3>
2499 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) ParseForm() <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
2501 ParseForm parses the raw query from the URL and updates r.Form.
2504 For POST or PUT requests, it also parses the request body as a form and
2505 put the results into both r.PostForm and r.Form.
2506 POST and PUT body parameters take precedence over URL query string values
2510 If the request Body's size has not already been limited by MaxBytesReader,
2511 the size is capped at 10MB.
2514 ParseMultipartForm calls ParseForm automatically.
2523 <h3 id="Request.ParseMultipartForm">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=27267:27326#L895">ParseMultipartForm</a></h3>
2524 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) ParseMultipartForm(maxMemory <a href="https://golang.org/pkg/builtin/#int64">int64</a>) <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
2526 ParseMultipartForm parses a request body as multipart/form-data.
2527 The whole request body is parsed and up to a total of maxMemory bytes of
2528 its file parts are stored in memory, with the remainder stored on
2529 disk in temporary files.
2530 ParseMultipartForm calls ParseForm if necessary.
2531 After one call to ParseMultipartForm, subsequent calls have no effect.
2539 <h3 id="Request.PostFormValue">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=28755:28805#L948">PostFormValue</a></h3>
2540 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) PostFormValue(key <a href="https://golang.org/pkg/builtin/#string">string</a>) <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
2542 PostFormValue returns the first value for the named component of the POST
2543 or PUT request body. URL query parameters are ignored.
2544 PostFormValue calls ParseMultipartForm and ParseForm if necessary and ignores
2545 any errors returned by these functions.
2546 If key is not present, PostFormValue returns the empty string.
2554 <h3 id="Request.ProtoAtLeast">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=8370:8423#L228">ProtoAtLeast</a></h3>
2555 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) ProtoAtLeast(major, minor <a href="https://golang.org/pkg/builtin/#int">int</a>) <a href="https://golang.org/pkg/builtin/#bool">bool</a></pre>
2557 ProtoAtLeast reports whether the HTTP protocol used
2558 in the request is at least major.minor.
2566 <h3 id="Request.Referer">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=10131:10165#L276">Referer</a></h3>
2567 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) Referer() <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
2569 Referer returns the referring URL, if sent in the request.
2572 Referer is misspelled as in the request itself, a mistake from the
2573 earliest days of HTTP. This value can also be fetched from the
2574 Header map as Header["Referer"]; the benefit of making it available
2575 as a method is that the compiler can diagnose programs that use the
2576 alternate (correct English) spelling req.Referrer() but cannot
2577 diagnose programs that use Header["Referrer"].
2585 <h3 id="Request.SetBasicAuth">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=19455:19512#L604">SetBasicAuth</a></h3>
2586 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) SetBasicAuth(username, password <a href="https://golang.org/pkg/builtin/#string">string</a>)</pre>
2588 SetBasicAuth sets the request's Authorization header to use HTTP
2589 Basic Authentication with the provided username and password.
2592 With HTTP Basic Authentication the provided username and password
2601 <h3 id="Request.UserAgent">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=8580:8616#L234">UserAgent</a></h3>
2602 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) UserAgent() <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
2604 UserAgent returns the client's User-Agent, if sent in the request.
2612 <h3 id="Request.Write">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=12411:12453#L346">Write</a></h3>
2613 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) Write(w <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#Writer">Writer</a>) <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
2615 Write writes an HTTP/1.1 request, which is the header and body, in wire format.
2616 This method consults the following fields of the request:
2620 Method (defaults to "GET")
2627 If Body is present, Content-Length is <= 0 and TransferEncoding
2628 hasn't been set to "identity", Write adds "Transfer-Encoding:
2629 chunked" to the header. Body is closed after it is sent.
2637 <h3 id="Request.WriteProxy">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=12846:12893#L356">WriteProxy</a></h3>
2638 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) WriteProxy(w <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#Writer">Writer</a>) <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
2640 WriteProxy is like Write but writes the request in the form
2641 expected by an HTTP proxy. In particular, WriteProxy writes the
2642 initial Request-URI line of the request with an absolute URI, per
2643 section 5.1.2 of RFC 2616, including the scheme and host.
2644 In either case, WriteProxy also writes a Host header, using
2645 either r.Host or r.URL.Host.
2655 <h2 id="Response">type <a href="https://golang.org/src/net/http/response.go?s=512:2849#L19">Response</a></h2>
2656 <pre>type Response struct {
2657 Status <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// e.g. "200 OK"</span>
2658 StatusCode <a href="https://golang.org/pkg/builtin/#int">int</a> <span class="comment">// e.g. 200</span>
2659 Proto <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// e.g. "HTTP/1.0"</span>
2660 ProtoMajor <a href="https://golang.org/pkg/builtin/#int">int</a> <span class="comment">// e.g. 1</span>
2661 ProtoMinor <a href="https://golang.org/pkg/builtin/#int">int</a> <span class="comment">// e.g. 0</span>
2663 <span class="comment">// Header maps header keys to values. If the response had multiple</span>
2664 <span class="comment">// headers with the same key, they may be concatenated, with comma</span>
2665 <span class="comment">// delimiters. (Section 4.2 of RFC 2616 requires that multiple headers</span>
2666 <span class="comment">// be semantically equivalent to a comma-delimited sequence.) Values</span>
2667 <span class="comment">// duplicated by other fields in this struct (e.g., ContentLength) are</span>
2668 <span class="comment">// omitted from Header.</span>
2669 <span class="comment">//</span>
2670 <span class="comment">// Keys in the map are canonicalized (see CanonicalHeaderKey).</span>
2671 Header <a href="https://golang.org/pkg/net/http/#Header">Header</a>
2673 <span class="comment">// Body represents the response body.</span>
2674 <span class="comment">//</span>
2675 <span class="comment">// The http Client and Transport guarantee that Body is always</span>
2676 <span class="comment">// non-nil, even on responses without a body or responses with</span>
2677 <span class="comment">// a zero-length body. It is the caller's responsibility to</span>
2678 <span class="comment">// close Body. The default HTTP client's Transport does not</span>
2679 <span class="comment">// attempt to reuse HTTP/1.0 or HTTP/1.1 TCP connections</span>
2680 <span class="comment">// ("keep-alive") unless the Body is read to completion and is</span>
2681 <span class="comment">// closed.</span>
2682 <span class="comment">//</span>
2683 <span class="comment">// The Body is automatically dechunked if the server replied</span>
2684 <span class="comment">// with a "chunked" Transfer-Encoding.</span>
2685 Body <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#ReadCloser">ReadCloser</a>
2687 <span class="comment">// ContentLength records the length of the associated content. The</span>
2688 <span class="comment">// value -1 indicates that the length is unknown. Unless Request.Method</span>
2689 <span class="comment">// is "HEAD", values >= 0 indicate that the given number of bytes may</span>
2690 <span class="comment">// be read from Body.</span>
2691 ContentLength <a href="https://golang.org/pkg/builtin/#int64">int64</a>
2693 <span class="comment">// Contains transfer encodings from outer-most to inner-most. Value is</span>
2694 <span class="comment">// nil, means that "identity" encoding is used.</span>
2695 TransferEncoding []<a href="https://golang.org/pkg/builtin/#string">string</a>
2697 <span class="comment">// Close records whether the header directed that the connection be</span>
2698 <span class="comment">// closed after reading Body. The value is advice for clients: neither</span>
2699 <span class="comment">// ReadResponse nor Response.Write ever closes a connection.</span>
2700 Close <a href="https://golang.org/pkg/builtin/#bool">bool</a>
2702 <span class="comment">// Trailer maps trailer keys to values, in the same</span>
2703 <span class="comment">// format as the header.</span>
2704 Trailer <a href="https://golang.org/pkg/net/http/#Header">Header</a>
2706 <span class="comment">// The Request that was sent to obtain this Response.</span>
2707 <span class="comment">// Request's Body is nil (having already been consumed).</span>
2708 <span class="comment">// This is only populated for Client requests.</span>
2709 Request *<a href="https://golang.org/pkg/net/http/#Request">Request</a>
2711 <span class="comment">// TLS contains information about the TLS connection on which the</span>
2712 <span class="comment">// response was received. It is nil for unencrypted responses.</span>
2713 <span class="comment">// The pointer is shared between responses and should not be</span>
2714 <span class="comment">// modified.</span>
2715 TLS *<a href="https://golang.org/pkg/crypto/tls/">tls</a>.<a href="https://golang.org/pkg/crypto/tls/#ConnectionState">ConnectionState</a>
2718 Response represents the response from an HTTP request.
2732 <h3 id="Get">func <a href="https://golang.org/src/net/http/client.go?s=9198:9246#L270">Get</a></h3>
2733 <pre>func Get(url <a href="https://golang.org/pkg/builtin/#string">string</a>) (resp *<a href="https://golang.org/pkg/net/http/#Response">Response</a>, err <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
2735 Get issues a GET to the specified URL. If the response is one of
2736 the following redirect codes, Get follows the redirect, up to a
2737 maximum of 10 redirects:
2739 <pre>301 (Moved Permanently)
2742 307 (Temporary Redirect)
2745 An error is returned if there were too many redirects or if there
2746 was an HTTP protocol error. A non-2xx response doesn't cause an
2750 When err is nil, resp always contains a non-nil resp.Body.
2751 Caller should close resp.Body when done reading from it.
2754 Get is a wrapper around DefaultClient.Get.
2757 To make a request with custom headers, use NewRequest and
2761 <div id="example_Get" class="toggle">
2762 <div class="collapsed">
2763 <p class="exampleHeading toggleButton">▹ <span class="text">Example</span></p>
2765 <div class="expanded">
2766 <p class="exampleHeading toggleButton">▾ <span class="text">Example</span></p>
2771 <div class="input"><textarea class="code">package main
2781 res, err := http.Get("http://www.google.com/robots.txt")
2785 robots, err := ioutil.ReadAll(res.Body)
2790 fmt.Printf("%s", robots)
2793 <div class="output"><pre></pre></div>
2794 <div class="buttons">
2795 <a class="run" title="Run this code [shift-enter]">Run</a>
2796 <a class="fmt" title="Format this code">Format</a>
2807 <h3 id="Head">func <a href="https://golang.org/src/net/http/client.go?s=15901:15950#L500">Head</a></h3>
2808 <pre>func Head(url <a href="https://golang.org/pkg/builtin/#string">string</a>) (resp *<a href="https://golang.org/pkg/net/http/#Response">Response</a>, err <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
2810 Head issues a HEAD to the specified URL. If the response is one of
2811 the following redirect codes, Head follows the redirect, up to a
2812 maximum of 10 redirects:
2814 <pre>301 (Moved Permanently)
2817 307 (Temporary Redirect)
2820 Head is a wrapper around DefaultClient.Head
2827 <h3 id="Post">func <a href="https://golang.org/src/net/http/client.go?s=13816:13898#L443">Post</a></h3>
2828 <pre>func Post(url <a href="https://golang.org/pkg/builtin/#string">string</a>, bodyType <a href="https://golang.org/pkg/builtin/#string">string</a>, body <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#Reader">Reader</a>) (resp *<a href="https://golang.org/pkg/net/http/#Response">Response</a>, err <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
2830 Post issues a POST to the specified URL.
2833 Caller should close resp.Body when done reading from it.
2836 If the provided body is an io.Closer, it is closed after the
2840 Post is a wrapper around DefaultClient.Post.
2843 To set custom headers, use NewRequest and DefaultClient.Do.
2850 <h3 id="PostForm">func <a href="https://golang.org/src/net/http/client.go?s=14909:14979#L474">PostForm</a></h3>
2851 <pre>func PostForm(url <a href="https://golang.org/pkg/builtin/#string">string</a>, data <a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#Values">Values</a>) (resp *<a href="https://golang.org/pkg/net/http/#Response">Response</a>, err <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
2853 PostForm issues a POST to the specified URL, with data's keys and
2854 values URL-encoded as the request body.
2857 The Content-Type header is set to application/x-www-form-urlencoded.
2858 To set other headers, use NewRequest and DefaultClient.Do.
2861 When err is nil, resp always contains a non-nil resp.Body.
2862 Caller should close resp.Body when done reading from it.
2865 PostForm is a wrapper around DefaultClient.PostForm.
2872 <h3 id="ReadResponse">func <a href="https://golang.org/src/net/http/response.go?s=3992:4059#L111">ReadResponse</a></h3>
2873 <pre>func ReadResponse(r *<a href="https://golang.org/pkg/bufio/">bufio</a>.<a href="https://golang.org/pkg/bufio/#Reader">Reader</a>, req *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) (*<a href="https://golang.org/pkg/net/http/#Response">Response</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
2875 ReadResponse reads and returns an HTTP response from r.
2876 The req parameter optionally specifies the Request that corresponds
2877 to this Response. If nil, a GET request is assumed.
2878 Clients must call resp.Body.Close when finished reading resp.Body.
2879 After that call, clients can inspect resp.Trailer to find key/value
2880 pairs included in the response trailer.
2889 <h3 id="Response.Cookies">func (*Response) <a href="https://golang.org/src/net/http/response.go?s=2924:2962#L82">Cookies</a></h3>
2890 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Response">Response</a>) Cookies() []*<a href="https://golang.org/pkg/net/http/#Cookie">Cookie</a></pre>
2892 Cookies parses and returns the cookies set in the Set-Cookie headers.
2900 <h3 id="Response.Location">func (*Response) <a href="https://golang.org/src/net/http/response.go?s=3387:3434#L94">Location</a></h3>
2901 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Response">Response</a>) Location() (*<a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#URL">URL</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
2903 Location returns the URL of the response's "Location" header,
2904 if present. Relative redirects are resolved relative to
2905 the Response's Request. ErrNoLocation is returned if no
2906 Location header is present.
2914 <h3 id="Response.ProtoAtLeast">func (*Response) <a href="https://golang.org/src/net/http/response.go?s=5570:5624#L179">ProtoAtLeast</a></h3>
2915 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Response">Response</a>) ProtoAtLeast(major, minor <a href="https://golang.org/pkg/builtin/#int">int</a>) <a href="https://golang.org/pkg/builtin/#bool">bool</a></pre>
2917 ProtoAtLeast reports whether the HTTP protocol used
2918 in the response is at least major.minor.
2926 <h3 id="Response.Write">func (*Response) <a href="https://golang.org/src/net/http/response.go?s=6162:6205#L200">Write</a></h3>
2927 <pre>func (r *<a href="https://golang.org/pkg/net/http/#Response">Response</a>) Write(w <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#Writer">Writer</a>) <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
2929 Write writes r to w in the HTTP/1.n server response format,
2930 including the status line, headers, body, and optional trailer.
2933 This method consults the following fields of the response r:
2943 Header, values for non-canonical keys will have unpredictable behavior
2946 The Response Body is closed after it is sent.
2956 <h2 id="ResponseWriter">type <a href="https://golang.org/src/net/http/server.go?s=1517:2599#L48">ResponseWriter</a></h2>
2957 <pre>type ResponseWriter interface {
2958 <span class="comment">// Header returns the header map that will be sent by</span>
2959 <span class="comment">// WriteHeader. Changing the header after a call to</span>
2960 <span class="comment">// WriteHeader (or Write) has no effect unless the modified</span>
2961 <span class="comment">// headers were declared as trailers by setting the</span>
2962 <span class="comment">// "Trailer" header before the call to WriteHeader (see example).</span>
2963 <span class="comment">// To suppress implicit response headers, set their value to nil.</span>
2964 Header() <a href="https://golang.org/pkg/net/http/#Header">Header</a>
2966 <span class="comment">// Write writes the data to the connection as part of an HTTP reply.</span>
2967 <span class="comment">// If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK)</span>
2968 <span class="comment">// before writing the data. If the Header does not contain a</span>
2969 <span class="comment">// Content-Type line, Write adds a Content-Type set to the result of passing</span>
2970 <span class="comment">// the initial 512 bytes of written data to DetectContentType.</span>
2971 Write([]<a href="https://golang.org/pkg/builtin/#byte">byte</a>) (<a href="https://golang.org/pkg/builtin/#int">int</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)
2973 <span class="comment">// WriteHeader sends an HTTP response header with status code.</span>
2974 <span class="comment">// If WriteHeader is not called explicitly, the first call to Write</span>
2975 <span class="comment">// will trigger an implicit WriteHeader(http.StatusOK).</span>
2976 <span class="comment">// Thus explicit calls to WriteHeader are mainly used to</span>
2977 <span class="comment">// send error codes.</span>
2978 WriteHeader(<a href="https://golang.org/pkg/builtin/#int">int</a>)
2981 A ResponseWriter interface is used by an HTTP handler to
2982 construct an HTTP response.
2990 <div id="example_ResponseWriter_trailers" class="toggle">
2991 <div class="collapsed">
2992 <p class="exampleHeading toggleButton">▹ <span class="text">Example (Trailers)</span></p>
2994 <div class="expanded">
2995 <p class="exampleHeading toggleButton">▾ <span class="text">Example (Trailers)</span></p>
2996 <p>HTTP Trailers are a set of key/value pairs like headers that come
2997 after the HTTP response, instead of before.
3002 <div class="input"><textarea class="code">package main
3010 mux := http.NewServeMux()
3011 mux.HandleFunc("/sendstrailers", func(w http.ResponseWriter, req *http.Request) {
3012 // Before any call to WriteHeader or Write, declare
3013 // the trailers you will set during the HTTP
3014 // response. These three headers are actually sent in
3016 w.Header().Set("Trailer", "AtEnd1, AtEnd2")
3017 w.Header().Add("Trailer", "AtEnd3")
3019 w.Header().Set("Content-Type", "text/plain; charset=utf-8") // normal header
3020 w.WriteHeader(http.StatusOK)
3022 w.Header().Set("AtEnd1", "value 1")
3023 io.WriteString(w, "This HTTP response has both headers before this text and trailers at the end.\n")
3024 w.Header().Set("AtEnd2", "value 2")
3025 w.Header().Set("AtEnd3", "value 3") // These will appear as trailers.
3029 <div class="output"><pre></pre></div>
3030 <div class="buttons">
3031 <a class="run" title="Run this code [shift-enter]">Run</a>
3032 <a class="fmt" title="Format this code">Format</a>
3049 <h2 id="RoundTripper">type <a href="https://golang.org/src/net/http/client.go?s=2750:3517#L73">RoundTripper</a></h2>
3050 <pre>type RoundTripper interface {
3051 <span class="comment">// RoundTrip executes a single HTTP transaction, returning</span>
3052 <span class="comment">// the Response for the request req. RoundTrip should not</span>
3053 <span class="comment">// attempt to interpret the response. In particular,</span>
3054 <span class="comment">// RoundTrip must return err == nil if it obtained a response,</span>
3055 <span class="comment">// regardless of the response's HTTP status code. A non-nil</span>
3056 <span class="comment">// err should be reserved for failure to obtain a response.</span>
3057 <span class="comment">// Similarly, RoundTrip should not attempt to handle</span>
3058 <span class="comment">// higher-level protocol details such as redirects,</span>
3059 <span class="comment">// authentication, or cookies.</span>
3060 <span class="comment">//</span>
3061 <span class="comment">// RoundTrip should not modify the request, except for</span>
3062 <span class="comment">// consuming and closing the Body, including on errors. The</span>
3063 <span class="comment">// request's URL and Header fields are guaranteed to be</span>
3064 <span class="comment">// initialized.</span>
3065 RoundTrip(*<a href="https://golang.org/pkg/net/http/#Request">Request</a>) (*<a href="https://golang.org/pkg/net/http/#Response">Response</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)
3068 RoundTripper is an interface representing the ability to execute a
3069 single HTTP transaction, obtaining the Response for a given Request.
3072 A RoundTripper must be safe for concurrent use by multiple
3080 <pre>var <span id="DefaultTransport">DefaultTransport</span> <a href="https://golang.org/pkg/net/http/#RoundTripper">RoundTripper</a> = &<a href="https://golang.org/pkg/net/http/#Transport">Transport</a>{
3081 <a href="https://golang.org/pkg/net/http/#Proxy">Proxy</a>: <a href="https://golang.org/pkg/net/http/#ProxyFromEnvironment">ProxyFromEnvironment</a>,
3082 <a href="https://golang.org/pkg/net/http/#Dial">Dial</a>: (&<a href="https://golang.org/pkg/net/">net</a>.<a href="https://golang.org/pkg/net/#Dialer">Dialer</a>{
3083 <a href="https://golang.org/pkg/net/http/#Timeout">Timeout</a>: 30 * <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Second">Second</a>,
3084 <a href="https://golang.org/pkg/net/http/#KeepAlive">KeepAlive</a>: 30 * <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Second">Second</a>,
3085 }).<a href="https://golang.org/pkg/net/http/#Dial">Dial</a>,
3086 <a href="https://golang.org/pkg/net/http/#TLSHandshakeTimeout">TLSHandshakeTimeout</a>: 10 * <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Second">Second</a>,
3089 DefaultTransport is the default implementation of Transport and is
3090 used by DefaultClient. It establishes network connections as needed
3091 and caches them for reuse by subsequent calls. It uses HTTP proxies
3092 as directed by the $HTTP_PROXY and $NO_PROXY (or $http_proxy and
3093 $no_proxy) environment variables.
3104 <h3 id="NewFileTransport">func <a href="https://golang.org/src/net/http/filetransport.go?s=827:876#L20">NewFileTransport</a></h3>
3105 <pre>func NewFileTransport(fs <a href="https://golang.org/pkg/net/http/#FileSystem">FileSystem</a>) <a href="https://golang.org/pkg/net/http/#RoundTripper">RoundTripper</a></pre>
3107 NewFileTransport returns a new RoundTripper, serving the provided
3108 FileSystem. The returned RoundTripper ignores the URL host in its
3109 incoming requests, as well as most other properties of the
3113 The typical use case for NewFileTransport is to register the "file"
3114 protocol with a Transport, as in:
3116 <pre>t := &http.Transport{}
3117 t.RegisterProtocol("file", http.NewFileTransport(http.Dir("/")))
3118 c := &http.Client{Transport: t}
3119 res, err := c.Get("file:///etc/passwd")
3131 <h2 id="ServeMux">type <a href="https://golang.org/src/net/http/server.go?s=46684:46809#L1569">ServeMux</a></h2>
3132 <pre>type ServeMux struct {
3133 <span class="comment">// contains filtered or unexported fields</span>
3136 ServeMux is an HTTP request multiplexer.
3137 It matches the URL of each incoming request against a list of registered
3138 patterns and calls the handler for the pattern that
3139 most closely matches the URL.
3142 Patterns name fixed, rooted paths, like "/favicon.ico",
3143 or rooted subtrees, like "/images/" (note the trailing slash).
3144 Longer patterns take precedence over shorter ones, so that
3145 if there are handlers registered for both "/images/"
3146 and "/images/thumbnails/", the latter handler will be
3147 called for paths beginning "/images/thumbnails/" and the
3148 former will receive requests for any other paths in the
3152 Note that since a pattern ending in a slash names a rooted subtree,
3153 the pattern "/" matches all paths not matched by other registered
3154 patterns, not just the URL with Path == "/".
3157 Patterns may optionally begin with a host name, restricting matches to
3158 URLs on that host only. Host-specific patterns take precedence over
3159 general patterns, so that a handler might register for the two patterns
3160 "/codesearch" and "codesearch.google.com/" without also taking over
3161 requests for "<a href="http://www.google.com/">http://www.google.com/</a>".
3164 ServeMux also takes care of sanitizing the URL request path,
3165 redirecting any request containing . or .. elements to an
3166 equivalent .- and ..-free URL.
3180 <h3 id="NewServeMux">func <a href="https://golang.org/src/net/http/server.go?s=46940:46968#L1582">NewServeMux</a></h3>
3181 <pre>func NewServeMux() *<a href="https://golang.org/pkg/net/http/#ServeMux">ServeMux</a></pre>
3183 NewServeMux allocates and returns a new ServeMux.
3192 <h3 id="ServeMux.Handle">func (*ServeMux) <a href="https://golang.org/src/net/http/server.go?s=49985:50045#L1694">Handle</a></h3>
3193 <pre>func (mux *<a href="https://golang.org/pkg/net/http/#ServeMux">ServeMux</a>) Handle(pattern <a href="https://golang.org/pkg/builtin/#string">string</a>, handler <a href="https://golang.org/pkg/net/http/#Handler">Handler</a>)</pre>
3195 Handle registers the handler for the given pattern.
3196 If a handler already exists for pattern, Handle panics.
3200 <div id="example_ServeMux_Handle" class="toggle">
3201 <div class="collapsed">
3202 <p class="exampleHeading toggleButton">▹ <span class="text">Example</span></p>
3204 <div class="expanded">
3205 <p class="exampleHeading toggleButton">▾ <span class="text">Example</span></p>
3210 <pre class="code"> mux := http.NewServeMux()
3211 mux.Handle("/api/", apiHandler{})
3212 mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
3213 <span class="comment">// The "/" pattern matches everything, so we need to check</span>
3214 <span class="comment">// that we're at the root here.</span>
3215 if req.URL.Path != "/" {
3216 http.NotFound(w, req)
3219 fmt.Fprintf(w, "Welcome to the home page!")
3230 <h3 id="ServeMux.HandleFunc">func (*ServeMux) <a href="https://golang.org/src/net/http/server.go?s=51148:51235#L1733">HandleFunc</a></h3>
3231 <pre>func (mux *<a href="https://golang.org/pkg/net/http/#ServeMux">ServeMux</a>) HandleFunc(pattern <a href="https://golang.org/pkg/builtin/#string">string</a>, handler func(<a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, *<a href="https://golang.org/pkg/net/http/#Request">Request</a>))</pre>
3233 HandleFunc registers the handler function for the given pattern.
3241 <h3 id="ServeMux.Handler">func (*ServeMux) <a href="https://golang.org/src/net/http/server.go?s=48689:48757#L1646">Handler</a></h3>
3242 <pre>func (mux *<a href="https://golang.org/pkg/net/http/#ServeMux">ServeMux</a>) Handler(r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) (h <a href="https://golang.org/pkg/net/http/#Handler">Handler</a>, pattern <a href="https://golang.org/pkg/builtin/#string">string</a>)</pre>
3244 Handler returns the handler to use for the given request,
3245 consulting r.Method, r.Host, and r.URL.Path. It always returns
3246 a non-nil handler. If the path is not in its canonical form, the
3247 handler will be an internally-generated handler that redirects
3248 to the canonical path.
3251 Handler also returns the registered pattern that matches the
3252 request or, in the case of internally-generated redirects,
3253 the pattern that will match after following the redirect.
3256 If there is no registered handler that applies to the request,
3257 Handler returns a “page not found” handler and an empty pattern.
3265 <h3 id="ServeMux.ServeHTTP">func (*ServeMux) <a href="https://golang.org/src/net/http/server.go?s=49617:49677#L1680">ServeHTTP</a></h3>
3266 <pre>func (mux *<a href="https://golang.org/pkg/net/http/#ServeMux">ServeMux</a>) ServeHTTP(w <a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, r *<a href="https://golang.org/pkg/net/http/#Request">Request</a>)</pre>
3268 ServeHTTP dispatches the request to the handler whose
3269 pattern most closely matches the request URL.
3279 <h2 id="Server">type <a href="https://golang.org/src/net/http/server.go?s=52296:53789#L1760">Server</a></h2>
3280 <pre>type Server struct {
3281 Addr <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// TCP address to listen on, ":http" if empty</span>
3282 Handler <a href="https://golang.org/pkg/net/http/#Handler">Handler</a> <span class="comment">// handler to invoke, http.DefaultServeMux if nil</span>
3283 ReadTimeout <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Duration">Duration</a> <span class="comment">// maximum duration before timing out read of the request</span>
3284 WriteTimeout <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Duration">Duration</a> <span class="comment">// maximum duration before timing out write of the response</span>
3285 MaxHeaderBytes <a href="https://golang.org/pkg/builtin/#int">int</a> <span class="comment">// maximum size of request headers, DefaultMaxHeaderBytes if 0</span>
3286 TLSConfig *<a href="https://golang.org/pkg/crypto/tls/">tls</a>.<a href="https://golang.org/pkg/crypto/tls/#Config">Config</a> <span class="comment">// optional TLS config, used by ListenAndServeTLS</span>
3288 <span class="comment">// TLSNextProto optionally specifies a function to take over</span>
3289 <span class="comment">// ownership of the provided TLS connection when an NPN</span>
3290 <span class="comment">// protocol upgrade has occurred. The map key is the protocol</span>
3291 <span class="comment">// name negotiated. The Handler argument should be used to</span>
3292 <span class="comment">// handle HTTP requests and will initialize the Request's TLS</span>
3293 <span class="comment">// and RemoteAddr if not already set. The connection is</span>
3294 <span class="comment">// automatically closed when the function returns.</span>
3295 TLSNextProto map[<a href="https://golang.org/pkg/builtin/#string">string</a>]func(*<a href="https://golang.org/pkg/net/http/#Server">Server</a>, *<a href="https://golang.org/pkg/crypto/tls/">tls</a>.<a href="https://golang.org/pkg/crypto/tls/#Conn">Conn</a>, <a href="https://golang.org/pkg/net/http/#Handler">Handler</a>)
3297 <span class="comment">// ConnState specifies an optional callback function that is</span>
3298 <span class="comment">// called when a client connection changes state. See the</span>
3299 <span class="comment">// ConnState type and associated constants for details.</span>
3300 ConnState func(<a href="https://golang.org/pkg/net/">net</a>.<a href="https://golang.org/pkg/net/#Conn">Conn</a>, <a href="https://golang.org/pkg/net/http/#ConnState">ConnState</a>)
3302 <span class="comment">// ErrorLog specifies an optional logger for errors accepting</span>
3303 <span class="comment">// connections and unexpected behavior from handlers.</span>
3304 <span class="comment">// If nil, logging goes to os.Stderr via the log package's</span>
3305 <span class="comment">// standard logger.</span>
3306 ErrorLog *<a href="https://golang.org/pkg/log/">log</a>.<a href="https://golang.org/pkg/log/#Logger">Logger</a>
3307 <span class="comment">// contains filtered or unexported fields</span>
3310 A Server defines parameters for running an HTTP server.
3311 The zero value for Server is a valid configuration.
3327 <h3 id="Server.ListenAndServe">func (*Server) <a href="https://golang.org/src/net/http/server.go?s=55886:55927#L1858">ListenAndServe</a></h3>
3328 <pre>func (srv *<a href="https://golang.org/pkg/net/http/#Server">Server</a>) ListenAndServe() <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
3330 ListenAndServe listens on the TCP network address srv.Addr and then
3331 calls Serve to handle requests on incoming connections. If
3332 srv.Addr is blank, ":http" is used.
3340 <h3 id="Server.ListenAndServeTLS">func (*Server) <a href="https://golang.org/src/net/http/server.go?s=60146:60214#L2003">ListenAndServeTLS</a></h3>
3341 <pre>func (srv *<a href="https://golang.org/pkg/net/http/#Server">Server</a>) ListenAndServeTLS(certFile, keyFile <a href="https://golang.org/pkg/builtin/#string">string</a>) <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
3343 ListenAndServeTLS listens on the TCP network address srv.Addr and
3344 then calls Serve to handle requests on incoming TLS connections.
3347 Filenames containing a certificate and matching private key for the
3348 server must be provided if the Server's TLSConfig.Certificates is
3349 not populated. If the certificate is signed by a certificate
3350 authority, the certFile should be the concatenation of the server's
3351 certificate, any intermediates, and the CA's certificate.
3354 If srv.Addr is blank, ":https" is used.
3362 <h3 id="Server.Serve">func (*Server) <a href="https://golang.org/src/net/http/server.go?s=56308:56354#L1873">Serve</a></h3>
3363 <pre>func (srv *<a href="https://golang.org/pkg/net/http/#Server">Server</a>) Serve(l <a href="https://golang.org/pkg/net/">net</a>.<a href="https://golang.org/pkg/net/#Listener">Listener</a>) <a href="https://golang.org/pkg/builtin/#error">error</a></pre>
3365 Serve accepts incoming connections on the Listener l, creating a
3366 new service goroutine for each. The service goroutines read requests and
3367 then call srv.Handler to reply to them.
3375 <h3 id="Server.SetKeepAlivesEnabled">func (*Server) <a href="https://golang.org/src/net/http/server.go?s=57329:57376#L1912">SetKeepAlivesEnabled</a></h3>
3376 <pre>func (srv *<a href="https://golang.org/pkg/net/http/#Server">Server</a>) SetKeepAlivesEnabled(v <a href="https://golang.org/pkg/builtin/#bool">bool</a>)</pre>
3378 SetKeepAlivesEnabled controls whether HTTP keep-alives are enabled.
3379 By default, keep-alives are always enabled. Only very
3380 resource-constrained environments or servers in the process of
3381 shutting down should disable them.
3391 <h2 id="Transport">type <a href="https://golang.org/src/net/http/transport.go?s=1324:4038#L39">Transport</a></h2>
3392 <pre>type Transport struct {
3394 <span class="comment">// Proxy specifies a function to return a proxy for a given</span>
3395 <span class="comment">// Request. If the function returns a non-nil error, the</span>
3396 <span class="comment">// request is aborted with the provided error.</span>
3397 <span class="comment">// If Proxy is nil or returns a nil *URL, no proxy is used.</span>
3398 Proxy func(*<a href="https://golang.org/pkg/net/http/#Request">Request</a>) (*<a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#URL">URL</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)
3400 <span class="comment">// Dial specifies the dial function for creating unencrypted</span>
3401 <span class="comment">// TCP connections.</span>
3402 <span class="comment">// If Dial is nil, net.Dial is used.</span>
3403 Dial func(network, addr <a href="https://golang.org/pkg/builtin/#string">string</a>) (<a href="https://golang.org/pkg/net/">net</a>.<a href="https://golang.org/pkg/net/#Conn">Conn</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)
3405 <span class="comment">// DialTLS specifies an optional dial function for creating</span>
3406 <span class="comment">// TLS connections for non-proxied HTTPS requests.</span>
3407 <span class="comment">//</span>
3408 <span class="comment">// If DialTLS is nil, Dial and TLSClientConfig are used.</span>
3409 <span class="comment">//</span>
3410 <span class="comment">// If DialTLS is set, the Dial hook is not used for HTTPS</span>
3411 <span class="comment">// requests and the TLSClientConfig and TLSHandshakeTimeout</span>
3412 <span class="comment">// are ignored. The returned net.Conn is assumed to already be</span>
3413 <span class="comment">// past the TLS handshake.</span>
3414 DialTLS func(network, addr <a href="https://golang.org/pkg/builtin/#string">string</a>) (<a href="https://golang.org/pkg/net/">net</a>.<a href="https://golang.org/pkg/net/#Conn">Conn</a>, <a href="https://golang.org/pkg/builtin/#error">error</a>)
3416 <span class="comment">// TLSClientConfig specifies the TLS configuration to use with</span>
3417 <span class="comment">// tls.Client. If nil, the default configuration is used.</span>
3418 TLSClientConfig *<a href="https://golang.org/pkg/crypto/tls/">tls</a>.<a href="https://golang.org/pkg/crypto/tls/#Config">Config</a>
3420 <span class="comment">// TLSHandshakeTimeout specifies the maximum amount of time waiting to</span>
3421 <span class="comment">// wait for a TLS handshake. Zero means no timeout.</span>
3422 TLSHandshakeTimeout <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Duration">Duration</a>
3424 <span class="comment">// DisableKeepAlives, if true, prevents re-use of TCP connections</span>
3425 <span class="comment">// between different HTTP requests.</span>
3426 DisableKeepAlives <a href="https://golang.org/pkg/builtin/#bool">bool</a>
3428 <span class="comment">// DisableCompression, if true, prevents the Transport from</span>
3429 <span class="comment">// requesting compression with an "Accept-Encoding: gzip"</span>
3430 <span class="comment">// request header when the Request contains no existing</span>
3431 <span class="comment">// Accept-Encoding value. If the Transport requests gzip on</span>
3432 <span class="comment">// its own and gets a gzipped response, it's transparently</span>
3433 <span class="comment">// decoded in the Response.Body. However, if the user</span>
3434 <span class="comment">// explicitly requested gzip it is not automatically</span>
3435 <span class="comment">// uncompressed.</span>
3436 DisableCompression <a href="https://golang.org/pkg/builtin/#bool">bool</a>
3438 <span class="comment">// MaxIdleConnsPerHost, if non-zero, controls the maximum idle</span>
3439 <span class="comment">// (keep-alive) to keep per-host. If zero,</span>
3440 <span class="comment">// DefaultMaxIdleConnsPerHost is used.</span>
3441 MaxIdleConnsPerHost <a href="https://golang.org/pkg/builtin/#int">int</a>
3443 <span class="comment">// ResponseHeaderTimeout, if non-zero, specifies the amount of</span>
3444 <span class="comment">// time to wait for a server's response headers after fully</span>
3445 <span class="comment">// writing the request (including its body, if any). This</span>
3446 <span class="comment">// time does not include the time to read the response body.</span>
3447 ResponseHeaderTimeout <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Duration">Duration</a>
3448 <span class="comment">// contains filtered or unexported fields</span>
3451 Transport is an implementation of RoundTripper that supports HTTP,
3452 HTTPS, and HTTP proxies (for either HTTP or HTTPS with CONNECT).
3453 Transport can also cache connections for future re-use.
3469 <h3 id="Transport.CancelRequest">func (*Transport) <a href="https://golang.org/src/net/http/transport.go?s=8881:8928#L269">CancelRequest</a></h3>
3470 <pre>func (t *<a href="https://golang.org/pkg/net/http/#Transport">Transport</a>) CancelRequest(req *<a href="https://golang.org/pkg/net/http/#Request">Request</a>)</pre>
3472 CancelRequest cancels an in-flight request by closing its connection.
3473 CancelRequest should only be called after RoundTrip has returned.
3481 <h3 id="Transport.CloseIdleConnections">func (*Transport) <a href="https://golang.org/src/net/http/transport.go?s=8498:8540#L253">CloseIdleConnections</a></h3>
3482 <pre>func (t *<a href="https://golang.org/pkg/net/http/#Transport">Transport</a>) CloseIdleConnections()</pre>
3484 CloseIdleConnections closes any connections which were previously
3485 connected from previous requests but are now sitting idle in
3486 a "keep-alive" state. It does not interrupt any connections currently
3495 <h3 id="Transport.RegisterProtocol">func (*Transport) <a href="https://golang.org/src/net/http/transport.go?s=7866:7934#L234">RegisterProtocol</a></h3>
3496 <pre>func (t *<a href="https://golang.org/pkg/net/http/#Transport">Transport</a>) RegisterProtocol(scheme <a href="https://golang.org/pkg/builtin/#string">string</a>, rt <a href="https://golang.org/pkg/net/http/#RoundTripper">RoundTripper</a>)</pre>
3498 RegisterProtocol registers a new protocol with scheme.
3499 The Transport will pass requests using the given scheme to rt.
3500 It is rt's responsibility to simulate HTTP request semantics.
3503 RegisterProtocol can be used by other packages to provide
3504 implementations of protocol schemes like "ftp" or "file".
3512 <h3 id="Transport.RoundTrip">func (*Transport) <a href="https://golang.org/src/net/http/transport.go?s=6344:6415#L181">RoundTrip</a></h3>
3513 <pre>func (t *<a href="https://golang.org/pkg/net/http/#Transport">Transport</a>) RoundTrip(req *<a href="https://golang.org/pkg/net/http/#Request">Request</a>) (resp *<a href="https://golang.org/pkg/net/http/#Response">Response</a>, err <a href="https://golang.org/pkg/builtin/#error">error</a>)</pre>
3515 RoundTrip implements the RoundTripper interface.
3518 For higher-level HTTP client support (such as handling of cookies
3519 and redirects), see Get, Post, and the Client type.
3537 <h2 id="pkg-subdirectories">Subdirectories</h2>
3542 <div class="pkg-dir">
3545 <th class="pkg-name">Name</th>
3546 <th class="pkg-synopsis">Synopsis</th>
3551 <td colspan="2"><a href="https://golang.org/pkg/net/">..</a></td>
3558 <td class="pkg-name" style="padding-left: 0px;">
3559 <a href="https://golang.org/pkg/net/http/cgi/">cgi</a>
3561 <td class="pkg-synopsis">
3562 Package cgi implements CGI (Common Gateway Interface) as specified in RFC 3875.
3569 <td class="pkg-name" style="padding-left: 0px;">
3570 <a href="https://golang.org/pkg/net/http/cookiejar/">cookiejar</a>
3572 <td class="pkg-synopsis">
3573 Package cookiejar implements an in-memory RFC 6265-compliant http.CookieJar.
3580 <td class="pkg-name" style="padding-left: 0px;">
3581 <a href="https://golang.org/pkg/net/http/fcgi/">fcgi</a>
3583 <td class="pkg-synopsis">
3584 Package fcgi implements the FastCGI protocol.
3591 <td class="pkg-name" style="padding-left: 0px;">
3592 <a href="https://golang.org/pkg/net/http/httptest/">httptest</a>
3594 <td class="pkg-synopsis">
3595 Package httptest provides utilities for HTTP testing.
3602 <td class="pkg-name" style="padding-left: 0px;">
3603 <a href="https://golang.org/pkg/net/http/httputil/">httputil</a>
3605 <td class="pkg-synopsis">
3606 Package httputil provides HTTP utility functions, complementing the more common ones in the net/http package.
3613 <td class="pkg-name" style="padding-left: 0px;">
3614 <a href="https://golang.org/pkg/net/http/pprof/">pprof</a>
3616 <td class="pkg-synopsis">
3617 Package pprof serves via its HTTP server runtime profiling data in the format expected by the pprof visualization tool.
3631 Build version go1.5.1.<br>
3632 Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
3633 the content of this page is licensed under the
3634 Creative Commons Attribution 3.0 License,
3635 and code is licensed under a <a href="https://golang.org/LICENSE">BSD license</a>.<br>
3636 <a href="https://golang.org/doc/tos.html">Terms of Service</a> |
3637 <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
3640 </div><!-- .container -->
3641 </div><!-- #page -->
3643 <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
3644 <script type="text/javascript" src="./http - The Go Programming Language_files/jquery.min.js"></script>
3645 <script type="text/javascript" src="./http - The Go Programming Language_files/jquery.treeview.js"></script>
3646 <script type="text/javascript" src="./http - The Go Programming Language_files/jquery.treeview.edit.js"></script>
3649 <script type="text/javascript" src="./http - The Go Programming Language_files/playground.js"></script>
3651 <script type="text/javascript" src="./http - The Go Programming Language_files/godocs.js"></script>
3653 <script type="text/javascript">
3655 var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;
3656 ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
3657 var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);