The Go Programming Language.html 147 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663
  1. <!DOCTYPE html>
  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">
  4. <meta name="viewport" content="width=device-width, initial-scale=1">
  5. <meta name="theme-color" content="#375EAB">
  6. <title>http - The Go Programming Language</title>
  7. <link type="text/css" rel="stylesheet" href="./http - The Go Programming Language_files/style.css">
  8. <link rel="search" type="application/opensearchdescription+xml" title="godoc" href="https://golang.org/opensearch.xml">
  9. <link rel="stylesheet" href="./http - The Go Programming Language_files/jquery.treeview.css">
  10. <script type="text/javascript" async="" src="./http - The Go Programming Language_files/ga.js"></script><script type="text/javascript">window.initFuncs = [];</script>
  11. <script type="text/javascript">
  12. var _gaq = _gaq || [];
  13. _gaq.push(["_setAccount", "UA-11222381-2"]);
  14. _gaq.push(["b._setAccount", "UA-49880327-6"]);
  15. window.trackPageview = function() {
  16. _gaq.push(["_trackPageview", location.pathname+location.hash]);
  17. _gaq.push(["b._trackPageview", location.pathname+location.hash]);
  18. };
  19. window.trackPageview();
  20. window.trackEvent = function(category, action, opt_label, opt_value, opt_noninteraction) {
  21. _gaq.push(["_trackEvent", category, action, opt_label, opt_value, opt_noninteraction]);
  22. _gaq.push(["b._trackEvent", category, action, opt_label, opt_value, opt_noninteraction]);
  23. };
  24. </script>
  25. </head>
  26. <body>
  27. <div id="lowframe" style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  28. ...
  29. </div><!-- #lowframe -->
  30. <div id="topbar" class="wide"><div class="container">
  31. <div class="top-heading" id="heading-wide"><a href="https://golang.org/">The Go Programming Language</a></div>
  32. <div class="top-heading" id="heading-narrow"><a href="https://golang.org/">Go</a></div>
  33. <a href="https://golang.org/pkg/net/http/#" id="menu-button"><span id="menu-button-arrow">▽</span></a>
  34. <form method="GET" action="https://golang.org/search">
  35. <div id="menu" style="min-width: 60px;">
  36. <a href="https://golang.org/doc/">Documents</a>
  37. <a href="https://golang.org/pkg/">Packages</a>
  38. <a href="https://golang.org/project/">The Project</a>
  39. <a href="https://golang.org/help/">Help</a>
  40. <a href="https://golang.org/blog/">Blog</a>
  41. <a id="playgroundButton" href="http://play.golang.org/" title="Show Go Playground" style="display: inline;">Play</a>
  42. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  43. </div>
  44. </form>
  45. </div></div>
  46. <div id="playground" class="play">
  47. <div class="input"><textarea class="code">package main
  48. import "fmt"
  49. func main() {
  50. fmt.Println("Hello, 世界")
  51. }</textarea></div>
  52. <div class="output"></div>
  53. <div class="buttons">
  54. <a class="run" title="Run this code [shift-enter]">Run</a>
  55. <a class="fmt" title="Format this code">Format</a>
  56. </div>
  57. </div>
  58. <div id="page" class="wide" tabindex="-1" style="outline: 0px;">
  59. <div class="container">
  60. <h1>Package http</h1>
  61. <div id="nav"></div>
  62. <!--
  63. Copyright 2009 The Go Authors. All rights reserved.
  64. Use of this source code is governed by a BSD-style
  65. license that can be found in the LICENSE file.
  66. -->
  67. <!--
  68. Note: Static (i.e., not template-generated) href and id
  69. attributes start with "pkg-" to make it impossible for
  70. them to conflict with generated attributes (some of which
  71. correspond to Go identifiers).
  72. -->
  73. <script type="text/javascript">
  74. document.ANALYSIS_DATA = null;
  75. document.CALLGRAPH = null;
  76. </script>
  77. <div id="short-nav">
  78. <dl>
  79. <dd><code>import "net/http"</code></dd>
  80. </dl>
  81. <dl>
  82. <dd><a href="https://golang.org/pkg/net/http/#pkg-overview" class="overviewLink">Overview</a></dd>
  83. <dd><a href="https://golang.org/pkg/net/http/#pkg-index" class="indexLink">Index</a></dd>
  84. <dd><a href="https://golang.org/pkg/net/http/#pkg-examples" class="examplesLink">Examples</a></dd>
  85. <dd><a href="https://golang.org/pkg/net/http/#pkg-subdirectories">Subdirectories</a></dd>
  86. </dl>
  87. </div>
  88. <!-- The package's Name is printed as title by the top-level template -->
  89. <div id="pkg-overview" class="toggleVisible">
  90. <div class="collapsed">
  91. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  92. </div>
  93. <div class="expanded">
  94. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  95. <p>
  96. Package http provides HTTP client and server implementations.
  97. </p>
  98. <p>
  99. Get, Head, Post, and PostForm make HTTP (or HTTPS) requests:
  100. </p>
  101. <pre>resp, err := http.Get("<a href="http://example.com/">http://example.com/</a>")
  102. ...
  103. resp, err := http.Post("<a href="http://example.com/upload">http://example.com/upload</a>", "image/jpeg", &amp;buf)
  104. ...
  105. resp, err := http.PostForm("<a href="http://example.com/form">http://example.com/form</a>",
  106. url.Values{"key": {"Value"}, "id": {"123"}})
  107. </pre>
  108. <p>
  109. The client must close the response body when finished with it:
  110. </p>
  111. <pre>resp, err := http.Get("<a href="http://example.com/">http://example.com/</a>")
  112. if err != nil {
  113. // handle error
  114. }
  115. defer resp.Body.Close()
  116. body, err := ioutil.ReadAll(resp.Body)
  117. // ...
  118. </pre>
  119. <p>
  120. For control over HTTP client headers, redirect policy, and other
  121. settings, create a Client:
  122. </p>
  123. <pre>client := &amp;http.Client{
  124. CheckRedirect: redirectPolicyFunc,
  125. }
  126. resp, err := client.Get("<a href="http://example.com/">http://example.com</a>")
  127. // ...
  128. req, err := http.NewRequest("GET", "<a href="http://example.com/">http://example.com</a>", nil)
  129. // ...
  130. req.Header.Add("If-None-Match", `W/"wyzzy"`)
  131. resp, err := client.Do(req)
  132. // ...
  133. </pre>
  134. <p>
  135. For control over proxies, TLS configuration, keep-alives,
  136. compression, and other settings, create a Transport:
  137. </p>
  138. <pre>tr := &amp;http.Transport{
  139. TLSClientConfig: &amp;tls.Config{RootCAs: pool},
  140. DisableCompression: true,
  141. }
  142. client := &amp;http.Client{Transport: tr}
  143. resp, err := client.Get("<a href="https://example.com/">https://example.com</a>")
  144. </pre>
  145. <p>
  146. Clients and Transports are safe for concurrent use by multiple
  147. goroutines and for efficiency should only be created once and re-used.
  148. </p>
  149. <p>
  150. ListenAndServe starts an HTTP server with a given address and handler.
  151. The handler is usually nil, which means to use DefaultServeMux.
  152. Handle and HandleFunc add handlers to DefaultServeMux:
  153. </p>
  154. <pre>http.Handle("/foo", fooHandler)
  155. http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) {
  156. fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
  157. })
  158. log.Fatal(http.ListenAndServe(":8080", nil))
  159. </pre>
  160. <p>
  161. More control over the server's behavior is available by creating a
  162. custom Server:
  163. </p>
  164. <pre>s := &amp;http.Server{
  165. Addr: ":8080",
  166. Handler: myHandler,
  167. ReadTimeout: 10 * time.Second,
  168. WriteTimeout: 10 * time.Second,
  169. MaxHeaderBytes: 1 &lt;&lt; 20,
  170. }
  171. log.Fatal(s.ListenAndServe())
  172. </pre>
  173. </div>
  174. </div>
  175. <div id="pkg-index" class="toggleVisible">
  176. <div class="collapsed">
  177. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  178. </div>
  179. <div class="expanded">
  180. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  181. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  182. <div id="manual-nav">
  183. <dl>
  184. <dd><a href="https://golang.org/pkg/net/http/#pkg-constants">Constants</a></dd>
  185. <dd><a href="https://golang.org/pkg/net/http/#pkg-variables">Variables</a></dd>
  186. <dd><a href="https://golang.org/pkg/net/http/#CanonicalHeaderKey">func CanonicalHeaderKey(s string) string</a></dd>
  187. <dd><a href="https://golang.org/pkg/net/http/#DetectContentType">func DetectContentType(data []byte) string</a></dd>
  188. <dd><a href="https://golang.org/pkg/net/http/#Error">func Error(w ResponseWriter, error string, code int)</a></dd>
  189. <dd><a href="https://golang.org/pkg/net/http/#Handle">func Handle(pattern string, handler Handler)</a></dd>
  190. <dd><a href="https://golang.org/pkg/net/http/#HandleFunc">func HandleFunc(pattern string, handler func(ResponseWriter, *Request))</a></dd>
  191. <dd><a href="https://golang.org/pkg/net/http/#ListenAndServe">func ListenAndServe(addr string, handler Handler) error</a></dd>
  192. <dd><a href="https://golang.org/pkg/net/http/#ListenAndServeTLS">func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler) error</a></dd>
  193. <dd><a href="https://golang.org/pkg/net/http/#MaxBytesReader">func MaxBytesReader(w ResponseWriter, r io.ReadCloser, n int64) io.ReadCloser</a></dd>
  194. <dd><a href="https://golang.org/pkg/net/http/#NotFound">func NotFound(w ResponseWriter, r *Request)</a></dd>
  195. <dd><a href="https://golang.org/pkg/net/http/#ParseHTTPVersion">func ParseHTTPVersion(vers string) (major, minor int, ok bool)</a></dd>
  196. <dd><a href="https://golang.org/pkg/net/http/#ParseTime">func ParseTime(text string) (t time.Time, err error)</a></dd>
  197. <dd><a href="https://golang.org/pkg/net/http/#ProxyFromEnvironment">func ProxyFromEnvironment(req *Request) (*url.URL, error)</a></dd>
  198. <dd><a href="https://golang.org/pkg/net/http/#ProxyURL">func ProxyURL(fixedURL *url.URL) func(*Request) (*url.URL, error)</a></dd>
  199. <dd><a href="https://golang.org/pkg/net/http/#Redirect">func Redirect(w ResponseWriter, r *Request, urlStr string, code int)</a></dd>
  200. <dd><a href="https://golang.org/pkg/net/http/#Serve">func Serve(l net.Listener, handler Handler) error</a></dd>
  201. <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>
  202. <dd><a href="https://golang.org/pkg/net/http/#ServeFile">func ServeFile(w ResponseWriter, r *Request, name string)</a></dd>
  203. <dd><a href="https://golang.org/pkg/net/http/#SetCookie">func SetCookie(w ResponseWriter, cookie *Cookie)</a></dd>
  204. <dd><a href="https://golang.org/pkg/net/http/#StatusText">func StatusText(code int) string</a></dd>
  205. <dd><a href="https://golang.org/pkg/net/http/#Client">type Client</a></dd>
  206. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Client.Do">func (c *Client) Do(req *Request) (resp *Response, err error)</a></dd>
  207. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Client.Get">func (c *Client) Get(url string) (resp *Response, err error)</a></dd>
  208. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Client.Head">func (c *Client) Head(url string) (resp *Response, err error)</a></dd>
  209. <dd>&nbsp; &nbsp; <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>
  210. <dd>&nbsp; &nbsp; <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>
  211. <dd><a href="https://golang.org/pkg/net/http/#CloseNotifier">type CloseNotifier</a></dd>
  212. <dd><a href="https://golang.org/pkg/net/http/#ConnState">type ConnState</a></dd>
  213. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#ConnState.String">func (c ConnState) String() string</a></dd>
  214. <dd><a href="https://golang.org/pkg/net/http/#Cookie">type Cookie</a></dd>
  215. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Cookie.String">func (c *Cookie) String() string</a></dd>
  216. <dd><a href="https://golang.org/pkg/net/http/#CookieJar">type CookieJar</a></dd>
  217. <dd><a href="https://golang.org/pkg/net/http/#Dir">type Dir</a></dd>
  218. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Dir.Open">func (d Dir) Open(name string) (File, error)</a></dd>
  219. <dd><a href="https://golang.org/pkg/net/http/#File">type File</a></dd>
  220. <dd><a href="https://golang.org/pkg/net/http/#FileSystem">type FileSystem</a></dd>
  221. <dd><a href="https://golang.org/pkg/net/http/#Flusher">type Flusher</a></dd>
  222. <dd><a href="https://golang.org/pkg/net/http/#Handler">type Handler</a></dd>
  223. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#FileServer">func FileServer(root FileSystem) Handler</a></dd>
  224. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#NotFoundHandler">func NotFoundHandler() Handler</a></dd>
  225. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#RedirectHandler">func RedirectHandler(url string, code int) Handler</a></dd>
  226. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#StripPrefix">func StripPrefix(prefix string, h Handler) Handler</a></dd>
  227. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#TimeoutHandler">func TimeoutHandler(h Handler, dt time.Duration, msg string) Handler</a></dd>
  228. <dd><a href="https://golang.org/pkg/net/http/#HandlerFunc">type HandlerFunc</a></dd>
  229. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#HandlerFunc.ServeHTTP">func (f HandlerFunc) ServeHTTP(w ResponseWriter, r *Request)</a></dd>
  230. <dd><a href="https://golang.org/pkg/net/http/#Header">type Header</a></dd>
  231. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Header.Add">func (h Header) Add(key, value string)</a></dd>
  232. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Header.Del">func (h Header) Del(key string)</a></dd>
  233. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Header.Get">func (h Header) Get(key string) string</a></dd>
  234. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Header.Set">func (h Header) Set(key, value string)</a></dd>
  235. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Header.Write">func (h Header) Write(w io.Writer) error</a></dd>
  236. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Header.WriteSubset">func (h Header) WriteSubset(w io.Writer, exclude map[string]bool) error</a></dd>
  237. <dd><a href="https://golang.org/pkg/net/http/#Hijacker">type Hijacker</a></dd>
  238. <dd><a href="https://golang.org/pkg/net/http/#ProtocolError">type ProtocolError</a></dd>
  239. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#ProtocolError.Error">func (err *ProtocolError) Error() string</a></dd>
  240. <dd><a href="https://golang.org/pkg/net/http/#Request">type Request</a></dd>
  241. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#NewRequest">func NewRequest(method, urlStr string, body io.Reader) (*Request, error)</a></dd>
  242. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#ReadRequest">func ReadRequest(b *bufio.Reader) (req *Request, err error)</a></dd>
  243. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.AddCookie">func (r *Request) AddCookie(c *Cookie)</a></dd>
  244. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.BasicAuth">func (r *Request) BasicAuth() (username, password string, ok bool)</a></dd>
  245. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.Cookie">func (r *Request) Cookie(name string) (*Cookie, error)</a></dd>
  246. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.Cookies">func (r *Request) Cookies() []*Cookie</a></dd>
  247. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.FormFile">func (r *Request) FormFile(key string) (multipart.File, *multipart.FileHeader, error)</a></dd>
  248. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.FormValue">func (r *Request) FormValue(key string) string</a></dd>
  249. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.MultipartReader">func (r *Request) MultipartReader() (*multipart.Reader, error)</a></dd>
  250. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.ParseForm">func (r *Request) ParseForm() error</a></dd>
  251. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.ParseMultipartForm">func (r *Request) ParseMultipartForm(maxMemory int64) error</a></dd>
  252. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.PostFormValue">func (r *Request) PostFormValue(key string) string</a></dd>
  253. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.ProtoAtLeast">func (r *Request) ProtoAtLeast(major, minor int) bool</a></dd>
  254. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.Referer">func (r *Request) Referer() string</a></dd>
  255. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.SetBasicAuth">func (r *Request) SetBasicAuth(username, password string)</a></dd>
  256. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.UserAgent">func (r *Request) UserAgent() string</a></dd>
  257. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.Write">func (r *Request) Write(w io.Writer) error</a></dd>
  258. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Request.WriteProxy">func (r *Request) WriteProxy(w io.Writer) error</a></dd>
  259. <dd><a href="https://golang.org/pkg/net/http/#Response">type Response</a></dd>
  260. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Get">func Get(url string) (resp *Response, err error)</a></dd>
  261. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Head">func Head(url string) (resp *Response, err error)</a></dd>
  262. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Post">func Post(url string, bodyType string, body io.Reader) (resp *Response, err error)</a></dd>
  263. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#PostForm">func PostForm(url string, data url.Values) (resp *Response, err error)</a></dd>
  264. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#ReadResponse">func ReadResponse(r *bufio.Reader, req *Request) (*Response, error)</a></dd>
  265. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Response.Cookies">func (r *Response) Cookies() []*Cookie</a></dd>
  266. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Response.Location">func (r *Response) Location() (*url.URL, error)</a></dd>
  267. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Response.ProtoAtLeast">func (r *Response) ProtoAtLeast(major, minor int) bool</a></dd>
  268. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Response.Write">func (r *Response) Write(w io.Writer) error</a></dd>
  269. <dd><a href="https://golang.org/pkg/net/http/#ResponseWriter">type ResponseWriter</a></dd>
  270. <dd><a href="https://golang.org/pkg/net/http/#RoundTripper">type RoundTripper</a></dd>
  271. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#NewFileTransport">func NewFileTransport(fs FileSystem) RoundTripper</a></dd>
  272. <dd><a href="https://golang.org/pkg/net/http/#ServeMux">type ServeMux</a></dd>
  273. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#NewServeMux">func NewServeMux() *ServeMux</a></dd>
  274. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#ServeMux.Handle">func (mux *ServeMux) Handle(pattern string, handler Handler)</a></dd>
  275. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#ServeMux.HandleFunc">func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Request))</a></dd>
  276. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#ServeMux.Handler">func (mux *ServeMux) Handler(r *Request) (h Handler, pattern string)</a></dd>
  277. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#ServeMux.ServeHTTP">func (mux *ServeMux) ServeHTTP(w ResponseWriter, r *Request)</a></dd>
  278. <dd><a href="https://golang.org/pkg/net/http/#Server">type Server</a></dd>
  279. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Server.ListenAndServe">func (srv *Server) ListenAndServe() error</a></dd>
  280. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Server.ListenAndServeTLS">func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error</a></dd>
  281. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Server.Serve">func (srv *Server) Serve(l net.Listener) error</a></dd>
  282. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Server.SetKeepAlivesEnabled">func (srv *Server) SetKeepAlivesEnabled(v bool)</a></dd>
  283. <dd><a href="https://golang.org/pkg/net/http/#Transport">type Transport</a></dd>
  284. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Transport.CancelRequest">func (t *Transport) CancelRequest(req *Request)</a></dd>
  285. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Transport.CloseIdleConnections">func (t *Transport) CloseIdleConnections()</a></dd>
  286. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Transport.RegisterProtocol">func (t *Transport) RegisterProtocol(scheme string, rt RoundTripper)</a></dd>
  287. <dd>&nbsp; &nbsp; <a href="https://golang.org/pkg/net/http/#Transport.RoundTrip">func (t *Transport) RoundTrip(req *Request) (resp *Response, err error)</a></dd>
  288. </dl>
  289. </div><!-- #manual-nav -->
  290. <div id="pkg-examples">
  291. <h4>Examples</h4>
  292. <dl>
  293. <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_FileServer">FileServer</a></dd>
  294. <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_FileServer_stripPrefix">FileServer (StripPrefix)</a></dd>
  295. <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_Get">Get</a></dd>
  296. <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_Hijacker">Hijacker</a></dd>
  297. <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_ResponseWriter_trailers">ResponseWriter (Trailers)</a></dd>
  298. <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_ServeMux_Handle">ServeMux.Handle</a></dd>
  299. <dd><a class="exampleLink" href="https://golang.org/pkg/net/http/#example_StripPrefix">StripPrefix</a></dd>
  300. </dl>
  301. </div>
  302. <h4>Package files</h4>
  303. <p>
  304. <span style="font-size:90%">
  305. <a href="https://golang.org/src/net/http/client.go">client.go</a>
  306. <a href="https://golang.org/src/net/http/cookie.go">cookie.go</a>
  307. <a href="https://golang.org/src/net/http/doc.go">doc.go</a>
  308. <a href="https://golang.org/src/net/http/filetransport.go">filetransport.go</a>
  309. <a href="https://golang.org/src/net/http/fs.go">fs.go</a>
  310. <a href="https://golang.org/src/net/http/header.go">header.go</a>
  311. <a href="https://golang.org/src/net/http/jar.go">jar.go</a>
  312. <a href="https://golang.org/src/net/http/lex.go">lex.go</a>
  313. <a href="https://golang.org/src/net/http/request.go">request.go</a>
  314. <a href="https://golang.org/src/net/http/response.go">response.go</a>
  315. <a href="https://golang.org/src/net/http/server.go">server.go</a>
  316. <a href="https://golang.org/src/net/http/sniff.go">sniff.go</a>
  317. <a href="https://golang.org/src/net/http/status.go">status.go</a>
  318. <a href="https://golang.org/src/net/http/transfer.go">transfer.go</a>
  319. <a href="https://golang.org/src/net/http/transport.go">transport.go</a>
  320. </span>
  321. </p>
  322. </div><!-- .expanded -->
  323. </div><!-- #pkg-index -->
  324. <div id="pkg-callgraph" class="toggle" style="display: none">
  325. <div class="collapsed">
  326. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  327. </div> <!-- .expanded -->
  328. <div class="expanded">
  329. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  330. <p>
  331. In the call graph viewer below, each node
  332. is a function belonging to this package
  333. and its children are the functions it
  334. calls—perhaps dynamically.
  335. </p>
  336. <p>
  337. The root nodes are the entry points of the
  338. package: functions that may be called from
  339. outside the package.
  340. There may be non-exported or anonymous
  341. functions among them if they are called
  342. dynamically from another package.
  343. </p>
  344. <p>
  345. Click a node to visit that function's source code.
  346. From there you can visit its callers by
  347. clicking its declaring <code>func</code>
  348. token.
  349. </p>
  350. <p>
  351. Functions may be omitted if they were
  352. determined to be unreachable in the
  353. particular programs or tests that were
  354. analyzed.
  355. </p>
  356. <!-- Zero means show all package entry points. -->
  357. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  358. </div>
  359. </div> <!-- #pkg-callgraph -->
  360. <h2 id="pkg-constants">Constants</h2>
  361. <pre>const (
  362. <span id="StatusContinue">StatusContinue</span> = 100
  363. <span id="StatusSwitchingProtocols">StatusSwitchingProtocols</span> = 101
  364. <span id="StatusOK">StatusOK</span> = 200
  365. <span id="StatusCreated">StatusCreated</span> = 201
  366. <span id="StatusAccepted">StatusAccepted</span> = 202
  367. <span id="StatusNonAuthoritativeInfo">StatusNonAuthoritativeInfo</span> = 203
  368. <span id="StatusNoContent">StatusNoContent</span> = 204
  369. <span id="StatusResetContent">StatusResetContent</span> = 205
  370. <span id="StatusPartialContent">StatusPartialContent</span> = 206
  371. <span id="StatusMultipleChoices">StatusMultipleChoices</span> = 300
  372. <span id="StatusMovedPermanently">StatusMovedPermanently</span> = 301
  373. <span id="StatusFound">StatusFound</span> = 302
  374. <span id="StatusSeeOther">StatusSeeOther</span> = 303
  375. <span id="StatusNotModified">StatusNotModified</span> = 304
  376. <span id="StatusUseProxy">StatusUseProxy</span> = 305
  377. <span id="StatusTemporaryRedirect">StatusTemporaryRedirect</span> = 307
  378. <span id="StatusBadRequest">StatusBadRequest</span> = 400
  379. <span id="StatusUnauthorized">StatusUnauthorized</span> = 401
  380. <span id="StatusPaymentRequired">StatusPaymentRequired</span> = 402
  381. <span id="StatusForbidden">StatusForbidden</span> = 403
  382. <span id="StatusNotFound">StatusNotFound</span> = 404
  383. <span id="StatusMethodNotAllowed">StatusMethodNotAllowed</span> = 405
  384. <span id="StatusNotAcceptable">StatusNotAcceptable</span> = 406
  385. <span id="StatusProxyAuthRequired">StatusProxyAuthRequired</span> = 407
  386. <span id="StatusRequestTimeout">StatusRequestTimeout</span> = 408
  387. <span id="StatusConflict">StatusConflict</span> = 409
  388. <span id="StatusGone">StatusGone</span> = 410
  389. <span id="StatusLengthRequired">StatusLengthRequired</span> = 411
  390. <span id="StatusPreconditionFailed">StatusPreconditionFailed</span> = 412
  391. <span id="StatusRequestEntityTooLarge">StatusRequestEntityTooLarge</span> = 413
  392. <span id="StatusRequestURITooLong">StatusRequestURITooLong</span> = 414
  393. <span id="StatusUnsupportedMediaType">StatusUnsupportedMediaType</span> = 415
  394. <span id="StatusRequestedRangeNotSatisfiable">StatusRequestedRangeNotSatisfiable</span> = 416
  395. <span id="StatusExpectationFailed">StatusExpectationFailed</span> = 417
  396. <span id="StatusTeapot">StatusTeapot</span> = 418
  397. <span id="StatusInternalServerError">StatusInternalServerError</span> = 500
  398. <span id="StatusNotImplemented">StatusNotImplemented</span> = 501
  399. <span id="StatusBadGateway">StatusBadGateway</span> = 502
  400. <span id="StatusServiceUnavailable">StatusServiceUnavailable</span> = 503
  401. <span id="StatusGatewayTimeout">StatusGatewayTimeout</span> = 504
  402. <span id="StatusHTTPVersionNotSupported">StatusHTTPVersionNotSupported</span> = 505
  403. )</pre>
  404. <p>
  405. HTTP status codes, defined in RFC 2616.
  406. </p>
  407. <pre>const <span id="DefaultMaxHeaderBytes">DefaultMaxHeaderBytes</span> = 1 &lt;&lt; 20 <span class="comment">// 1 MB</span>
  408. </pre>
  409. <p>
  410. DefaultMaxHeaderBytes is the maximum permitted size of the headers
  411. in an HTTP request.
  412. This can be overridden by setting Server.MaxHeaderBytes.
  413. </p>
  414. <pre>const <span id="DefaultMaxIdleConnsPerHost">DefaultMaxIdleConnsPerHost</span> = 2</pre>
  415. <p>
  416. DefaultMaxIdleConnsPerHost is the default value of Transport's
  417. MaxIdleConnsPerHost.
  418. </p>
  419. <pre>const <span id="TimeFormat">TimeFormat</span> = "Mon, 02 Jan 2006 15:04:05 GMT"</pre>
  420. <p>
  421. TimeFormat is the time format to use with
  422. time.Parse and time.Time.Format when parsing
  423. or generating times in HTTP headers.
  424. It is like time.RFC1123 but hard codes GMT as the time zone.
  425. </p>
  426. <h2 id="pkg-variables">Variables</h2>
  427. <pre>var (
  428. <span id="ErrHeaderTooLong">ErrHeaderTooLong</span> = &amp;<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"header too long"}
  429. <span id="ErrShortBody">ErrShortBody</span> = &amp;<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"entity body too short"}
  430. <span id="ErrNotSupported">ErrNotSupported</span> = &amp;<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"feature not supported"}
  431. <span id="ErrUnexpectedTrailer">ErrUnexpectedTrailer</span> = &amp;<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"trailer header without chunked transfer encoding"}
  432. <span id="ErrMissingContentLength">ErrMissingContentLength</span> = &amp;<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"missing ContentLength in HEAD response"}
  433. <span id="ErrNotMultipart">ErrNotMultipart</span> = &amp;<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"request Content-Type isn't multipart/form-data"}
  434. <span id="ErrMissingBoundary">ErrMissingBoundary</span> = &amp;<a href="https://golang.org/pkg/net/http/#ProtocolError">ProtocolError</a>{"no multipart boundary param in Content-Type"}
  435. )</pre>
  436. <pre>var (
  437. <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")
  438. <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")
  439. <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")
  440. <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")
  441. )</pre>
  442. <p>
  443. Errors introduced by the HTTP server.
  444. </p>
  445. <pre>var <span id="DefaultClient">DefaultClient</span> = &amp;<a href="https://golang.org/pkg/net/http/#Client">Client</a>{}</pre>
  446. <p>
  447. DefaultClient is the default Client and is used by Get, Head, and Post.
  448. </p>
  449. <pre>var <span id="DefaultServeMux">DefaultServeMux</span> = <a href="https://golang.org/pkg/net/http/#NewServeMux">NewServeMux</a>()</pre>
  450. <p>
  451. DefaultServeMux is the default ServeMux used by Serve.
  452. </p>
  453. <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>
  454. <p>
  455. ErrBodyReadAfterClose is returned when reading a Request or Response
  456. Body after the body has been closed. This typically happens when the body is
  457. read after an HTTP Handler calls WriteHeader or Write on its
  458. ResponseWriter.
  459. </p>
  460. <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>
  461. <p>
  462. ErrHandlerTimeout is returned on ResponseWriter Write calls
  463. in handlers which have timed out.
  464. </p>
  465. <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>
  466. <p>
  467. ErrLineTooLong is returned when reading request or response bodies
  468. with malformed chunked encoding.
  469. </p>
  470. <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>
  471. <p>
  472. ErrMissingFile is returned by FormFile when the provided file field name
  473. is either not present in the request or not a file field.
  474. </p>
  475. <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>
  476. <p>
  477. ErrNoCookie is returned by Request's Cookie method when a cookie is not found.
  478. </p>
  479. <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>
  480. <p>
  481. ErrNoLocation is returned by Response's Location method
  482. when no Location header is present.
  483. </p>
  484. <h2 id="CanonicalHeaderKey">func <a href="https://golang.org/src/net/http/header.go?s=4562:4602#L163">CanonicalHeaderKey</a></h2>
  485. <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>
  486. <p>
  487. CanonicalHeaderKey returns the canonical format of the
  488. header key s. The canonicalization converts the first
  489. letter and any letter following a hyphen to upper case;
  490. the rest are converted to lowercase. For example, the
  491. canonical key for "accept-encoding" is "Accept-Encoding".
  492. If s contains a space or invalid header field bytes, it is
  493. returned without modifications.
  494. </p>
  495. <h2 id="DetectContentType">func <a href="https://golang.org/src/net/http/sniff.go?s=648:690#L11">DetectContentType</a></h2>
  496. <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>
  497. <p>
  498. DetectContentType implements the algorithm described
  499. at <a href="http://mimesniff.spec.whatwg.org/">http://mimesniff.spec.whatwg.org/</a> to determine the
  500. Content-Type of the given data. It considers at most the
  501. first 512 bytes of data. DetectContentType always returns
  502. a valid MIME type: if it cannot determine a more specific one, it
  503. returns "application/octet-stream".
  504. </p>
  505. <h2 id="Error">func <a href="https://golang.org/src/net/http/server.go?s=41562:41614#L1419">Error</a></h2>
  506. <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>
  507. <p>
  508. Error replies to the request with the specified error message and HTTP code.
  509. The error message should be plain text.
  510. </p>
  511. <h2 id="Handle">func <a href="https://golang.org/src/net/http/server.go?s=51434:51478#L1740">Handle</a></h2>
  512. <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>
  513. <p>
  514. Handle registers the handler for the given pattern
  515. in the DefaultServeMux.
  516. The documentation for ServeMux explains how patterns are matched.
  517. </p>
  518. <h2 id="HandleFunc">func <a href="https://golang.org/src/net/http/server.go?s=51688:51759#L1745">HandleFunc</a></h2>
  519. <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>
  520. <p>
  521. HandleFunc registers the handler function for the given pattern
  522. in the DefaultServeMux.
  523. The documentation for ServeMux explains how patterns are matched.
  524. </p>
  525. <h2 id="ListenAndServe">func <a href="https://golang.org/src/net/http/server.go?s=58314:58369#L1955">ListenAndServe</a></h2>
  526. <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>
  527. <p>
  528. ListenAndServe listens on the TCP network address addr
  529. and then calls Serve with handler to handle requests
  530. on incoming connections. Handler is typically nil,
  531. in which case the DefaultServeMux is used.
  532. </p>
  533. <p>
  534. A trivial example server is:
  535. </p>
  536. <pre>package main
  537. import (
  538. "io"
  539. "net/http"
  540. "log"
  541. )
  542. // hello world, the web server
  543. func HelloServer(w http.ResponseWriter, req *http.Request) {
  544. io.WriteString(w, "hello, world!\n")
  545. }
  546. func main() {
  547. http.HandleFunc("/hello", HelloServer)
  548. err := http.ListenAndServe(":12345", nil)
  549. if err != nil {
  550. log.Fatal("ListenAndServe: ", err)
  551. }
  552. }
  553. </pre>
  554. <h2 id="ListenAndServeTLS">func <a href="https://golang.org/src/net/http/server.go?s=59426:59517#L1988">ListenAndServeTLS</a></h2>
  555. <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>
  556. <p>
  557. ListenAndServeTLS acts identically to ListenAndServe, except that it
  558. expects HTTPS connections. Additionally, files containing a certificate and
  559. matching private key for the server must be provided. If the certificate
  560. is signed by a certificate authority, the certFile should be the concatenation
  561. of the server's certificate, any intermediates, and the CA's certificate.
  562. </p>
  563. <p>
  564. A trivial example server is:
  565. </p>
  566. <pre>import (
  567. "log"
  568. "net/http"
  569. )
  570. func handler(w http.ResponseWriter, req *http.Request) {
  571. w.Header().Set("Content-Type", "text/plain")
  572. w.Write([]byte("This is an example server.\n"))
  573. }
  574. func main() {
  575. http.HandleFunc("/", handler)
  576. log.Printf("About to listen on 10443. Go to <a href="https://127.0.0.1:10443/">https://127.0.0.1:10443/</a>")
  577. err := http.ListenAndServeTLS(":10443", "cert.pem", "key.pem", nil)
  578. if err != nil {
  579. log.Fatal(err)
  580. }
  581. }
  582. </pre>
  583. <p>
  584. One can use generate_cert.go in crypto/tls to generate cert.pem and key.pem.
  585. </p>
  586. <h2 id="MaxBytesReader">func <a href="https://golang.org/src/net/http/request.go?s=22939:23016#L726">MaxBytesReader</a></h2>
  587. <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>
  588. <p>
  589. MaxBytesReader is similar to io.LimitReader but is intended for
  590. limiting the size of incoming request bodies. In contrast to
  591. io.LimitReader, MaxBytesReader's result is a ReadCloser, returns a
  592. non-EOF error for a Read beyond the limit, and closes the
  593. underlying reader when its Close method is called.
  594. </p>
  595. <p>
  596. MaxBytesReader prevents clients from accidentally or maliciously
  597. sending a large request and wasting server resources.
  598. </p>
  599. <h2 id="NotFound">func <a href="https://golang.org/src/net/http/server.go?s=41848:41891#L1427">NotFound</a></h2>
  600. <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>
  601. <p>
  602. NotFound replies to the request with an HTTP 404 not found error.
  603. </p>
  604. <h2 id="ParseHTTPVersion">func <a href="https://golang.org/src/net/http/request.go?s=16539:16601#L498">ParseHTTPVersion</a></h2>
  605. <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>
  606. <p>
  607. ParseHTTPVersion parses a HTTP version string.
  608. "HTTP/1.0" returns (1, 0, true).
  609. </p>
  610. <h2 id="ParseTime">func <a href="https://golang.org/src/net/http/header.go?s=1908:1960#L69">ParseTime</a></h2>
  611. <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>
  612. <p>
  613. ParseTime parses a time header (such as the Date: header),
  614. trying each of the three formats allowed by HTTP/1.1:
  615. TimeFormat, time.RFC850, and time.ANSIC.
  616. </p>
  617. <h2 id="ProxyFromEnvironment">func <a href="https://golang.org/src/net/http/transport.go?s=4805:4862#L126">ProxyFromEnvironment</a></h2>
  618. <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>
  619. <p>
  620. ProxyFromEnvironment returns the URL of the proxy to use for a
  621. given request, as indicated by the environment variables
  622. HTTP_PROXY, HTTPS_PROXY and NO_PROXY (or the lowercase versions
  623. thereof). HTTPS_PROXY takes precedence over HTTP_PROXY for https
  624. requests.
  625. </p>
  626. <p>
  627. The environment values may be either a complete URL or a
  628. "host[:port]", in which case the "http" scheme is assumed.
  629. An error is returned if the value is a different form.
  630. </p>
  631. <p>
  632. A nil URL and nil error are returned if no proxy is defined in the
  633. environment, or a proxy should not be used for the given request,
  634. as defined by NO_PROXY.
  635. </p>
  636. <p>
  637. As a special case, if req.URL.Host is "localhost" (with or without
  638. a port number), then a nil URL and nil error will be returned.
  639. </p>
  640. <h2 id="ProxyURL">func <a href="https://golang.org/src/net/http/transport.go?s=5664:5729#L157">ProxyURL</a></h2>
  641. <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>
  642. <p>
  643. ProxyURL returns a proxy function (for use in a Transport)
  644. that always returns the same URL.
  645. </p>
  646. <h2 id="Redirect">func <a href="https://golang.org/src/net/http/server.go?s=42815:42883#L1454">Redirect</a></h2>
  647. <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>
  648. <p>
  649. Redirect replies to the request with a redirect to url,
  650. which may be a path relative to the request path.
  651. </p>
  652. <h2 id="Serve">func <a href="https://golang.org/src/net/http/server.go?s=52072:52121#L1753">Serve</a></h2>
  653. <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>
  654. <p>
  655. Serve accepts incoming HTTP connections on the listener l,
  656. creating a new service goroutine for each. The service goroutines
  657. read requests and then call handler to reply to them.
  658. Handler is typically nil, in which case the DefaultServeMux is used.
  659. </p>
  660. <h2 id="ServeContent">func <a href="https://golang.org/src/net/http/fs.go?s=3535:3639#L107">ServeContent</a></h2>
  661. <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>
  662. <p>
  663. ServeContent replies to the request using the content in the
  664. provided ReadSeeker. The main benefit of ServeContent over io.Copy
  665. is that it handles Range requests properly, sets the MIME type, and
  666. handles If-Modified-Since requests.
  667. </p>
  668. <p>
  669. If the response's Content-Type header is not set, ServeContent
  670. first tries to deduce the type from name's file extension and,
  671. if that fails, falls back to reading the first block of the content
  672. and passing it to DetectContentType.
  673. The name is otherwise unused; in particular it can be empty and is
  674. never sent in the response.
  675. </p>
  676. <p>
  677. If modtime is not the zero time or Unix epoch, ServeContent
  678. includes it in a Last-Modified header in the response. If the
  679. request includes an If-Modified-Since header, ServeContent uses
  680. modtime to decide whether the content needs to be sent at all.
  681. </p>
  682. <p>
  683. The content's Seek method must work: ServeContent uses
  684. a seek to the end of the content to determine its size.
  685. </p>
  686. <p>
  687. If the caller has set w's ETag header, ServeContent uses it to
  688. handle requests using If-Range and If-None-Match.
  689. </p>
  690. <p>
  691. Note that *os.File implements the io.ReadSeeker interface.
  692. </p>
  693. <h2 id="ServeFile">func <a href="https://golang.org/src/net/http/fs.go?s=13941:13998#L443">ServeFile</a></h2>
  694. <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>
  695. <p>
  696. ServeFile replies to the request with the contents of the named
  697. file or directory.
  698. </p>
  699. <p>
  700. As a special case, ServeFile redirects any request where r.URL.Path
  701. ends in "/index.html" to the same path, without the final
  702. "index.html". To avoid such redirects either modify the path or
  703. use ServeContent.
  704. </p>
  705. <h2 id="SetCookie">func <a href="https://golang.org/src/net/http/cookie.go?s=3059:3107#L120">SetCookie</a></h2>
  706. <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>
  707. <p>
  708. SetCookie adds a Set-Cookie header to the provided ResponseWriter's headers.
  709. The provided cookie must have a valid Name. Invalid cookies may be
  710. silently dropped.
  711. </p>
  712. <h2 id="StatusText">func <a href="https://golang.org/src/net/http/status.go?s=4602:4634#L108">StatusText</a></h2>
  713. <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>
  714. <p>
  715. StatusText returns a text for the HTTP status code. It returns the empty
  716. string if the code is unknown.
  717. </p>
  718. <h2 id="Client">type <a href="https://golang.org/src/net/http/client.go?s=897:2420#L26">Client</a></h2>
  719. <pre>type Client struct {
  720. <span class="comment">// Transport specifies the mechanism by which individual</span>
  721. <span class="comment">// HTTP requests are made.</span>
  722. <span class="comment">// If nil, DefaultTransport is used.</span>
  723. Transport <a href="https://golang.org/pkg/net/http/#RoundTripper">RoundTripper</a>
  724. <span class="comment">// CheckRedirect specifies the policy for handling redirects.</span>
  725. <span class="comment">// If CheckRedirect is not nil, the client calls it before</span>
  726. <span class="comment">// following an HTTP redirect. The arguments req and via are</span>
  727. <span class="comment">// the upcoming request and the requests made already, oldest</span>
  728. <span class="comment">// first. If CheckRedirect returns an error, the Client's Get</span>
  729. <span class="comment">// method returns both the previous Response and</span>
  730. <span class="comment">// CheckRedirect's error (wrapped in a url.Error) instead of</span>
  731. <span class="comment">// issuing the Request req.</span>
  732. <span class="comment">//</span>
  733. <span class="comment">// If CheckRedirect is nil, the Client uses its default policy,</span>
  734. <span class="comment">// which is to stop after 10 consecutive requests.</span>
  735. 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>
  736. <span class="comment">// Jar specifies the cookie jar.</span>
  737. <span class="comment">// If Jar is nil, cookies are not sent in requests and ignored</span>
  738. <span class="comment">// in responses.</span>
  739. Jar <a href="https://golang.org/pkg/net/http/#CookieJar">CookieJar</a>
  740. <span class="comment">// Timeout specifies a time limit for requests made by this</span>
  741. <span class="comment">// Client. The timeout includes connection time, any</span>
  742. <span class="comment">// redirects, and reading the response body. The timer remains</span>
  743. <span class="comment">// running after Get, Head, Post, or Do return and will</span>
  744. <span class="comment">// interrupt reading of the Response.Body.</span>
  745. <span class="comment">//</span>
  746. <span class="comment">// A Timeout of zero means no timeout.</span>
  747. <span class="comment">//</span>
  748. <span class="comment">// The Client's Transport must support the CancelRequest</span>
  749. <span class="comment">// method or Client will return errors when attempting to make</span>
  750. <span class="comment">// a request with Get, Head, Post, or Do. Client's default</span>
  751. <span class="comment">// Transport (DefaultTransport) supports CancelRequest.</span>
  752. Timeout <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Duration">Duration</a>
  753. }</pre>
  754. <p>
  755. A Client is an HTTP client. Its zero value (DefaultClient) is a
  756. usable client that uses DefaultTransport.
  757. </p>
  758. <p>
  759. The Client's Transport typically has internal state (cached TCP
  760. connections), so Clients should be reused instead of created as
  761. needed. Clients are safe for concurrent use by multiple goroutines.
  762. </p>
  763. <p>
  764. A Client is higher-level than a RoundTripper (such as Transport)
  765. and additionally handles HTTP details such as cookies and
  766. redirects.
  767. </p>
  768. <h3 id="Client.Do">func (*Client) <a href="https://golang.org/src/net/http/client.go?s=6009:6070#L163">Do</a></h3>
  769. <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>
  770. <p>
  771. Do sends an HTTP request and returns an HTTP response, following
  772. policy (e.g. redirects, cookies, auth) as configured on the client.
  773. </p>
  774. <p>
  775. An error is returned if caused by client policy (such as
  776. CheckRedirect), or if there was an HTTP protocol error.
  777. A non-2xx response doesn't cause an error.
  778. </p>
  779. <p>
  780. When err is nil, resp always contains a non-nil resp.Body.
  781. </p>
  782. <p>
  783. Callers should close resp.Body when done reading from it. If
  784. resp.Body is not closed, the Client's underlying RoundTripper
  785. (typically Transport) may not be able to re-use a persistent TCP
  786. connection to the server for a subsequent "keep-alive" request.
  787. </p>
  788. <p>
  789. The request Body, if non-nil, will be closed by the underlying
  790. Transport, even on errors.
  791. </p>
  792. <p>
  793. Generally Get, Post, or PostForm will be used instead of Do.
  794. </p>
  795. <h3 id="Client.Get">func (*Client) <a href="https://golang.org/src/net/http/client.go?s=9928:9988#L291">Get</a></h3>
  796. <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>
  797. <p>
  798. Get issues a GET to the specified URL. If the response is one of the
  799. following redirect codes, Get follows the redirect after calling the
  800. Client's CheckRedirect function:
  801. </p>
  802. <pre>301 (Moved Permanently)
  803. 302 (Found)
  804. 303 (See Other)
  805. 307 (Temporary Redirect)
  806. </pre>
  807. <p>
  808. An error is returned if the Client's CheckRedirect function fails
  809. or if there was an HTTP protocol error. A non-2xx response doesn't
  810. cause an error.
  811. </p>
  812. <p>
  813. When err is nil, resp always contains a non-nil resp.Body.
  814. Caller should close resp.Body when done reading from it.
  815. </p>
  816. <p>
  817. To make a request with custom headers, use NewRequest and Client.Do.
  818. </p>
  819. <h3 id="Client.Head">func (*Client) <a href="https://golang.org/src/net/http/client.go?s=16276:16337#L512">Head</a></h3>
  820. <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>
  821. <p>
  822. Head issues a HEAD to the specified URL. If the response is one of the
  823. following redirect codes, Head follows the redirect after calling the
  824. Client's CheckRedirect function:
  825. </p>
  826. <pre>301 (Moved Permanently)
  827. 302 (Found)
  828. 303 (See Other)
  829. 307 (Temporary Redirect)
  830. </pre>
  831. <h3 id="Client.Post">func (*Client) <a href="https://golang.org/src/net/http/client.go?s=14197:14291#L455">Post</a></h3>
  832. <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>
  833. <p>
  834. Post issues a POST to the specified URL.
  835. </p>
  836. <p>
  837. Caller should close resp.Body when done reading from it.
  838. </p>
  839. <p>
  840. If the provided body is an io.Closer, it is closed after the
  841. request.
  842. </p>
  843. <p>
  844. To set custom headers, use NewRequest and Client.Do.
  845. </p>
  846. <h3 id="Client.PostForm">func (*Client) <a href="https://golang.org/src/net/http/client.go?s=15401:15483#L486">PostForm</a></h3>
  847. <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>
  848. <p>
  849. PostForm issues a POST to the specified URL,
  850. with data's keys and values URL-encoded as the request body.
  851. </p>
  852. <p>
  853. The Content-Type header is set to application/x-www-form-urlencoded.
  854. To set other headers, use NewRequest and DefaultClient.Do.
  855. </p>
  856. <p>
  857. When err is nil, resp always contains a non-nil resp.Body.
  858. Caller should close resp.Body when done reading from it.
  859. </p>
  860. <h2 id="CloseNotifier">type <a href="https://golang.org/src/net/http/server.go?s=3931:4099#L106">CloseNotifier</a></h2>
  861. <pre>type CloseNotifier interface {
  862. <span class="comment">// CloseNotify returns a channel that receives a single value</span>
  863. <span class="comment">// when the client connection has gone away.</span>
  864. CloseNotify() &lt;-chan <a href="https://golang.org/pkg/builtin/#bool">bool</a>
  865. }</pre>
  866. <p>
  867. The CloseNotifier interface is implemented by ResponseWriters which
  868. allow detecting when the underlying connection has gone away.
  869. </p>
  870. <p>
  871. This mechanism can be used to cancel long operations on the server
  872. if the client has disconnected before the response is ready.
  873. </p>
  874. <h2 id="ConnState">type <a href="https://golang.org/src/net/http/server.go?s=53915:53933#L1793">ConnState</a></h2>
  875. <pre>type ConnState <a href="https://golang.org/pkg/builtin/#int">int</a></pre>
  876. <p>
  877. A ConnState represents the state of a client connection to a server.
  878. It's used by the optional Server.ConnState hook.
  879. </p>
  880. <pre>const (
  881. <span class="comment">// StateNew represents a new connection that is expected to</span>
  882. <span class="comment">// send a request immediately. Connections begin at this</span>
  883. <span class="comment">// state and then transition to either StateActive or</span>
  884. <span class="comment">// StateClosed.</span>
  885. <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>
  886. <span class="comment">// StateActive represents a connection that has read 1 or more</span>
  887. <span class="comment">// bytes of a request. The Server.ConnState hook for</span>
  888. <span class="comment">// StateActive fires before the request has entered a handler</span>
  889. <span class="comment">// and doesn't fire again until the request has been</span>
  890. <span class="comment">// handled. After the request is handled, the state</span>
  891. <span class="comment">// transitions to StateClosed, StateHijacked, or StateIdle.</span>
  892. <span id="StateActive">StateActive</span>
  893. <span class="comment">// StateIdle represents a connection that has finished</span>
  894. <span class="comment">// handling a request and is in the keep-alive state, waiting</span>
  895. <span class="comment">// for a new request. Connections transition from StateIdle</span>
  896. <span class="comment">// to either StateActive or StateClosed.</span>
  897. <span id="StateIdle">StateIdle</span>
  898. <span class="comment">// StateHijacked represents a hijacked connection.</span>
  899. <span class="comment">// This is a terminal state. It does not transition to StateClosed.</span>
  900. <span id="StateHijacked">StateHijacked</span>
  901. <span class="comment">// StateClosed represents a closed connection.</span>
  902. <span class="comment">// This is a terminal state. Hijacked connections do not</span>
  903. <span class="comment">// transition to StateClosed.</span>
  904. <span id="StateClosed">StateClosed</span>
  905. )</pre>
  906. <h3 id="ConnState.String">func (ConnState) <a href="https://golang.org/src/net/http/server.go?s=55217:55251#L1834">String</a></h3>
  907. <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>
  908. <h2 id="Cookie">type <a href="https://golang.org/src/net/http/cookie.go?s=439:952#L11">Cookie</a></h2>
  909. <pre>type Cookie struct {
  910. Name <a href="https://golang.org/pkg/builtin/#string">string</a>
  911. Value <a href="https://golang.org/pkg/builtin/#string">string</a>
  912. Path <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// optional</span>
  913. Domain <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// optional</span>
  914. 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>
  915. RawExpires <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// for reading cookies only</span>
  916. <span class="comment">// MaxAge=0 means no 'Max-Age' attribute specified.</span>
  917. <span class="comment">// MaxAge&lt;0 means delete cookie now, equivalently 'Max-Age: 0'</span>
  918. <span class="comment">// MaxAge&gt;0 means Max-Age attribute present and given in seconds</span>
  919. MaxAge <a href="https://golang.org/pkg/builtin/#int">int</a>
  920. Secure <a href="https://golang.org/pkg/builtin/#bool">bool</a>
  921. HttpOnly <a href="https://golang.org/pkg/builtin/#bool">bool</a>
  922. Raw <a href="https://golang.org/pkg/builtin/#string">string</a>
  923. Unparsed []<a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// Raw text of unparsed attribute-value pairs</span>
  924. }</pre>
  925. <p>
  926. A Cookie represents an HTTP cookie as sent in the Set-Cookie header of an
  927. HTTP response or the Cookie header of an HTTP request.
  928. </p>
  929. <p>
  930. See <a href="http://tools.ietf.org/html/rfc6265">http://tools.ietf.org/html/rfc6265</a> for details.
  931. </p>
  932. <h3 id="Cookie.String">func (*Cookie) <a href="https://golang.org/src/net/http/cookie.go?s=3428:3460#L130">String</a></h3>
  933. <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>
  934. <p>
  935. String returns the serialization of the cookie for use in a Cookie
  936. header (if only Name and Value are set) or a Set-Cookie response
  937. header (if other fields are set).
  938. If c is nil or c.Name is invalid, the empty string is returned.
  939. </p>
  940. <h2 id="CookieJar">type <a href="https://golang.org/src/net/http/jar.go?s=433:899#L7">CookieJar</a></h2>
  941. <pre>type CookieJar interface {
  942. <span class="comment">// SetCookies handles the receipt of the cookies in a reply for the</span>
  943. <span class="comment">// given URL. It may or may not choose to save the cookies, depending</span>
  944. <span class="comment">// on the jar's policy and implementation.</span>
  945. 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>)
  946. <span class="comment">// Cookies returns the cookies to send in a request for the given URL.</span>
  947. <span class="comment">// It is up to the implementation to honor the standard cookie use</span>
  948. <span class="comment">// restrictions such as in RFC 6265.</span>
  949. 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>
  950. }</pre>
  951. <p>
  952. A CookieJar manages storage and use of cookies in HTTP requests.
  953. </p>
  954. <p>
  955. Implementations of CookieJar must be safe for concurrent use by multiple
  956. goroutines.
  957. </p>
  958. <p>
  959. The net/http/cookiejar package provides a CookieJar implementation.
  960. </p>
  961. <h2 id="Dir">type <a href="https://golang.org/src/net/http/fs.go?s=719:734#L23">Dir</a></h2>
  962. <pre>type Dir <a href="https://golang.org/pkg/builtin/#string">string</a></pre>
  963. <p>
  964. A Dir implements FileSystem using the native file system restricted to a
  965. specific directory tree.
  966. </p>
  967. <p>
  968. While the FileSystem.Open method takes '/'-separated paths, a Dir's string
  969. value is a filename on the native file system, not a URL, so it is separated
  970. by filepath.Separator, which isn't necessarily '/'.
  971. </p>
  972. <p>
  973. An empty Dir is treated as ".".
  974. </p>
  975. <h3 id="Dir.Open">func (Dir) <a href="https://golang.org/src/net/http/fs.go?s=736:780#L25">Open</a></h3>
  976. <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>
  977. <h2 id="File">type <a href="https://golang.org/src/net/http/fs.go?s=1591:1755#L52">File</a></h2>
  978. <pre>type File interface {
  979. <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#Closer">Closer</a>
  980. <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#Reader">Reader</a>
  981. 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>)
  982. 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>)
  983. 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>)
  984. }</pre>
  985. <p>
  986. A File is returned by a FileSystem's Open method and can be
  987. served by the FileServer implementation.
  988. </p>
  989. <p>
  990. The methods should behave the same as those on an *os.File.
  991. </p>
  992. <h2 id="FileSystem">type <a href="https://golang.org/src/net/http/fs.go?s=1354:1416#L44">FileSystem</a></h2>
  993. <pre>type FileSystem interface {
  994. 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>)
  995. }</pre>
  996. <p>
  997. A FileSystem implements access to a collection of named files.
  998. The elements in a file path are separated by slash ('/', U+002F)
  999. characters, regardless of host operating system convention.
  1000. </p>
  1001. <h2 id="Flusher">type <a href="https://golang.org/src/net/http/server.go?s=2921:3005#L79">Flusher</a></h2>
  1002. <pre>type Flusher interface {
  1003. <span class="comment">// Flush sends any buffered data to the client.</span>
  1004. Flush()
  1005. }</pre>
  1006. <p>
  1007. The Flusher interface is implemented by ResponseWriters that allow
  1008. an HTTP handler to flush buffered data to the client.
  1009. </p>
  1010. <p>
  1011. Note that even for ResponseWriters that support Flush,
  1012. if the client is connected through an HTTP proxy,
  1013. the buffered data may not reach the client until the response
  1014. completes.
  1015. </p>
  1016. <h2 id="Handler">type <a href="https://golang.org/src/net/http/server.go?s=1361:1424#L42">Handler</a></h2>
  1017. <pre>type Handler interface {
  1018. ServeHTTP(<a href="https://golang.org/pkg/net/http/#ResponseWriter">ResponseWriter</a>, *<a href="https://golang.org/pkg/net/http/#Request">Request</a>)
  1019. }</pre>
  1020. <p>
  1021. Objects implementing the Handler interface can be
  1022. registered to serve a particular path or subtree
  1023. in the HTTP server.
  1024. </p>
  1025. <p>
  1026. ServeHTTP should write reply headers and data to the ResponseWriter
  1027. and then return. Returning signals that the request is finished
  1028. and that the HTTP server can move on to the next request on
  1029. the connection.
  1030. </p>
  1031. <p>
  1032. If ServeHTTP panics, the server (the caller of ServeHTTP) assumes
  1033. that the effect of the panic was isolated to the active request.
  1034. It recovers the panic, logs a stack trace to the server error log,
  1035. and hangs up the connection.
  1036. </p>
  1037. <h3 id="FileServer">func <a href="https://golang.org/src/net/http/fs.go?s=14534:14574#L463">FileServer</a></h3>
  1038. <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>
  1039. <p>
  1040. FileServer returns a handler that serves HTTP requests
  1041. with the contents of the file system rooted at root.
  1042. </p>
  1043. <p>
  1044. To use the operating system's file system implementation,
  1045. use http.Dir:
  1046. </p>
  1047. <pre>http.Handle("/", http.FileServer(http.Dir("/tmp")))
  1048. </pre>
  1049. <p>
  1050. As a special case, the returned file server redirects any request
  1051. ending in "/index.html" to the same path, without the final
  1052. "index.html".
  1053. </p>
  1054. <div id="example_FileServer" class="toggle">
  1055. <div class="collapsed">
  1056. <p class="exampleHeading toggleButton">▹ <span class="text">Example</span></p>
  1057. </div>
  1058. <div class="expanded">
  1059. <p class="exampleHeading toggleButton">▾ <span class="text">Example</span></p>
  1060. <div class="play">
  1061. <div class="input"><textarea class="code">package main
  1062. import (
  1063. "log"
  1064. "net/http"
  1065. )
  1066. func main() {
  1067. // Simple static webserver:
  1068. log.Fatal(http.ListenAndServe(":8080", http.FileServer(http.Dir("/usr/share/doc"))))
  1069. }
  1070. </textarea></div>
  1071. <div class="output"><pre></pre></div>
  1072. <div class="buttons">
  1073. <a class="run" title="Run this code [shift-enter]">Run</a>
  1074. <a class="fmt" title="Format this code">Format</a>
  1075. </div>
  1076. </div>
  1077. </div>
  1078. </div>
  1079. <div id="example_FileServer_stripPrefix" class="toggle">
  1080. <div class="collapsed">
  1081. <p class="exampleHeading toggleButton">▹ <span class="text">Example (StripPrefix)</span></p>
  1082. </div>
  1083. <div class="expanded">
  1084. <p class="exampleHeading toggleButton">▾ <span class="text">Example (StripPrefix)</span></p>
  1085. <div class="play">
  1086. <div class="input"><textarea class="code">package main
  1087. import (
  1088. "net/http"
  1089. )
  1090. func main() {
  1091. // To serve a directory on disk (/tmp) under an alternate URL
  1092. // path (/tmpfiles/), use StripPrefix to modify the request
  1093. // URL's path before the FileServer sees it:
  1094. http.Handle("/tmpfiles/", http.StripPrefix("/tmpfiles/", http.FileServer(http.Dir("/tmp"))))
  1095. }
  1096. </textarea></div>
  1097. <div class="output"><pre></pre></div>
  1098. <div class="buttons">
  1099. <a class="run" title="Run this code [shift-enter]">Run</a>
  1100. <a class="fmt" title="Format this code">Format</a>
  1101. </div>
  1102. </div>
  1103. </div>
  1104. </div>
  1105. <h3 id="NotFoundHandler">func <a href="https://golang.org/src/net/http/server.go?s=42065:42095#L1431">NotFoundHandler</a></h3>
  1106. <pre>func NotFoundHandler() <a href="https://golang.org/pkg/net/http/#Handler">Handler</a></pre>
  1107. <p>
  1108. NotFoundHandler returns a simple request handler
  1109. that replies to each request with a “404 page not found” reply.
  1110. </p>
  1111. <h3 id="RedirectHandler">func <a href="https://golang.org/src/net/http/server.go?s=45249:45299#L1538">RedirectHandler</a></h3>
  1112. <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>
  1113. <p>
  1114. RedirectHandler returns a request handler that redirects
  1115. each request it receives to the given url using the given
  1116. status code.
  1117. </p>
  1118. <h3 id="StripPrefix">func <a href="https://golang.org/src/net/http/server.go?s=42404:42454#L1438">StripPrefix</a></h3>
  1119. <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>
  1120. <p>
  1121. StripPrefix returns a handler that serves HTTP requests
  1122. by removing the given prefix from the request URL's Path
  1123. and invoking the handler h. StripPrefix handles a
  1124. request for a path that doesn't begin with prefix by
  1125. replying with an HTTP 404 not found error.
  1126. </p>
  1127. <div id="example_StripPrefix" class="toggle">
  1128. <div class="collapsed">
  1129. <p class="exampleHeading toggleButton">▹ <span class="text">Example</span></p>
  1130. </div>
  1131. <div class="expanded">
  1132. <p class="exampleHeading toggleButton">▾ <span class="text">Example</span></p>
  1133. <div class="play">
  1134. <div class="input"><textarea class="code">package main
  1135. import (
  1136. "net/http"
  1137. )
  1138. func main() {
  1139. // To serve a directory on disk (/tmp) under an alternate URL
  1140. // path (/tmpfiles/), use StripPrefix to modify the request
  1141. // URL's path before the FileServer sees it:
  1142. http.Handle("/tmpfiles/", http.StripPrefix("/tmpfiles/", http.FileServer(http.Dir("/tmp"))))
  1143. }
  1144. </textarea></div>
  1145. <div class="output"><pre></pre></div>
  1146. <div class="buttons">
  1147. <a class="run" title="Run this code [shift-enter]">Run</a>
  1148. <a class="fmt" title="Format this code">Format</a>
  1149. </div>
  1150. </div>
  1151. </div>
  1152. </div>
  1153. <h3 id="TimeoutHandler">func <a href="https://golang.org/src/net/http/server.go?s=61275:61343#L2039">TimeoutHandler</a></h3>
  1154. <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>
  1155. <p>
  1156. TimeoutHandler returns a Handler that runs h with the given time limit.
  1157. </p>
  1158. <p>
  1159. The new Handler calls h.ServeHTTP to handle each request, but if a
  1160. call runs for longer than its time limit, the handler responds with
  1161. a 503 Service Unavailable error and the given message in its body.
  1162. (If msg is empty, a suitable default message will be sent.)
  1163. After such a timeout, writes by h to its ResponseWriter will return
  1164. ErrHandlerTimeout.
  1165. </p>
  1166. <h2 id="HandlerFunc">type <a href="https://golang.org/src/net/http/server.go?s=41267:41314#L1408">HandlerFunc</a></h2>
  1167. <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>
  1168. <p>
  1169. The HandlerFunc type is an adapter to allow the use of
  1170. ordinary functions as HTTP handlers. If f is a function
  1171. with the appropriate signature, HandlerFunc(f) is a
  1172. Handler object that calls f.
  1173. </p>
  1174. <h3 id="HandlerFunc.ServeHTTP">func (HandlerFunc) <a href="https://golang.org/src/net/http/server.go?s=41344:41404#L1411">ServeHTTP</a></h3>
  1175. <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>
  1176. <p>
  1177. ServeHTTP calls f(w, r).
  1178. </p>
  1179. <h2 id="Header">type <a href="https://golang.org/src/net/http/header.go?s=350:381#L9">Header</a></h2>
  1180. <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>
  1181. <p>
  1182. A Header represents the key-value pairs in an HTTP header.
  1183. </p>
  1184. <h3 id="Header.Add">func (Header) <a href="https://golang.org/src/net/http/header.go?s=488:526#L13">Add</a></h3>
  1185. <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>
  1186. <p>
  1187. Add adds the key, value pair to the header.
  1188. It appends to any existing values associated with key.
  1189. </p>
  1190. <h3 id="Header.Del">func (Header) <a href="https://golang.org/src/net/http/header.go?s=1321:1352#L41">Del</a></h3>
  1191. <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>
  1192. <p>
  1193. Del deletes the values associated with key.
  1194. </p>
  1195. <h3 id="Header.Get">func (Header) <a href="https://golang.org/src/net/http/header.go?s=1015:1053#L28">Get</a></h3>
  1196. <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>
  1197. <p>
  1198. Get gets the first value associated with the given key.
  1199. If there are no values associated with the key, Get returns "".
  1200. To access multiple values of a key, access the map directly
  1201. with CanonicalHeaderKey.
  1202. </p>
  1203. <h3 id="Header.Set">func (Header) <a href="https://golang.org/src/net/http/header.go?s=713:751#L20">Set</a></h3>
  1204. <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>
  1205. <p>
  1206. Set sets the header entries associated with key to
  1207. the single element value. It replaces any existing
  1208. values associated with key.
  1209. </p>
  1210. <h3 id="Header.Write">func (Header) <a href="https://golang.org/src/net/http/header.go?s=1433:1473#L46">Write</a></h3>
  1211. <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>
  1212. <p>
  1213. Write writes a header in wire format.
  1214. </p>
  1215. <h3 id="Header.WriteSubset">func (Header) <a href="https://golang.org/src/net/http/header.go?s=3676:3747#L135">WriteSubset</a></h3>
  1216. <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>
  1217. <p>
  1218. WriteSubset writes a header in wire format.
  1219. If exclude is not nil, keys where exclude[key] == true are not written.
  1220. </p>
  1221. <h2 id="Hijacker">type <a href="https://golang.org/src/net/http/server.go?s=3126:3656#L86">Hijacker</a></h2>
  1222. <pre>type Hijacker interface {
  1223. <span class="comment">// Hijack lets the caller take over the connection.</span>
  1224. <span class="comment">// After a call to Hijack(), the HTTP server library</span>
  1225. <span class="comment">// will not do anything else with the connection.</span>
  1226. <span class="comment">//</span>
  1227. <span class="comment">// It becomes the caller's responsibility to manage</span>
  1228. <span class="comment">// and close the connection.</span>
  1229. <span class="comment">//</span>
  1230. <span class="comment">// The returned net.Conn may have read or write deadlines</span>
  1231. <span class="comment">// already set, depending on the configuration of the</span>
  1232. <span class="comment">// Server. It is the caller's responsibility to set</span>
  1233. <span class="comment">// or clear those deadlines as needed.</span>
  1234. 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>)
  1235. }</pre>
  1236. <p>
  1237. The Hijacker interface is implemented by ResponseWriters that allow
  1238. an HTTP handler to take over the connection.
  1239. </p>
  1240. <div id="example_Hijacker" class="toggle">
  1241. <div class="collapsed">
  1242. <p class="exampleHeading toggleButton">▹ <span class="text">Example</span></p>
  1243. </div>
  1244. <div class="expanded">
  1245. <p class="exampleHeading toggleButton">▾ <span class="text">Example</span></p>
  1246. <div class="play">
  1247. <div class="input"><textarea class="code">package main
  1248. import (
  1249. "fmt"
  1250. "log"
  1251. "net/http"
  1252. )
  1253. func main() {
  1254. http.HandleFunc("/hijack", func(w http.ResponseWriter, r *http.Request) {
  1255. hj, ok := w.(http.Hijacker)
  1256. if !ok {
  1257. http.Error(w, "webserver doesn't support hijacking", http.StatusInternalServerError)
  1258. return
  1259. }
  1260. conn, bufrw, err := hj.Hijack()
  1261. if err != nil {
  1262. http.Error(w, err.Error(), http.StatusInternalServerError)
  1263. return
  1264. }
  1265. // Don't forget to close the connection:
  1266. defer conn.Close()
  1267. bufrw.WriteString("Now we're speaking raw TCP. Say hi: ")
  1268. bufrw.Flush()
  1269. s, err := bufrw.ReadString('\n')
  1270. if err != nil {
  1271. log.Printf("error reading string: %v", err)
  1272. return
  1273. }
  1274. fmt.Fprintf(bufrw, "You said: %q\nBye.\n", s)
  1275. bufrw.Flush()
  1276. })
  1277. }
  1278. </textarea></div>
  1279. <div class="output"><pre></pre></div>
  1280. <div class="buttons">
  1281. <a class="run" title="Run this code [shift-enter]">Run</a>
  1282. <a class="fmt" title="Format this code">Format</a>
  1283. </div>
  1284. </div>
  1285. </div>
  1286. </div>
  1287. <h2 id="ProtocolError">type <a href="https://golang.org/src/net/http/request.go?s=668:717#L26">ProtocolError</a></h2>
  1288. <pre>type ProtocolError struct {
  1289. ErrorString <a href="https://golang.org/pkg/builtin/#string">string</a>
  1290. }</pre>
  1291. <p>
  1292. HTTP request parsing errors.
  1293. </p>
  1294. <h3 id="ProtocolError.Error">func (*ProtocolError) <a href="https://golang.org/src/net/http/request.go?s=719:759#L30">Error</a></h3>
  1295. <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>
  1296. <h2 id="Request">type <a href="https://golang.org/src/net/http/request.go?s=2057:8270#L64">Request</a></h2>
  1297. <pre>type Request struct {
  1298. <span class="comment">// Method specifies the HTTP method (GET, POST, PUT, etc.).</span>
  1299. <span class="comment">// For client requests an empty string means GET.</span>
  1300. Method <a href="https://golang.org/pkg/builtin/#string">string</a>
  1301. <span class="comment">// URL specifies either the URI being requested (for server</span>
  1302. <span class="comment">// requests) or the URL to access (for client requests).</span>
  1303. <span class="comment">//</span>
  1304. <span class="comment">// For server requests the URL is parsed from the URI</span>
  1305. <span class="comment">// supplied on the Request-Line as stored in RequestURI. For</span>
  1306. <span class="comment">// most requests, fields other than Path and RawQuery will be</span>
  1307. <span class="comment">// empty. (See RFC 2616, Section 5.1.2)</span>
  1308. <span class="comment">//</span>
  1309. <span class="comment">// For client requests, the URL's Host specifies the server to</span>
  1310. <span class="comment">// connect to, while the Request's Host field optionally</span>
  1311. <span class="comment">// specifies the Host header value to send in the HTTP</span>
  1312. <span class="comment">// request.</span>
  1313. URL *<a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#URL">URL</a>
  1314. <span class="comment">// The protocol version for incoming requests.</span>
  1315. <span class="comment">// Client requests always use HTTP/1.1.</span>
  1316. Proto <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// "HTTP/1.0"</span>
  1317. ProtoMajor <a href="https://golang.org/pkg/builtin/#int">int</a> <span class="comment">// 1</span>
  1318. ProtoMinor <a href="https://golang.org/pkg/builtin/#int">int</a> <span class="comment">// 0</span>
  1319. <span class="comment">// A header maps request lines to their values.</span>
  1320. <span class="comment">// If the header says</span>
  1321. <span class="comment">//</span>
  1322. <span class="comment">// accept-encoding: gzip, deflate</span>
  1323. <span class="comment">// Accept-Language: en-us</span>
  1324. <span class="comment">// Connection: keep-alive</span>
  1325. <span class="comment">//</span>
  1326. <span class="comment">// then</span>
  1327. <span class="comment">//</span>
  1328. <span class="comment">// Header = map[string][]string{</span>
  1329. <span class="comment">// "Accept-Encoding": {"gzip, deflate"},</span>
  1330. <span class="comment">// "Accept-Language": {"en-us"},</span>
  1331. <span class="comment">// "Connection": {"keep-alive"},</span>
  1332. <span class="comment">// }</span>
  1333. <span class="comment">//</span>
  1334. <span class="comment">// HTTP defines that header names are case-insensitive.</span>
  1335. <span class="comment">// The request parser implements this by canonicalizing the</span>
  1336. <span class="comment">// name, making the first character and any characters</span>
  1337. <span class="comment">// following a hyphen uppercase and the rest lowercase.</span>
  1338. <span class="comment">//</span>
  1339. <span class="comment">// For client requests certain headers are automatically</span>
  1340. <span class="comment">// added and may override values in Header.</span>
  1341. <span class="comment">//</span>
  1342. <span class="comment">// See the documentation for the Request.Write method.</span>
  1343. Header <a href="https://golang.org/pkg/net/http/#Header">Header</a>
  1344. <span class="comment">// Body is the request's body.</span>
  1345. <span class="comment">//</span>
  1346. <span class="comment">// For client requests a nil body means the request has no</span>
  1347. <span class="comment">// body, such as a GET request. The HTTP Client's Transport</span>
  1348. <span class="comment">// is responsible for calling the Close method.</span>
  1349. <span class="comment">//</span>
  1350. <span class="comment">// For server requests the Request Body is always non-nil</span>
  1351. <span class="comment">// but will return EOF immediately when no body is present.</span>
  1352. <span class="comment">// The Server will close the request body. The ServeHTTP</span>
  1353. <span class="comment">// Handler does not need to.</span>
  1354. Body <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#ReadCloser">ReadCloser</a>
  1355. <span class="comment">// ContentLength records the length of the associated content.</span>
  1356. <span class="comment">// The value -1 indicates that the length is unknown.</span>
  1357. <span class="comment">// Values &gt;= 0 indicate that the given number of bytes may</span>
  1358. <span class="comment">// be read from Body.</span>
  1359. <span class="comment">// For client requests, a value of 0 means unknown if Body is not nil.</span>
  1360. ContentLength <a href="https://golang.org/pkg/builtin/#int64">int64</a>
  1361. <span class="comment">// TransferEncoding lists the transfer encodings from outermost to</span>
  1362. <span class="comment">// innermost. An empty list denotes the "identity" encoding.</span>
  1363. <span class="comment">// TransferEncoding can usually be ignored; chunked encoding is</span>
  1364. <span class="comment">// automatically added and removed as necessary when sending and</span>
  1365. <span class="comment">// receiving requests.</span>
  1366. TransferEncoding []<a href="https://golang.org/pkg/builtin/#string">string</a>
  1367. <span class="comment">// Close indicates whether to close the connection after</span>
  1368. <span class="comment">// replying to this request (for servers) or after sending</span>
  1369. <span class="comment">// the request (for clients).</span>
  1370. Close <a href="https://golang.org/pkg/builtin/#bool">bool</a>
  1371. <span class="comment">// For server requests Host specifies the host on which the</span>
  1372. <span class="comment">// URL is sought. Per RFC 2616, this is either the value of</span>
  1373. <span class="comment">// the "Host" header or the host name given in the URL itself.</span>
  1374. <span class="comment">// It may be of the form "host:port".</span>
  1375. <span class="comment">//</span>
  1376. <span class="comment">// For client requests Host optionally overrides the Host</span>
  1377. <span class="comment">// header to send. If empty, the Request.Write method uses</span>
  1378. <span class="comment">// the value of URL.Host.</span>
  1379. Host <a href="https://golang.org/pkg/builtin/#string">string</a>
  1380. <span class="comment">// Form contains the parsed form data, including both the URL</span>
  1381. <span class="comment">// field's query parameters and the POST or PUT form data.</span>
  1382. <span class="comment">// This field is only available after ParseForm is called.</span>
  1383. <span class="comment">// The HTTP client ignores Form and uses Body instead.</span>
  1384. Form <a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#Values">Values</a>
  1385. <span class="comment">// PostForm contains the parsed form data from POST, PATCH,</span>
  1386. <span class="comment">// or PUT body parameters.</span>
  1387. <span class="comment">//</span>
  1388. <span class="comment">// This field is only available after ParseForm is called.</span>
  1389. <span class="comment">// The HTTP client ignores PostForm and uses Body instead.</span>
  1390. PostForm <a href="https://golang.org/pkg/net/url/">url</a>.<a href="https://golang.org/pkg/net/url/#Values">Values</a>
  1391. <span class="comment">// MultipartForm is the parsed multipart form, including file uploads.</span>
  1392. <span class="comment">// This field is only available after ParseMultipartForm is called.</span>
  1393. <span class="comment">// The HTTP client ignores MultipartForm and uses Body instead.</span>
  1394. MultipartForm *<a href="https://golang.org/pkg/mime/multipart/">multipart</a>.<a href="https://golang.org/pkg/mime/multipart/#Form">Form</a>
  1395. <span class="comment">// Trailer specifies additional headers that are sent after the request</span>
  1396. <span class="comment">// body.</span>
  1397. <span class="comment">//</span>
  1398. <span class="comment">// For server requests the Trailer map initially contains only the</span>
  1399. <span class="comment">// trailer keys, with nil values. (The client declares which trailers it</span>
  1400. <span class="comment">// will later send.) While the handler is reading from Body, it must</span>
  1401. <span class="comment">// not reference Trailer. After reading from Body returns EOF, Trailer</span>
  1402. <span class="comment">// can be read again and will contain non-nil values, if they were sent</span>
  1403. <span class="comment">// by the client.</span>
  1404. <span class="comment">//</span>
  1405. <span class="comment">// For client requests Trailer must be initialized to a map containing</span>
  1406. <span class="comment">// the trailer keys to later send. The values may be nil or their final</span>
  1407. <span class="comment">// values. The ContentLength must be 0 or -1, to send a chunked request.</span>
  1408. <span class="comment">// After the HTTP request is sent the map values can be updated while</span>
  1409. <span class="comment">// the request body is read. Once the body returns EOF, the caller must</span>
  1410. <span class="comment">// not mutate Trailer.</span>
  1411. <span class="comment">//</span>
  1412. <span class="comment">// Few HTTP clients, servers, or proxies support HTTP trailers.</span>
  1413. Trailer <a href="https://golang.org/pkg/net/http/#Header">Header</a>
  1414. <span class="comment">// RemoteAddr allows HTTP servers and other software to record</span>
  1415. <span class="comment">// the network address that sent the request, usually for</span>
  1416. <span class="comment">// logging. This field is not filled in by ReadRequest and</span>
  1417. <span class="comment">// has no defined format. The HTTP server in this package</span>
  1418. <span class="comment">// sets RemoteAddr to an "IP:port" address before invoking a</span>
  1419. <span class="comment">// handler.</span>
  1420. <span class="comment">// This field is ignored by the HTTP client.</span>
  1421. RemoteAddr <a href="https://golang.org/pkg/builtin/#string">string</a>
  1422. <span class="comment">// RequestURI is the unmodified Request-URI of the</span>
  1423. <span class="comment">// Request-Line (RFC 2616, Section 5.1) as sent by the client</span>
  1424. <span class="comment">// to a server. Usually the URL field should be used instead.</span>
  1425. <span class="comment">// It is an error to set this field in an HTTP client request.</span>
  1426. RequestURI <a href="https://golang.org/pkg/builtin/#string">string</a>
  1427. <span class="comment">// TLS allows HTTP servers and other software to record</span>
  1428. <span class="comment">// information about the TLS connection on which the request</span>
  1429. <span class="comment">// was received. This field is not filled in by ReadRequest.</span>
  1430. <span class="comment">// The HTTP server in this package sets the field for</span>
  1431. <span class="comment">// TLS-enabled connections before invoking a handler;</span>
  1432. <span class="comment">// otherwise it leaves the field nil.</span>
  1433. <span class="comment">// This field is ignored by the HTTP client.</span>
  1434. TLS *<a href="https://golang.org/pkg/crypto/tls/">tls</a>.<a href="https://golang.org/pkg/crypto/tls/#ConnectionState">ConnectionState</a>
  1435. <span class="comment">// Cancel is an optional channel whose closure indicates that the client</span>
  1436. <span class="comment">// request should be regarded as canceled. Not all implementations of</span>
  1437. <span class="comment">// RoundTripper may support Cancel.</span>
  1438. <span class="comment">//</span>
  1439. <span class="comment">// For server requests, this field is not applicable.</span>
  1440. Cancel &lt;-chan struct{}
  1441. }</pre>
  1442. <p>
  1443. A Request represents an HTTP request received by a server
  1444. or to be sent by a client.
  1445. </p>
  1446. <p>
  1447. The field semantics differ slightly between client and server
  1448. usage. In addition to the notes on the fields below, see the
  1449. documentation for Request.Write and RoundTripper.
  1450. </p>
  1451. <h3 id="NewRequest">func <a href="https://golang.org/src/net/http/request.go?s=17718:17790#L536">NewRequest</a></h3>
  1452. <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>
  1453. <p>
  1454. NewRequest returns a new Request given a method, URL, and optional body.
  1455. </p>
  1456. <p>
  1457. If the provided body is also an io.Closer, the returned
  1458. Request.Body is set to body and will be closed by the Client
  1459. methods Do, Post, and PostForm, and Transport.RoundTrip.
  1460. </p>
  1461. <p>
  1462. NewRequest returns a Request suitable for use with Client.Do or
  1463. Transport.RoundTrip.
  1464. To create a request for use with testing a Server Handler use either
  1465. ReadRequest or manually update the Request fields. See the Request
  1466. type's documentation for the difference between inbound and outbound
  1467. request fields.
  1468. </p>
  1469. <h3 id="ReadRequest">func <a href="https://golang.org/src/net/http/request.go?s=20301:20360#L636">ReadRequest</a></h3>
  1470. <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>
  1471. <p>
  1472. ReadRequest reads and parses an incoming request from b.
  1473. </p>
  1474. <h3 id="Request.AddCookie">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=9423:9461#L259">AddCookie</a></h3>
  1475. <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>
  1476. <p>
  1477. AddCookie adds a cookie to the request. Per RFC 6265 section 5.4,
  1478. AddCookie does not attach more than one Cookie header field. That
  1479. means all cookies, if any, are written into the same line,
  1480. separated by semicolon.
  1481. </p>
  1482. <h3 id="Request.BasicAuth">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=18567:18633#L572">BasicAuth</a></h3>
  1483. <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>
  1484. <p>
  1485. BasicAuth returns the username and password provided in the request's
  1486. Authorization header, if the request uses HTTP Basic Authentication.
  1487. See RFC 2617, Section 2.
  1488. </p>
  1489. <h3 id="Request.Cookie">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=9041:9095#L248">Cookie</a></h3>
  1490. <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>
  1491. <p>
  1492. Cookie returns the named cookie provided in the request or
  1493. ErrNoCookie if not found.
  1494. </p>
  1495. <h3 id="Request.Cookies">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=8727:8764#L239">Cookies</a></h3>
  1496. <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>
  1497. <p>
  1498. Cookies parses and returns the HTTP cookies sent with the request.
  1499. </p>
  1500. <h3 id="Request.FormFile">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=29076:29161#L960">FormFile</a></h3>
  1501. <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>
  1502. <p>
  1503. FormFile returns the first file for the provided form key.
  1504. FormFile calls ParseMultipartForm and ParseForm if necessary.
  1505. </p>
  1506. <h3 id="Request.FormValue">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=28248:28294#L933">FormValue</a></h3>
  1507. <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>
  1508. <p>
  1509. FormValue returns the first value for the named component of the query.
  1510. POST and PUT body parameters take precedence over URL query string values.
  1511. FormValue calls ParseMultipartForm and ParseForm if necessary and ignores
  1512. any errors returned by these functions.
  1513. If key is not present, FormValue returns the empty string.
  1514. To access multiple values of the same key, call ParseForm and
  1515. then inspect Request.Form directly.
  1516. </p>
  1517. <h3 id="Request.MultipartReader">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=10760:10822#L292">MultipartReader</a></h3>
  1518. <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>
  1519. <p>
  1520. MultipartReader returns a MIME multipart reader if this is a
  1521. multipart/form-data POST request, else returns nil and an error.
  1522. Use this function instead of ParseMultipartForm to
  1523. process the request body as a stream.
  1524. </p>
  1525. <h3 id="Request.ParseForm">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=26212:26247#L854">ParseForm</a></h3>
  1526. <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>
  1527. <p>
  1528. ParseForm parses the raw query from the URL and updates r.Form.
  1529. </p>
  1530. <p>
  1531. For POST or PUT requests, it also parses the request body as a form and
  1532. put the results into both r.PostForm and r.Form.
  1533. POST and PUT body parameters take precedence over URL query string values
  1534. in r.Form.
  1535. </p>
  1536. <p>
  1537. If the request Body's size has not already been limited by MaxBytesReader,
  1538. the size is capped at 10MB.
  1539. </p>
  1540. <p>
  1541. ParseMultipartForm calls ParseForm automatically.
  1542. It is idempotent.
  1543. </p>
  1544. <h3 id="Request.ParseMultipartForm">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=27267:27326#L895">ParseMultipartForm</a></h3>
  1545. <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>
  1546. <p>
  1547. ParseMultipartForm parses a request body as multipart/form-data.
  1548. The whole request body is parsed and up to a total of maxMemory bytes of
  1549. its file parts are stored in memory, with the remainder stored on
  1550. disk in temporary files.
  1551. ParseMultipartForm calls ParseForm if necessary.
  1552. After one call to ParseMultipartForm, subsequent calls have no effect.
  1553. </p>
  1554. <h3 id="Request.PostFormValue">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=28755:28805#L948">PostFormValue</a></h3>
  1555. <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>
  1556. <p>
  1557. PostFormValue returns the first value for the named component of the POST
  1558. or PUT request body. URL query parameters are ignored.
  1559. PostFormValue calls ParseMultipartForm and ParseForm if necessary and ignores
  1560. any errors returned by these functions.
  1561. If key is not present, PostFormValue returns the empty string.
  1562. </p>
  1563. <h3 id="Request.ProtoAtLeast">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=8370:8423#L228">ProtoAtLeast</a></h3>
  1564. <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>
  1565. <p>
  1566. ProtoAtLeast reports whether the HTTP protocol used
  1567. in the request is at least major.minor.
  1568. </p>
  1569. <h3 id="Request.Referer">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=10131:10165#L276">Referer</a></h3>
  1570. <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>
  1571. <p>
  1572. Referer returns the referring URL, if sent in the request.
  1573. </p>
  1574. <p>
  1575. Referer is misspelled as in the request itself, a mistake from the
  1576. earliest days of HTTP. This value can also be fetched from the
  1577. Header map as Header["Referer"]; the benefit of making it available
  1578. as a method is that the compiler can diagnose programs that use the
  1579. alternate (correct English) spelling req.Referrer() but cannot
  1580. diagnose programs that use Header["Referrer"].
  1581. </p>
  1582. <h3 id="Request.SetBasicAuth">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=19455:19512#L604">SetBasicAuth</a></h3>
  1583. <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>
  1584. <p>
  1585. SetBasicAuth sets the request's Authorization header to use HTTP
  1586. Basic Authentication with the provided username and password.
  1587. </p>
  1588. <p>
  1589. With HTTP Basic Authentication the provided username and password
  1590. are not encrypted.
  1591. </p>
  1592. <h3 id="Request.UserAgent">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=8580:8616#L234">UserAgent</a></h3>
  1593. <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>
  1594. <p>
  1595. UserAgent returns the client's User-Agent, if sent in the request.
  1596. </p>
  1597. <h3 id="Request.Write">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=12411:12453#L346">Write</a></h3>
  1598. <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>
  1599. <p>
  1600. Write writes an HTTP/1.1 request, which is the header and body, in wire format.
  1601. This method consults the following fields of the request:
  1602. </p>
  1603. <pre>Host
  1604. URL
  1605. Method (defaults to "GET")
  1606. Header
  1607. ContentLength
  1608. TransferEncoding
  1609. Body
  1610. </pre>
  1611. <p>
  1612. If Body is present, Content-Length is &lt;= 0 and TransferEncoding
  1613. hasn't been set to "identity", Write adds "Transfer-Encoding:
  1614. chunked" to the header. Body is closed after it is sent.
  1615. </p>
  1616. <h3 id="Request.WriteProxy">func (*Request) <a href="https://golang.org/src/net/http/request.go?s=12846:12893#L356">WriteProxy</a></h3>
  1617. <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>
  1618. <p>
  1619. WriteProxy is like Write but writes the request in the form
  1620. expected by an HTTP proxy. In particular, WriteProxy writes the
  1621. initial Request-URI line of the request with an absolute URI, per
  1622. section 5.1.2 of RFC 2616, including the scheme and host.
  1623. In either case, WriteProxy also writes a Host header, using
  1624. either r.Host or r.URL.Host.
  1625. </p>
  1626. <h2 id="Response">type <a href="https://golang.org/src/net/http/response.go?s=512:2849#L19">Response</a></h2>
  1627. <pre>type Response struct {
  1628. Status <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// e.g. "200 OK"</span>
  1629. StatusCode <a href="https://golang.org/pkg/builtin/#int">int</a> <span class="comment">// e.g. 200</span>
  1630. Proto <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// e.g. "HTTP/1.0"</span>
  1631. ProtoMajor <a href="https://golang.org/pkg/builtin/#int">int</a> <span class="comment">// e.g. 1</span>
  1632. ProtoMinor <a href="https://golang.org/pkg/builtin/#int">int</a> <span class="comment">// e.g. 0</span>
  1633. <span class="comment">// Header maps header keys to values. If the response had multiple</span>
  1634. <span class="comment">// headers with the same key, they may be concatenated, with comma</span>
  1635. <span class="comment">// delimiters. (Section 4.2 of RFC 2616 requires that multiple headers</span>
  1636. <span class="comment">// be semantically equivalent to a comma-delimited sequence.) Values</span>
  1637. <span class="comment">// duplicated by other fields in this struct (e.g., ContentLength) are</span>
  1638. <span class="comment">// omitted from Header.</span>
  1639. <span class="comment">//</span>
  1640. <span class="comment">// Keys in the map are canonicalized (see CanonicalHeaderKey).</span>
  1641. Header <a href="https://golang.org/pkg/net/http/#Header">Header</a>
  1642. <span class="comment">// Body represents the response body.</span>
  1643. <span class="comment">//</span>
  1644. <span class="comment">// The http Client and Transport guarantee that Body is always</span>
  1645. <span class="comment">// non-nil, even on responses without a body or responses with</span>
  1646. <span class="comment">// a zero-length body. It is the caller's responsibility to</span>
  1647. <span class="comment">// close Body. The default HTTP client's Transport does not</span>
  1648. <span class="comment">// attempt to reuse HTTP/1.0 or HTTP/1.1 TCP connections</span>
  1649. <span class="comment">// ("keep-alive") unless the Body is read to completion and is</span>
  1650. <span class="comment">// closed.</span>
  1651. <span class="comment">//</span>
  1652. <span class="comment">// The Body is automatically dechunked if the server replied</span>
  1653. <span class="comment">// with a "chunked" Transfer-Encoding.</span>
  1654. Body <a href="https://golang.org/pkg/io/">io</a>.<a href="https://golang.org/pkg/io/#ReadCloser">ReadCloser</a>
  1655. <span class="comment">// ContentLength records the length of the associated content. The</span>
  1656. <span class="comment">// value -1 indicates that the length is unknown. Unless Request.Method</span>
  1657. <span class="comment">// is "HEAD", values &gt;= 0 indicate that the given number of bytes may</span>
  1658. <span class="comment">// be read from Body.</span>
  1659. ContentLength <a href="https://golang.org/pkg/builtin/#int64">int64</a>
  1660. <span class="comment">// Contains transfer encodings from outer-most to inner-most. Value is</span>
  1661. <span class="comment">// nil, means that "identity" encoding is used.</span>
  1662. TransferEncoding []<a href="https://golang.org/pkg/builtin/#string">string</a>
  1663. <span class="comment">// Close records whether the header directed that the connection be</span>
  1664. <span class="comment">// closed after reading Body. The value is advice for clients: neither</span>
  1665. <span class="comment">// ReadResponse nor Response.Write ever closes a connection.</span>
  1666. Close <a href="https://golang.org/pkg/builtin/#bool">bool</a>
  1667. <span class="comment">// Trailer maps trailer keys to values, in the same</span>
  1668. <span class="comment">// format as the header.</span>
  1669. Trailer <a href="https://golang.org/pkg/net/http/#Header">Header</a>
  1670. <span class="comment">// The Request that was sent to obtain this Response.</span>
  1671. <span class="comment">// Request's Body is nil (having already been consumed).</span>
  1672. <span class="comment">// This is only populated for Client requests.</span>
  1673. Request *<a href="https://golang.org/pkg/net/http/#Request">Request</a>
  1674. <span class="comment">// TLS contains information about the TLS connection on which the</span>
  1675. <span class="comment">// response was received. It is nil for unencrypted responses.</span>
  1676. <span class="comment">// The pointer is shared between responses and should not be</span>
  1677. <span class="comment">// modified.</span>
  1678. TLS *<a href="https://golang.org/pkg/crypto/tls/">tls</a>.<a href="https://golang.org/pkg/crypto/tls/#ConnectionState">ConnectionState</a>
  1679. }</pre>
  1680. <p>
  1681. Response represents the response from an HTTP request.
  1682. </p>
  1683. <h3 id="Get">func <a href="https://golang.org/src/net/http/client.go?s=9198:9246#L270">Get</a></h3>
  1684. <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>
  1685. <p>
  1686. Get issues a GET to the specified URL. If the response is one of
  1687. the following redirect codes, Get follows the redirect, up to a
  1688. maximum of 10 redirects:
  1689. </p>
  1690. <pre>301 (Moved Permanently)
  1691. 302 (Found)
  1692. 303 (See Other)
  1693. 307 (Temporary Redirect)
  1694. </pre>
  1695. <p>
  1696. An error is returned if there were too many redirects or if there
  1697. was an HTTP protocol error. A non-2xx response doesn't cause an
  1698. error.
  1699. </p>
  1700. <p>
  1701. When err is nil, resp always contains a non-nil resp.Body.
  1702. Caller should close resp.Body when done reading from it.
  1703. </p>
  1704. <p>
  1705. Get is a wrapper around DefaultClient.Get.
  1706. </p>
  1707. <p>
  1708. To make a request with custom headers, use NewRequest and
  1709. DefaultClient.Do.
  1710. </p>
  1711. <div id="example_Get" class="toggle">
  1712. <div class="collapsed">
  1713. <p class="exampleHeading toggleButton">▹ <span class="text">Example</span></p>
  1714. </div>
  1715. <div class="expanded">
  1716. <p class="exampleHeading toggleButton">▾ <span class="text">Example</span></p>
  1717. <div class="play">
  1718. <div class="input"><textarea class="code">package main
  1719. import (
  1720. "fmt"
  1721. "io/ioutil"
  1722. "log"
  1723. "net/http"
  1724. )
  1725. func main() {
  1726. res, err := http.Get("http://www.google.com/robots.txt")
  1727. if err != nil {
  1728. log.Fatal(err)
  1729. }
  1730. robots, err := ioutil.ReadAll(res.Body)
  1731. res.Body.Close()
  1732. if err != nil {
  1733. log.Fatal(err)
  1734. }
  1735. fmt.Printf("%s", robots)
  1736. }
  1737. </textarea></div>
  1738. <div class="output"><pre></pre></div>
  1739. <div class="buttons">
  1740. <a class="run" title="Run this code [shift-enter]">Run</a>
  1741. <a class="fmt" title="Format this code">Format</a>
  1742. </div>
  1743. </div>
  1744. </div>
  1745. </div>
  1746. <h3 id="Head">func <a href="https://golang.org/src/net/http/client.go?s=15901:15950#L500">Head</a></h3>
  1747. <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>
  1748. <p>
  1749. Head issues a HEAD to the specified URL. If the response is one of
  1750. the following redirect codes, Head follows the redirect, up to a
  1751. maximum of 10 redirects:
  1752. </p>
  1753. <pre>301 (Moved Permanently)
  1754. 302 (Found)
  1755. 303 (See Other)
  1756. 307 (Temporary Redirect)
  1757. </pre>
  1758. <p>
  1759. Head is a wrapper around DefaultClient.Head
  1760. </p>
  1761. <h3 id="Post">func <a href="https://golang.org/src/net/http/client.go?s=13816:13898#L443">Post</a></h3>
  1762. <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>
  1763. <p>
  1764. Post issues a POST to the specified URL.
  1765. </p>
  1766. <p>
  1767. Caller should close resp.Body when done reading from it.
  1768. </p>
  1769. <p>
  1770. If the provided body is an io.Closer, it is closed after the
  1771. request.
  1772. </p>
  1773. <p>
  1774. Post is a wrapper around DefaultClient.Post.
  1775. </p>
  1776. <p>
  1777. To set custom headers, use NewRequest and DefaultClient.Do.
  1778. </p>
  1779. <h3 id="PostForm">func <a href="https://golang.org/src/net/http/client.go?s=14909:14979#L474">PostForm</a></h3>
  1780. <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>
  1781. <p>
  1782. PostForm issues a POST to the specified URL, with data's keys and
  1783. values URL-encoded as the request body.
  1784. </p>
  1785. <p>
  1786. The Content-Type header is set to application/x-www-form-urlencoded.
  1787. To set other headers, use NewRequest and DefaultClient.Do.
  1788. </p>
  1789. <p>
  1790. When err is nil, resp always contains a non-nil resp.Body.
  1791. Caller should close resp.Body when done reading from it.
  1792. </p>
  1793. <p>
  1794. PostForm is a wrapper around DefaultClient.PostForm.
  1795. </p>
  1796. <h3 id="ReadResponse">func <a href="https://golang.org/src/net/http/response.go?s=3992:4059#L111">ReadResponse</a></h3>
  1797. <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>
  1798. <p>
  1799. ReadResponse reads and returns an HTTP response from r.
  1800. The req parameter optionally specifies the Request that corresponds
  1801. to this Response. If nil, a GET request is assumed.
  1802. Clients must call resp.Body.Close when finished reading resp.Body.
  1803. After that call, clients can inspect resp.Trailer to find key/value
  1804. pairs included in the response trailer.
  1805. </p>
  1806. <h3 id="Response.Cookies">func (*Response) <a href="https://golang.org/src/net/http/response.go?s=2924:2962#L82">Cookies</a></h3>
  1807. <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>
  1808. <p>
  1809. Cookies parses and returns the cookies set in the Set-Cookie headers.
  1810. </p>
  1811. <h3 id="Response.Location">func (*Response) <a href="https://golang.org/src/net/http/response.go?s=3387:3434#L94">Location</a></h3>
  1812. <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>
  1813. <p>
  1814. Location returns the URL of the response's "Location" header,
  1815. if present. Relative redirects are resolved relative to
  1816. the Response's Request. ErrNoLocation is returned if no
  1817. Location header is present.
  1818. </p>
  1819. <h3 id="Response.ProtoAtLeast">func (*Response) <a href="https://golang.org/src/net/http/response.go?s=5570:5624#L179">ProtoAtLeast</a></h3>
  1820. <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>
  1821. <p>
  1822. ProtoAtLeast reports whether the HTTP protocol used
  1823. in the response is at least major.minor.
  1824. </p>
  1825. <h3 id="Response.Write">func (*Response) <a href="https://golang.org/src/net/http/response.go?s=6162:6205#L200">Write</a></h3>
  1826. <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>
  1827. <p>
  1828. Write writes r to w in the HTTP/1.n server response format,
  1829. including the status line, headers, body, and optional trailer.
  1830. </p>
  1831. <p>
  1832. This method consults the following fields of the response r:
  1833. </p>
  1834. <pre>StatusCode
  1835. ProtoMajor
  1836. ProtoMinor
  1837. Request.Method
  1838. TransferEncoding
  1839. Trailer
  1840. Body
  1841. ContentLength
  1842. Header, values for non-canonical keys will have unpredictable behavior
  1843. </pre>
  1844. <p>
  1845. The Response Body is closed after it is sent.
  1846. </p>
  1847. <h2 id="ResponseWriter">type <a href="https://golang.org/src/net/http/server.go?s=1517:2599#L48">ResponseWriter</a></h2>
  1848. <pre>type ResponseWriter interface {
  1849. <span class="comment">// Header returns the header map that will be sent by</span>
  1850. <span class="comment">// WriteHeader. Changing the header after a call to</span>
  1851. <span class="comment">// WriteHeader (or Write) has no effect unless the modified</span>
  1852. <span class="comment">// headers were declared as trailers by setting the</span>
  1853. <span class="comment">// "Trailer" header before the call to WriteHeader (see example).</span>
  1854. <span class="comment">// To suppress implicit response headers, set their value to nil.</span>
  1855. Header() <a href="https://golang.org/pkg/net/http/#Header">Header</a>
  1856. <span class="comment">// Write writes the data to the connection as part of an HTTP reply.</span>
  1857. <span class="comment">// If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK)</span>
  1858. <span class="comment">// before writing the data. If the Header does not contain a</span>
  1859. <span class="comment">// Content-Type line, Write adds a Content-Type set to the result of passing</span>
  1860. <span class="comment">// the initial 512 bytes of written data to DetectContentType.</span>
  1861. 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>)
  1862. <span class="comment">// WriteHeader sends an HTTP response header with status code.</span>
  1863. <span class="comment">// If WriteHeader is not called explicitly, the first call to Write</span>
  1864. <span class="comment">// will trigger an implicit WriteHeader(http.StatusOK).</span>
  1865. <span class="comment">// Thus explicit calls to WriteHeader are mainly used to</span>
  1866. <span class="comment">// send error codes.</span>
  1867. WriteHeader(<a href="https://golang.org/pkg/builtin/#int">int</a>)
  1868. }</pre>
  1869. <p>
  1870. A ResponseWriter interface is used by an HTTP handler to
  1871. construct an HTTP response.
  1872. </p>
  1873. <div id="example_ResponseWriter_trailers" class="toggle">
  1874. <div class="collapsed">
  1875. <p class="exampleHeading toggleButton">▹ <span class="text">Example (Trailers)</span></p>
  1876. </div>
  1877. <div class="expanded">
  1878. <p class="exampleHeading toggleButton">▾ <span class="text">Example (Trailers)</span></p>
  1879. <p>HTTP Trailers are a set of key/value pairs like headers that come
  1880. after the HTTP response, instead of before.
  1881. </p>
  1882. <div class="play">
  1883. <div class="input"><textarea class="code">package main
  1884. import (
  1885. "io"
  1886. "net/http"
  1887. )
  1888. func main() {
  1889. mux := http.NewServeMux()
  1890. mux.HandleFunc("/sendstrailers", func(w http.ResponseWriter, req *http.Request) {
  1891. // Before any call to WriteHeader or Write, declare
  1892. // the trailers you will set during the HTTP
  1893. // response. These three headers are actually sent in
  1894. // the trailer.
  1895. w.Header().Set("Trailer", "AtEnd1, AtEnd2")
  1896. w.Header().Add("Trailer", "AtEnd3")
  1897. w.Header().Set("Content-Type", "text/plain; charset=utf-8") // normal header
  1898. w.WriteHeader(http.StatusOK)
  1899. w.Header().Set("AtEnd1", "value 1")
  1900. io.WriteString(w, "This HTTP response has both headers before this text and trailers at the end.\n")
  1901. w.Header().Set("AtEnd2", "value 2")
  1902. w.Header().Set("AtEnd3", "value 3") // These will appear as trailers.
  1903. })
  1904. }
  1905. </textarea></div>
  1906. <div class="output"><pre></pre></div>
  1907. <div class="buttons">
  1908. <a class="run" title="Run this code [shift-enter]">Run</a>
  1909. <a class="fmt" title="Format this code">Format</a>
  1910. </div>
  1911. </div>
  1912. </div>
  1913. </div>
  1914. <h2 id="RoundTripper">type <a href="https://golang.org/src/net/http/client.go?s=2750:3517#L73">RoundTripper</a></h2>
  1915. <pre>type RoundTripper interface {
  1916. <span class="comment">// RoundTrip executes a single HTTP transaction, returning</span>
  1917. <span class="comment">// the Response for the request req. RoundTrip should not</span>
  1918. <span class="comment">// attempt to interpret the response. In particular,</span>
  1919. <span class="comment">// RoundTrip must return err == nil if it obtained a response,</span>
  1920. <span class="comment">// regardless of the response's HTTP status code. A non-nil</span>
  1921. <span class="comment">// err should be reserved for failure to obtain a response.</span>
  1922. <span class="comment">// Similarly, RoundTrip should not attempt to handle</span>
  1923. <span class="comment">// higher-level protocol details such as redirects,</span>
  1924. <span class="comment">// authentication, or cookies.</span>
  1925. <span class="comment">//</span>
  1926. <span class="comment">// RoundTrip should not modify the request, except for</span>
  1927. <span class="comment">// consuming and closing the Body, including on errors. The</span>
  1928. <span class="comment">// request's URL and Header fields are guaranteed to be</span>
  1929. <span class="comment">// initialized.</span>
  1930. 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>)
  1931. }</pre>
  1932. <p>
  1933. RoundTripper is an interface representing the ability to execute a
  1934. single HTTP transaction, obtaining the Response for a given Request.
  1935. </p>
  1936. <p>
  1937. A RoundTripper must be safe for concurrent use by multiple
  1938. goroutines.
  1939. </p>
  1940. <pre>var <span id="DefaultTransport">DefaultTransport</span> <a href="https://golang.org/pkg/net/http/#RoundTripper">RoundTripper</a> = &amp;<a href="https://golang.org/pkg/net/http/#Transport">Transport</a>{
  1941. <a href="https://golang.org/pkg/net/http/#Proxy">Proxy</a>: <a href="https://golang.org/pkg/net/http/#ProxyFromEnvironment">ProxyFromEnvironment</a>,
  1942. <a href="https://golang.org/pkg/net/http/#Dial">Dial</a>: (&amp;<a href="https://golang.org/pkg/net/">net</a>.<a href="https://golang.org/pkg/net/#Dialer">Dialer</a>{
  1943. <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>,
  1944. <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>,
  1945. }).<a href="https://golang.org/pkg/net/http/#Dial">Dial</a>,
  1946. <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>,
  1947. }</pre>
  1948. <p>
  1949. DefaultTransport is the default implementation of Transport and is
  1950. used by DefaultClient. It establishes network connections as needed
  1951. and caches them for reuse by subsequent calls. It uses HTTP proxies
  1952. as directed by the $HTTP_PROXY and $NO_PROXY (or $http_proxy and
  1953. $no_proxy) environment variables.
  1954. </p>
  1955. <h3 id="NewFileTransport">func <a href="https://golang.org/src/net/http/filetransport.go?s=827:876#L20">NewFileTransport</a></h3>
  1956. <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>
  1957. <p>
  1958. NewFileTransport returns a new RoundTripper, serving the provided
  1959. FileSystem. The returned RoundTripper ignores the URL host in its
  1960. incoming requests, as well as most other properties of the
  1961. request.
  1962. </p>
  1963. <p>
  1964. The typical use case for NewFileTransport is to register the "file"
  1965. protocol with a Transport, as in:
  1966. </p>
  1967. <pre>t := &amp;http.Transport{}
  1968. t.RegisterProtocol("file", http.NewFileTransport(http.Dir("/")))
  1969. c := &amp;http.Client{Transport: t}
  1970. res, err := c.Get("file:///etc/passwd")
  1971. ...
  1972. </pre>
  1973. <h2 id="ServeMux">type <a href="https://golang.org/src/net/http/server.go?s=46684:46809#L1569">ServeMux</a></h2>
  1974. <pre>type ServeMux struct {
  1975. <span class="comment">// contains filtered or unexported fields</span>
  1976. }</pre>
  1977. <p>
  1978. ServeMux is an HTTP request multiplexer.
  1979. It matches the URL of each incoming request against a list of registered
  1980. patterns and calls the handler for the pattern that
  1981. most closely matches the URL.
  1982. </p>
  1983. <p>
  1984. Patterns name fixed, rooted paths, like "/favicon.ico",
  1985. or rooted subtrees, like "/images/" (note the trailing slash).
  1986. Longer patterns take precedence over shorter ones, so that
  1987. if there are handlers registered for both "/images/"
  1988. and "/images/thumbnails/", the latter handler will be
  1989. called for paths beginning "/images/thumbnails/" and the
  1990. former will receive requests for any other paths in the
  1991. "/images/" subtree.
  1992. </p>
  1993. <p>
  1994. Note that since a pattern ending in a slash names a rooted subtree,
  1995. the pattern "/" matches all paths not matched by other registered
  1996. patterns, not just the URL with Path == "/".
  1997. </p>
  1998. <p>
  1999. Patterns may optionally begin with a host name, restricting matches to
  2000. URLs on that host only. Host-specific patterns take precedence over
  2001. general patterns, so that a handler might register for the two patterns
  2002. "/codesearch" and "codesearch.google.com/" without also taking over
  2003. requests for "<a href="http://www.google.com/">http://www.google.com/</a>".
  2004. </p>
  2005. <p>
  2006. ServeMux also takes care of sanitizing the URL request path,
  2007. redirecting any request containing . or .. elements to an
  2008. equivalent .- and ..-free URL.
  2009. </p>
  2010. <h3 id="NewServeMux">func <a href="https://golang.org/src/net/http/server.go?s=46940:46968#L1582">NewServeMux</a></h3>
  2011. <pre>func NewServeMux() *<a href="https://golang.org/pkg/net/http/#ServeMux">ServeMux</a></pre>
  2012. <p>
  2013. NewServeMux allocates and returns a new ServeMux.
  2014. </p>
  2015. <h3 id="ServeMux.Handle">func (*ServeMux) <a href="https://golang.org/src/net/http/server.go?s=49985:50045#L1694">Handle</a></h3>
  2016. <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>
  2017. <p>
  2018. Handle registers the handler for the given pattern.
  2019. If a handler already exists for pattern, Handle panics.
  2020. </p>
  2021. <div id="example_ServeMux_Handle" class="toggle">
  2022. <div class="collapsed">
  2023. <p class="exampleHeading toggleButton">▹ <span class="text">Example</span></p>
  2024. </div>
  2025. <div class="expanded">
  2026. <p class="exampleHeading toggleButton">▾ <span class="text">Example</span></p>
  2027. <p>Code:</p>
  2028. <pre class="code"> mux := http.NewServeMux()
  2029. mux.Handle("/api/", apiHandler{})
  2030. mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
  2031. <span class="comment">// The "/" pattern matches everything, so we need to check</span>
  2032. <span class="comment">// that we're at the root here.</span>
  2033. if req.URL.Path != "/" {
  2034. http.NotFound(w, req)
  2035. return
  2036. }
  2037. fmt.Fprintf(w, "Welcome to the home page!")
  2038. })
  2039. </pre>
  2040. </div>
  2041. </div>
  2042. <h3 id="ServeMux.HandleFunc">func (*ServeMux) <a href="https://golang.org/src/net/http/server.go?s=51148:51235#L1733">HandleFunc</a></h3>
  2043. <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>
  2044. <p>
  2045. HandleFunc registers the handler function for the given pattern.
  2046. </p>
  2047. <h3 id="ServeMux.Handler">func (*ServeMux) <a href="https://golang.org/src/net/http/server.go?s=48689:48757#L1646">Handler</a></h3>
  2048. <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>
  2049. <p>
  2050. Handler returns the handler to use for the given request,
  2051. consulting r.Method, r.Host, and r.URL.Path. It always returns
  2052. a non-nil handler. If the path is not in its canonical form, the
  2053. handler will be an internally-generated handler that redirects
  2054. to the canonical path.
  2055. </p>
  2056. <p>
  2057. Handler also returns the registered pattern that matches the
  2058. request or, in the case of internally-generated redirects,
  2059. the pattern that will match after following the redirect.
  2060. </p>
  2061. <p>
  2062. If there is no registered handler that applies to the request,
  2063. Handler returns a “page not found” handler and an empty pattern.
  2064. </p>
  2065. <h3 id="ServeMux.ServeHTTP">func (*ServeMux) <a href="https://golang.org/src/net/http/server.go?s=49617:49677#L1680">ServeHTTP</a></h3>
  2066. <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>
  2067. <p>
  2068. ServeHTTP dispatches the request to the handler whose
  2069. pattern most closely matches the request URL.
  2070. </p>
  2071. <h2 id="Server">type <a href="https://golang.org/src/net/http/server.go?s=52296:53789#L1760">Server</a></h2>
  2072. <pre>type Server struct {
  2073. Addr <a href="https://golang.org/pkg/builtin/#string">string</a> <span class="comment">// TCP address to listen on, ":http" if empty</span>
  2074. Handler <a href="https://golang.org/pkg/net/http/#Handler">Handler</a> <span class="comment">// handler to invoke, http.DefaultServeMux if nil</span>
  2075. 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>
  2076. 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>
  2077. MaxHeaderBytes <a href="https://golang.org/pkg/builtin/#int">int</a> <span class="comment">// maximum size of request headers, DefaultMaxHeaderBytes if 0</span>
  2078. 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>
  2079. <span class="comment">// TLSNextProto optionally specifies a function to take over</span>
  2080. <span class="comment">// ownership of the provided TLS connection when an NPN</span>
  2081. <span class="comment">// protocol upgrade has occurred. The map key is the protocol</span>
  2082. <span class="comment">// name negotiated. The Handler argument should be used to</span>
  2083. <span class="comment">// handle HTTP requests and will initialize the Request's TLS</span>
  2084. <span class="comment">// and RemoteAddr if not already set. The connection is</span>
  2085. <span class="comment">// automatically closed when the function returns.</span>
  2086. 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>)
  2087. <span class="comment">// ConnState specifies an optional callback function that is</span>
  2088. <span class="comment">// called when a client connection changes state. See the</span>
  2089. <span class="comment">// ConnState type and associated constants for details.</span>
  2090. 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>)
  2091. <span class="comment">// ErrorLog specifies an optional logger for errors accepting</span>
  2092. <span class="comment">// connections and unexpected behavior from handlers.</span>
  2093. <span class="comment">// If nil, logging goes to os.Stderr via the log package's</span>
  2094. <span class="comment">// standard logger.</span>
  2095. ErrorLog *<a href="https://golang.org/pkg/log/">log</a>.<a href="https://golang.org/pkg/log/#Logger">Logger</a>
  2096. <span class="comment">// contains filtered or unexported fields</span>
  2097. }</pre>
  2098. <p>
  2099. A Server defines parameters for running an HTTP server.
  2100. The zero value for Server is a valid configuration.
  2101. </p>
  2102. <h3 id="Server.ListenAndServe">func (*Server) <a href="https://golang.org/src/net/http/server.go?s=55886:55927#L1858">ListenAndServe</a></h3>
  2103. <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>
  2104. <p>
  2105. ListenAndServe listens on the TCP network address srv.Addr and then
  2106. calls Serve to handle requests on incoming connections. If
  2107. srv.Addr is blank, ":http" is used.
  2108. </p>
  2109. <h3 id="Server.ListenAndServeTLS">func (*Server) <a href="https://golang.org/src/net/http/server.go?s=60146:60214#L2003">ListenAndServeTLS</a></h3>
  2110. <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>
  2111. <p>
  2112. ListenAndServeTLS listens on the TCP network address srv.Addr and
  2113. then calls Serve to handle requests on incoming TLS connections.
  2114. </p>
  2115. <p>
  2116. Filenames containing a certificate and matching private key for the
  2117. server must be provided if the Server's TLSConfig.Certificates is
  2118. not populated. If the certificate is signed by a certificate
  2119. authority, the certFile should be the concatenation of the server's
  2120. certificate, any intermediates, and the CA's certificate.
  2121. </p>
  2122. <p>
  2123. If srv.Addr is blank, ":https" is used.
  2124. </p>
  2125. <h3 id="Server.Serve">func (*Server) <a href="https://golang.org/src/net/http/server.go?s=56308:56354#L1873">Serve</a></h3>
  2126. <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>
  2127. <p>
  2128. Serve accepts incoming connections on the Listener l, creating a
  2129. new service goroutine for each. The service goroutines read requests and
  2130. then call srv.Handler to reply to them.
  2131. </p>
  2132. <h3 id="Server.SetKeepAlivesEnabled">func (*Server) <a href="https://golang.org/src/net/http/server.go?s=57329:57376#L1912">SetKeepAlivesEnabled</a></h3>
  2133. <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>
  2134. <p>
  2135. SetKeepAlivesEnabled controls whether HTTP keep-alives are enabled.
  2136. By default, keep-alives are always enabled. Only very
  2137. resource-constrained environments or servers in the process of
  2138. shutting down should disable them.
  2139. </p>
  2140. <h2 id="Transport">type <a href="https://golang.org/src/net/http/transport.go?s=1324:4038#L39">Transport</a></h2>
  2141. <pre>type Transport struct {
  2142. <span class="comment">// Proxy specifies a function to return a proxy for a given</span>
  2143. <span class="comment">// Request. If the function returns a non-nil error, the</span>
  2144. <span class="comment">// request is aborted with the provided error.</span>
  2145. <span class="comment">// If Proxy is nil or returns a nil *URL, no proxy is used.</span>
  2146. 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>)
  2147. <span class="comment">// Dial specifies the dial function for creating unencrypted</span>
  2148. <span class="comment">// TCP connections.</span>
  2149. <span class="comment">// If Dial is nil, net.Dial is used.</span>
  2150. 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>)
  2151. <span class="comment">// DialTLS specifies an optional dial function for creating</span>
  2152. <span class="comment">// TLS connections for non-proxied HTTPS requests.</span>
  2153. <span class="comment">//</span>
  2154. <span class="comment">// If DialTLS is nil, Dial and TLSClientConfig are used.</span>
  2155. <span class="comment">//</span>
  2156. <span class="comment">// If DialTLS is set, the Dial hook is not used for HTTPS</span>
  2157. <span class="comment">// requests and the TLSClientConfig and TLSHandshakeTimeout</span>
  2158. <span class="comment">// are ignored. The returned net.Conn is assumed to already be</span>
  2159. <span class="comment">// past the TLS handshake.</span>
  2160. 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>)
  2161. <span class="comment">// TLSClientConfig specifies the TLS configuration to use with</span>
  2162. <span class="comment">// tls.Client. If nil, the default configuration is used.</span>
  2163. TLSClientConfig *<a href="https://golang.org/pkg/crypto/tls/">tls</a>.<a href="https://golang.org/pkg/crypto/tls/#Config">Config</a>
  2164. <span class="comment">// TLSHandshakeTimeout specifies the maximum amount of time waiting to</span>
  2165. <span class="comment">// wait for a TLS handshake. Zero means no timeout.</span>
  2166. TLSHandshakeTimeout <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Duration">Duration</a>
  2167. <span class="comment">// DisableKeepAlives, if true, prevents re-use of TCP connections</span>
  2168. <span class="comment">// between different HTTP requests.</span>
  2169. DisableKeepAlives <a href="https://golang.org/pkg/builtin/#bool">bool</a>
  2170. <span class="comment">// DisableCompression, if true, prevents the Transport from</span>
  2171. <span class="comment">// requesting compression with an "Accept-Encoding: gzip"</span>
  2172. <span class="comment">// request header when the Request contains no existing</span>
  2173. <span class="comment">// Accept-Encoding value. If the Transport requests gzip on</span>
  2174. <span class="comment">// its own and gets a gzipped response, it's transparently</span>
  2175. <span class="comment">// decoded in the Response.Body. However, if the user</span>
  2176. <span class="comment">// explicitly requested gzip it is not automatically</span>
  2177. <span class="comment">// uncompressed.</span>
  2178. DisableCompression <a href="https://golang.org/pkg/builtin/#bool">bool</a>
  2179. <span class="comment">// MaxIdleConnsPerHost, if non-zero, controls the maximum idle</span>
  2180. <span class="comment">// (keep-alive) to keep per-host. If zero,</span>
  2181. <span class="comment">// DefaultMaxIdleConnsPerHost is used.</span>
  2182. MaxIdleConnsPerHost <a href="https://golang.org/pkg/builtin/#int">int</a>
  2183. <span class="comment">// ResponseHeaderTimeout, if non-zero, specifies the amount of</span>
  2184. <span class="comment">// time to wait for a server's response headers after fully</span>
  2185. <span class="comment">// writing the request (including its body, if any). This</span>
  2186. <span class="comment">// time does not include the time to read the response body.</span>
  2187. ResponseHeaderTimeout <a href="https://golang.org/pkg/time/">time</a>.<a href="https://golang.org/pkg/time/#Duration">Duration</a>
  2188. <span class="comment">// contains filtered or unexported fields</span>
  2189. }</pre>
  2190. <p>
  2191. Transport is an implementation of RoundTripper that supports HTTP,
  2192. HTTPS, and HTTP proxies (for either HTTP or HTTPS with CONNECT).
  2193. Transport can also cache connections for future re-use.
  2194. </p>
  2195. <h3 id="Transport.CancelRequest">func (*Transport) <a href="https://golang.org/src/net/http/transport.go?s=8881:8928#L269">CancelRequest</a></h3>
  2196. <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>
  2197. <p>
  2198. CancelRequest cancels an in-flight request by closing its connection.
  2199. CancelRequest should only be called after RoundTrip has returned.
  2200. </p>
  2201. <h3 id="Transport.CloseIdleConnections">func (*Transport) <a href="https://golang.org/src/net/http/transport.go?s=8498:8540#L253">CloseIdleConnections</a></h3>
  2202. <pre>func (t *<a href="https://golang.org/pkg/net/http/#Transport">Transport</a>) CloseIdleConnections()</pre>
  2203. <p>
  2204. CloseIdleConnections closes any connections which were previously
  2205. connected from previous requests but are now sitting idle in
  2206. a "keep-alive" state. It does not interrupt any connections currently
  2207. in use.
  2208. </p>
  2209. <h3 id="Transport.RegisterProtocol">func (*Transport) <a href="https://golang.org/src/net/http/transport.go?s=7866:7934#L234">RegisterProtocol</a></h3>
  2210. <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>
  2211. <p>
  2212. RegisterProtocol registers a new protocol with scheme.
  2213. The Transport will pass requests using the given scheme to rt.
  2214. It is rt's responsibility to simulate HTTP request semantics.
  2215. </p>
  2216. <p>
  2217. RegisterProtocol can be used by other packages to provide
  2218. implementations of protocol schemes like "ftp" or "file".
  2219. </p>
  2220. <h3 id="Transport.RoundTrip">func (*Transport) <a href="https://golang.org/src/net/http/transport.go?s=6344:6415#L181">RoundTrip</a></h3>
  2221. <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>
  2222. <p>
  2223. RoundTrip implements the RoundTripper interface.
  2224. </p>
  2225. <p>
  2226. For higher-level HTTP client support (such as handling of cookies
  2227. and redirects), see Get, Post, and the Client type.
  2228. </p>
  2229. <h2 id="pkg-subdirectories">Subdirectories</h2>
  2230. <div class="pkg-dir">
  2231. <table>
  2232. <tbody><tr>
  2233. <th class="pkg-name">Name</th>
  2234. <th class="pkg-synopsis">Synopsis</th>
  2235. </tr>
  2236. <tr>
  2237. <td colspan="2"><a href="https://golang.org/pkg/net/">..</a></td>
  2238. </tr>
  2239. <tr>
  2240. <td class="pkg-name" style="padding-left: 0px;">
  2241. <a href="https://golang.org/pkg/net/http/cgi/">cgi</a>
  2242. </td>
  2243. <td class="pkg-synopsis">
  2244. Package cgi implements CGI (Common Gateway Interface) as specified in RFC 3875.
  2245. </td>
  2246. </tr>
  2247. <tr>
  2248. <td class="pkg-name" style="padding-left: 0px;">
  2249. <a href="https://golang.org/pkg/net/http/cookiejar/">cookiejar</a>
  2250. </td>
  2251. <td class="pkg-synopsis">
  2252. Package cookiejar implements an in-memory RFC 6265-compliant http.CookieJar.
  2253. </td>
  2254. </tr>
  2255. <tr>
  2256. <td class="pkg-name" style="padding-left: 0px;">
  2257. <a href="https://golang.org/pkg/net/http/fcgi/">fcgi</a>
  2258. </td>
  2259. <td class="pkg-synopsis">
  2260. Package fcgi implements the FastCGI protocol.
  2261. </td>
  2262. </tr>
  2263. <tr>
  2264. <td class="pkg-name" style="padding-left: 0px;">
  2265. <a href="https://golang.org/pkg/net/http/httptest/">httptest</a>
  2266. </td>
  2267. <td class="pkg-synopsis">
  2268. Package httptest provides utilities for HTTP testing.
  2269. </td>
  2270. </tr>
  2271. <tr>
  2272. <td class="pkg-name" style="padding-left: 0px;">
  2273. <a href="https://golang.org/pkg/net/http/httputil/">httputil</a>
  2274. </td>
  2275. <td class="pkg-synopsis">
  2276. Package httputil provides HTTP utility functions, complementing the more common ones in the net/http package.
  2277. </td>
  2278. </tr>
  2279. <tr>
  2280. <td class="pkg-name" style="padding-left: 0px;">
  2281. <a href="https://golang.org/pkg/net/http/pprof/">pprof</a>
  2282. </td>
  2283. <td class="pkg-synopsis">
  2284. Package pprof serves via its HTTP server runtime profiling data in the format expected by the pprof visualization tool.
  2285. </td>
  2286. </tr>
  2287. </tbody></table>
  2288. </div>
  2289. <div id="footer">
  2290. Build version go1.5.1.<br>
  2291. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  2292. the content of this page is licensed under the
  2293. Creative Commons Attribution 3.0 License,
  2294. and code is licensed under a <a href="https://golang.org/LICENSE">BSD license</a>.<br>
  2295. <a href="https://golang.org/doc/tos.html">Terms of Service</a> |
  2296. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  2297. </div>
  2298. </div><!-- .container -->
  2299. </div><!-- #page -->
  2300. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  2301. <script type="text/javascript" src="./http - The Go Programming Language_files/jquery.min.js"></script>
  2302. <script type="text/javascript" src="./http - The Go Programming Language_files/jquery.treeview.js"></script>
  2303. <script type="text/javascript" src="./http - The Go Programming Language_files/jquery.treeview.edit.js"></script>
  2304. <script type="text/javascript" src="./http - The Go Programming Language_files/playground.js"></script>
  2305. <script type="text/javascript" src="./http - The Go Programming Language_files/godocs.js"></script>
  2306. <script type="text/javascript">
  2307. (function() {
  2308. var ga = document.createElement("script"); ga.type = "text/javascript"; ga.async = true;
  2309. ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js";
  2310. var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(ga, s);
  2311. })();
  2312. </script>
  2313. </body></html>