You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1072 lines
33 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>textproto - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package textproto</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "net/textproto"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. </dl>
  58. </div>
  59. <!-- The package's Name is printed as title by the top-level template -->
  60. <div id="pkg-overview" class="toggleVisible">
  61. <div class="collapsed">
  62. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  63. </div>
  64. <div class="expanded">
  65. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  66. <p>
  67. Package textproto implements generic support for text-based request/response
  68. protocols in the style of HTTP, NNTP, and SMTP.
  69. </p>
  70. <p>
  71. The package provides:
  72. </p>
  73. <p>
  74. Error, which represents a numeric error response from
  75. a server.
  76. </p>
  77. <p>
  78. Pipeline, to manage pipelined requests and responses
  79. in a client.
  80. </p>
  81. <p>
  82. Reader, to read numeric response code lines,
  83. key: value headers, lines wrapped with leading spaces
  84. on continuation lines, and whole text blocks ending
  85. with a dot on a line by itself.
  86. </p>
  87. <p>
  88. Writer, to write dot-encoded text blocks.
  89. </p>
  90. <p>
  91. Conn, a convenient packaging of Reader, Writer, and Pipeline for use
  92. with a single network connection.
  93. </p>
  94. </div>
  95. </div>
  96. <div id="pkg-index" class="toggleVisible">
  97. <div class="collapsed">
  98. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  99. </div>
  100. <div class="expanded">
  101. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  102. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  103. <div id="manual-nav">
  104. <dl>
  105. <dd><a href="index.html#CanonicalMIMEHeaderKey">func CanonicalMIMEHeaderKey(s string) string</a></dd>
  106. <dd><a href="index.html#TrimBytes">func TrimBytes(b []byte) []byte</a></dd>
  107. <dd><a href="index.html#TrimString">func TrimString(s string) string</a></dd>
  108. <dd><a href="index.html#Conn">type Conn</a></dd>
  109. <dd>&nbsp; &nbsp; <a href="index.html#Dial">func Dial(network, addr string) (*Conn, error)</a></dd>
  110. <dd>&nbsp; &nbsp; <a href="index.html#NewConn">func NewConn(conn io.ReadWriteCloser) *Conn</a></dd>
  111. <dd>&nbsp; &nbsp; <a href="index.html#Conn.Close">func (c *Conn) Close() error</a></dd>
  112. <dd>&nbsp; &nbsp; <a href="index.html#Conn.Cmd">func (c *Conn) Cmd(format string, args ...interface{}) (id uint, err error)</a></dd>
  113. <dd><a href="index.html#Error">type Error</a></dd>
  114. <dd>&nbsp; &nbsp; <a href="index.html#Error.Error">func (e *Error) Error() string</a></dd>
  115. <dd><a href="index.html#MIMEHeader">type MIMEHeader</a></dd>
  116. <dd>&nbsp; &nbsp; <a href="index.html#MIMEHeader.Add">func (h MIMEHeader) Add(key, value string)</a></dd>
  117. <dd>&nbsp; &nbsp; <a href="index.html#MIMEHeader.Del">func (h MIMEHeader) Del(key string)</a></dd>
  118. <dd>&nbsp; &nbsp; <a href="index.html#MIMEHeader.Get">func (h MIMEHeader) Get(key string) string</a></dd>
  119. <dd>&nbsp; &nbsp; <a href="index.html#MIMEHeader.Set">func (h MIMEHeader) Set(key, value string)</a></dd>
  120. <dd><a href="index.html#Pipeline">type Pipeline</a></dd>
  121. <dd>&nbsp; &nbsp; <a href="index.html#Pipeline.EndRequest">func (p *Pipeline) EndRequest(id uint)</a></dd>
  122. <dd>&nbsp; &nbsp; <a href="index.html#Pipeline.EndResponse">func (p *Pipeline) EndResponse(id uint)</a></dd>
  123. <dd>&nbsp; &nbsp; <a href="index.html#Pipeline.Next">func (p *Pipeline) Next() uint</a></dd>
  124. <dd>&nbsp; &nbsp; <a href="index.html#Pipeline.StartRequest">func (p *Pipeline) StartRequest(id uint)</a></dd>
  125. <dd>&nbsp; &nbsp; <a href="index.html#Pipeline.StartResponse">func (p *Pipeline) StartResponse(id uint)</a></dd>
  126. <dd><a href="index.html#ProtocolError">type ProtocolError</a></dd>
  127. <dd>&nbsp; &nbsp; <a href="index.html#ProtocolError.Error">func (p ProtocolError) Error() string</a></dd>
  128. <dd><a href="index.html#Reader">type Reader</a></dd>
  129. <dd>&nbsp; &nbsp; <a href="index.html#NewReader">func NewReader(r *bufio.Reader) *Reader</a></dd>
  130. <dd>&nbsp; &nbsp; <a href="index.html#Reader.DotReader">func (r *Reader) DotReader() io.Reader</a></dd>
  131. <dd>&nbsp; &nbsp; <a href="index.html#Reader.ReadCodeLine">func (r *Reader) ReadCodeLine(expectCode int) (code int, message string, err error)</a></dd>
  132. <dd>&nbsp; &nbsp; <a href="index.html#Reader.ReadContinuedLine">func (r *Reader) ReadContinuedLine() (string, error)</a></dd>
  133. <dd>&nbsp; &nbsp; <a href="index.html#Reader.ReadContinuedLineBytes">func (r *Reader) ReadContinuedLineBytes() ([]byte, error)</a></dd>
  134. <dd>&nbsp; &nbsp; <a href="index.html#Reader.ReadDotBytes">func (r *Reader) ReadDotBytes() ([]byte, error)</a></dd>
  135. <dd>&nbsp; &nbsp; <a href="index.html#Reader.ReadDotLines">func (r *Reader) ReadDotLines() ([]string, error)</a></dd>
  136. <dd>&nbsp; &nbsp; <a href="index.html#Reader.ReadLine">func (r *Reader) ReadLine() (string, error)</a></dd>
  137. <dd>&nbsp; &nbsp; <a href="index.html#Reader.ReadLineBytes">func (r *Reader) ReadLineBytes() ([]byte, error)</a></dd>
  138. <dd>&nbsp; &nbsp; <a href="index.html#Reader.ReadMIMEHeader">func (r *Reader) ReadMIMEHeader() (MIMEHeader, error)</a></dd>
  139. <dd>&nbsp; &nbsp; <a href="index.html#Reader.ReadResponse">func (r *Reader) ReadResponse(expectCode int) (code int, message string, err error)</a></dd>
  140. <dd><a href="index.html#Writer">type Writer</a></dd>
  141. <dd>&nbsp; &nbsp; <a href="index.html#NewWriter">func NewWriter(w *bufio.Writer) *Writer</a></dd>
  142. <dd>&nbsp; &nbsp; <a href="index.html#Writer.DotWriter">func (w *Writer) DotWriter() io.WriteCloser</a></dd>
  143. <dd>&nbsp; &nbsp; <a href="index.html#Writer.PrintfLine">func (w *Writer) PrintfLine(format string, args ...interface{}) error</a></dd>
  144. </dl>
  145. </div><!-- #manual-nav -->
  146. <h4>Package files</h4>
  147. <p>
  148. <span style="font-size:90%">
  149. <a href="http://localhost:6060/src/net/textproto/header.go">header.go</a>
  150. <a href="http://localhost:6060/src/net/textproto/pipeline.go">pipeline.go</a>
  151. <a href="http://localhost:6060/src/net/textproto/reader.go">reader.go</a>
  152. <a href="http://localhost:6060/src/net/textproto/textproto.go">textproto.go</a>
  153. <a href="http://localhost:6060/src/net/textproto/writer.go">writer.go</a>
  154. </span>
  155. </p>
  156. </div><!-- .expanded -->
  157. </div><!-- #pkg-index -->
  158. <div id="pkg-callgraph" class="toggle" style="display: none">
  159. <div class="collapsed">
  160. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  161. </div> <!-- .expanded -->
  162. <div class="expanded">
  163. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  164. <p>
  165. In the call graph viewer below, each node
  166. is a function belonging to this package
  167. and its children are the functions it
  168. calls&mdash;perhaps dynamically.
  169. </p>
  170. <p>
  171. The root nodes are the entry points of the
  172. package: functions that may be called from
  173. outside the package.
  174. There may be non-exported or anonymous
  175. functions among them if they are called
  176. dynamically from another package.
  177. </p>
  178. <p>
  179. Click a node to visit that function's source code.
  180. From there you can visit its callers by
  181. clicking its declaring <code>func</code>
  182. token.
  183. </p>
  184. <p>
  185. Functions may be omitted if they were
  186. determined to be unreachable in the
  187. particular programs or tests that were
  188. analyzed.
  189. </p>
  190. <!-- Zero means show all package entry points. -->
  191. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  192. </div>
  193. </div> <!-- #pkg-callgraph -->
  194. <h2 id="CanonicalMIMEHeaderKey">func <a href="http://localhost:6060/src/net/textproto/reader.go?s=14875:14919#L552">CanonicalMIMEHeaderKey</a></h2>
  195. <pre>func CanonicalMIMEHeaderKey(s <a href="../../builtin/index.html#string">string</a>) <a href="../../builtin/index.html#string">string</a></pre>
  196. <p>
  197. CanonicalMIMEHeaderKey returns the canonical format of the
  198. MIME header key s. The canonicalization converts the first
  199. letter and any letter following a hyphen to upper case;
  200. the rest are converted to lowercase. For example, the
  201. canonical key for &#34;accept-encoding&#34; is &#34;Accept-Encoding&#34;.
  202. MIME header keys are assumed to be ASCII only.
  203. If s contains a space or invalid header field bytes, it is
  204. returned without modifications.
  205. </p>
  206. <h2 id="TrimBytes">func <a href="http://localhost:6060/src/net/textproto/textproto.go?s=3411:3442#L127">TrimBytes</a></h2>
  207. <pre>func TrimBytes(b []<a href="../../builtin/index.html#byte">byte</a>) []<a href="../../builtin/index.html#byte">byte</a></pre>
  208. <p>
  209. TrimBytes returns b without leading and trailing ASCII space.
  210. </p>
  211. <h2 id="TrimString">func <a href="http://localhost:6060/src/net/textproto/textproto.go?s=3174:3206#L116">TrimString</a></h2>
  212. <pre>func TrimString(s <a href="../../builtin/index.html#string">string</a>) <a href="../../builtin/index.html#string">string</a></pre>
  213. <p>
  214. TrimString returns s without leading and trailing ASCII space.
  215. </p>
  216. <h2 id="Conn">type <a href="http://localhost:6060/src/net/textproto/textproto.go?s=1557:1628#L48">Conn</a></h2>
  217. <pre>type Conn struct {
  218. <a href="index.html#Reader">Reader</a>
  219. <a href="index.html#Writer">Writer</a>
  220. <a href="index.html#Pipeline">Pipeline</a>
  221. <span class="comment">// contains filtered or unexported fields</span>
  222. }</pre>
  223. <p>
  224. A Conn represents a textual network protocol connection.
  225. It consists of a Reader and Writer to manage I/O
  226. and a Pipeline to sequence concurrent requests on the connection.
  227. These embedded types carry methods with them;
  228. see the documentation of those types for details.
  229. </p>
  230. <h3 id="Dial">func <a href="http://localhost:6060/src/net/textproto/textproto.go?s=2065:2111#L71">Dial</a></h3>
  231. <pre>func Dial(network, addr <a href="../../builtin/index.html#string">string</a>) (*<a href="index.html#Conn">Conn</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  232. <p>
  233. Dial connects to the given address on the given network using net.Dial
  234. and then returns a new Conn for the connection.
  235. </p>
  236. <h3 id="NewConn">func <a href="http://localhost:6060/src/net/textproto/textproto.go?s=1680:1723#L56">NewConn</a></h3>
  237. <pre>func NewConn(conn <a href="../../io/index.html">io</a>.<a href="../../io/index.html#ReadWriteCloser">ReadWriteCloser</a>) *<a href="index.html#Conn">Conn</a></pre>
  238. <p>
  239. NewConn returns a new Conn using conn for I/O.
  240. </p>
  241. <h3 id="Conn.Close">func (*Conn) <a href="http://localhost:6060/src/net/textproto/textproto.go?s=1883:1911#L65">Close</a></h3>
  242. <pre>func (c *<a href="index.html#Conn">Conn</a>) Close() <a href="../../builtin/index.html#error">error</a></pre>
  243. <p>
  244. Close closes the connection.
  245. </p>
  246. <h3 id="Conn.Cmd">func (*Conn) <a href="http://localhost:6060/src/net/textproto/textproto.go?s=2885:2960#L104">Cmd</a></h3>
  247. <pre>func (c *<a href="index.html#Conn">Conn</a>) Cmd(format <a href="../../builtin/index.html#string">string</a>, args ...interface{}) (id <a href="../../builtin/index.html#uint">uint</a>, err <a href="../../builtin/index.html#error">error</a>)</pre>
  248. <p>
  249. Cmd is a convenience method that sends a command after
  250. waiting its turn in the pipeline. The command text is the
  251. result of formatting format with args and appending \r\n.
  252. Cmd returns the id of the command, for use with StartResponse and EndResponse.
  253. </p>
  254. <p>
  255. For example, a client might run a HELP command that returns a dot-body
  256. by using:
  257. </p>
  258. <pre>id, err := c.Cmd(&#34;HELP&#34;)
  259. if err != nil {
  260. return nil, err
  261. }
  262. c.StartResponse(id)
  263. defer c.EndResponse(id)
  264. if _, _, err = c.ReadCodeLine(110); err != nil {
  265. return nil, err
  266. }
  267. text, err := c.ReadDotBytes()
  268. if err != nil {
  269. return nil, err
  270. }
  271. return c.ReadCodeLine(250)
  272. </pre>
  273. <h2 id="Error">type <a href="http://localhost:6060/src/net/textproto/textproto.go?s=952:996#L26">Error</a></h2>
  274. <pre>type Error struct {
  275. Code <a href="../../builtin/index.html#int">int</a>
  276. Msg <a href="../../builtin/index.html#string">string</a>
  277. }</pre>
  278. <p>
  279. An Error represents a numeric error response from a server.
  280. </p>
  281. <h3 id="Error.Error">func (*Error) <a href="http://localhost:6060/src/net/textproto/textproto.go?s=998:1028#L31">Error</a></h3>
  282. <pre>func (e *<a href="index.html#Error">Error</a>) Error() <a href="../../builtin/index.html#string">string</a></pre>
  283. <h2 id="MIMEHeader">type <a href="http://localhost:6060/src/net/textproto/header.go?s=262:297#L1">MIMEHeader</a></h2>
  284. <pre>type MIMEHeader map[<a href="../../builtin/index.html#string">string</a>][]<a href="../../builtin/index.html#string">string</a></pre>
  285. <p>
  286. A MIMEHeader represents a MIME-style header mapping
  287. keys to sets of values.
  288. </p>
  289. <h3 id="MIMEHeader.Add">func (MIMEHeader) <a href="http://localhost:6060/src/net/textproto/header.go?s=404:446#L3">Add</a></h3>
  290. <pre>func (h <a href="index.html#MIMEHeader">MIMEHeader</a>) Add(key, value <a href="../../builtin/index.html#string">string</a>)</pre>
  291. <p>
  292. Add adds the key, value pair to the header.
  293. It appends to any existing values associated with key.
  294. </p>
  295. <h3 id="MIMEHeader.Del">func (MIMEHeader) <a href="http://localhost:6060/src/net/textproto/header.go?s=1178:1213#L31">Del</a></h3>
  296. <pre>func (h <a href="index.html#MIMEHeader">MIMEHeader</a>) Del(key <a href="../../builtin/index.html#string">string</a>)</pre>
  297. <p>
  298. Del deletes the values associated with key.
  299. </p>
  300. <h3 id="MIMEHeader.Get">func (MIMEHeader) <a href="http://localhost:6060/src/net/textproto/header.go?s=970:1012#L19">Get</a></h3>
  301. <pre>func (h <a href="index.html#MIMEHeader">MIMEHeader</a>) Get(key <a href="../../builtin/index.html#string">string</a>) <a href="../../builtin/index.html#string">string</a></pre>
  302. <p>
  303. Get gets the first value associated with the given key.
  304. If there are no values associated with the key, Get returns &#34;&#34;.
  305. Get is a convenience method. For more complex queries,
  306. access the map directly.
  307. </p>
  308. <h3 id="MIMEHeader.Set">func (MIMEHeader) <a href="http://localhost:6060/src/net/textproto/header.go?s=659:701#L11">Set</a></h3>
  309. <pre>func (h <a href="index.html#MIMEHeader">MIMEHeader</a>) Set(key, value <a href="../../builtin/index.html#string">string</a>)</pre>
  310. <p>
  311. Set sets the header entries associated with key to
  312. the single element value. It replaces any existing
  313. values associated with key.
  314. </p>
  315. <h2 id="Pipeline">type <a href="http://localhost:6060/src/net/textproto/pipeline.go?s=817:917#L18">Pipeline</a></h2>
  316. <pre>type Pipeline struct {
  317. <span class="comment">// contains filtered or unexported fields</span>
  318. }</pre>
  319. <p>
  320. A Pipeline manages a pipelined in-order request/response sequence.
  321. </p>
  322. <p>
  323. To use a Pipeline p to manage multiple clients on a connection,
  324. each client should run:
  325. </p>
  326. <pre>id := p.Next() // take a number
  327. p.StartRequest(id) // wait for turn to send request
  328. «send request»
  329. p.EndRequest(id) // notify Pipeline that request is sent
  330. p.StartResponse(id) // wait for turn to read response
  331. «read response»
  332. p.EndResponse(id) // notify Pipeline that response is read
  333. </pre>
  334. <p>
  335. A pipelined server can use the same calls to ensure that
  336. responses computed in parallel are written in the correct order.
  337. </p>
  338. <h3 id="Pipeline.EndRequest">func (*Pipeline) <a href="http://localhost:6060/src/net/textproto/pipeline.go?s=1369:1407#L42">EndRequest</a></h3>
  339. <pre>func (p *<a href="index.html#Pipeline">Pipeline</a>) EndRequest(id <a href="../../builtin/index.html#uint">uint</a>)</pre>
  340. <p>
  341. EndRequest notifies p that the request with the given id has been sent
  342. (or, if this is a server, received).
  343. </p>
  344. <h3 id="Pipeline.EndResponse">func (*Pipeline) <a href="http://localhost:6060/src/net/textproto/pipeline.go?s=1735:1774#L54">EndResponse</a></h3>
  345. <pre>func (p *<a href="index.html#Pipeline">Pipeline</a>) EndResponse(id <a href="../../builtin/index.html#uint">uint</a>)</pre>
  346. <p>
  347. EndResponse notifies p that the response with the given id has been received
  348. (or, if this is a server, sent).
  349. </p>
  350. <h3 id="Pipeline.Next">func (*Pipeline) <a href="http://localhost:6060/src/net/textproto/pipeline.go?s=976:1006#L26">Next</a></h3>
  351. <pre>func (p *<a href="index.html#Pipeline">Pipeline</a>) Next() <a href="../../builtin/index.html#uint">uint</a></pre>
  352. <p>
  353. Next returns the next id for a request/response pair.
  354. </p>
  355. <h3 id="Pipeline.StartRequest">func (*Pipeline) <a href="http://localhost:6060/src/net/textproto/pipeline.go?s=1188:1228#L36">StartRequest</a></h3>
  356. <pre>func (p *<a href="index.html#Pipeline">Pipeline</a>) StartRequest(id <a href="../../builtin/index.html#uint">uint</a>)</pre>
  357. <p>
  358. StartRequest blocks until it is time to send (or, if this is a server, receive)
  359. the request with the given id.
  360. </p>
  361. <h3 id="Pipeline.StartResponse">func (*Pipeline) <a href="http://localhost:6060/src/net/textproto/pipeline.go?s=1550:1591#L48">StartResponse</a></h3>
  362. <pre>func (p *<a href="index.html#Pipeline">Pipeline</a>) StartResponse(id <a href="../../builtin/index.html#uint">uint</a>)</pre>
  363. <p>
  364. StartResponse blocks until it is time to receive (or, if this is a server, send)
  365. the request with the given id.
  366. </p>
  367. <h2 id="ProtocolError">type <a href="http://localhost:6060/src/net/textproto/textproto.go?s=1186:1211#L37">ProtocolError</a></h2>
  368. <pre>type ProtocolError <a href="../../builtin/index.html#string">string</a></pre>
  369. <p>
  370. A ProtocolError describes a protocol violation such
  371. as an invalid response or a hung-up connection.
  372. </p>
  373. <h3 id="ProtocolError.Error">func (ProtocolError) <a href="http://localhost:6060/src/net/textproto/textproto.go?s=1213:1250#L39">Error</a></h3>
  374. <pre>func (p <a href="index.html#ProtocolError">ProtocolError</a>) Error() <a href="../../builtin/index.html#string">string</a></pre>
  375. <h2 id="Reader">type <a href="http://localhost:6060/src/net/textproto/reader.go?s=372:490#L8">Reader</a></h2>
  376. <pre>type Reader struct {
  377. R *<a href="../../bufio/index.html">bufio</a>.<a href="../../bufio/index.html#Reader">Reader</a>
  378. <span class="comment">// contains filtered or unexported fields</span>
  379. }</pre>
  380. <p>
  381. A Reader implements convenience methods for reading requests
  382. or responses from a text protocol network connection.
  383. </p>
  384. <h3 id="NewReader">func <a href="http://localhost:6060/src/net/textproto/reader.go?s=707:746#L19">NewReader</a></h3>
  385. <pre>func NewReader(r *<a href="../../bufio/index.html">bufio</a>.<a href="../../bufio/index.html#Reader">Reader</a>) *<a href="index.html#Reader">Reader</a></pre>
  386. <p>
  387. NewReader returns a new Reader reading from r.
  388. </p>
  389. <p>
  390. To avoid denial of service attacks, the provided bufio.Reader
  391. should be reading from an io.LimitReader or similar Reader to bound
  392. the size of responses.
  393. </p>
  394. <h3 id="Reader.DotReader">func (*Reader) <a href="http://localhost:6060/src/net/textproto/reader.go?s=8320:8358#L286">DotReader</a></h3>
  395. <pre>func (r *<a href="index.html#Reader">Reader</a>) DotReader() <a href="../../io/index.html">io</a>.<a href="../../io/index.html#Reader">Reader</a></pre>
  396. <p>
  397. DotReader returns a new Reader that satisfies Reads using the
  398. decoded text of a dot-encoded block read from r.
  399. The returned Reader is only valid until the next call
  400. to a method on r.
  401. </p>
  402. <p>
  403. Dot encoding is a common framing used for data blocks
  404. in text protocols such as SMTP. The data consists of a sequence
  405. of lines, each of which ends in &#34;\r\n&#34;. The sequence itself
  406. ends at a line containing just a dot: &#34;.\r\n&#34;. Lines beginning
  407. with a dot are escaped with an additional dot to avoid
  408. looking like the end of the sequence.
  409. </p>
  410. <p>
  411. The decoded form returned by the Reader&#39;s Read method
  412. rewrites the &#34;\r\n&#34; line endings into the simpler &#34;\n&#34;,
  413. removes leading dot escapes if present, and stops with error io.EOF
  414. after consuming (and discarding) the end-of-sequence line.
  415. </p>
  416. <h3 id="Reader.ReadCodeLine">func (*Reader) <a href="http://localhost:6060/src/net/textproto/reader.go?s=5688:5771#L209">ReadCodeLine</a></h3>
  417. <pre>func (r *<a href="index.html#Reader">Reader</a>) ReadCodeLine(expectCode <a href="../../builtin/index.html#int">int</a>) (code <a href="../../builtin/index.html#int">int</a>, message <a href="../../builtin/index.html#string">string</a>, err <a href="../../builtin/index.html#error">error</a>)</pre>
  418. <p>
  419. ReadCodeLine reads a response code line of the form
  420. </p>
  421. <pre>code message
  422. </pre>
  423. <p>
  424. where code is a three-digit status code and the message
  425. extends to the rest of the line. An example of such a line is:
  426. </p>
  427. <pre>220 plan9.bell-labs.com ESMTP
  428. </pre>
  429. <p>
  430. If the prefix of the status does not match the digits in expectCode,
  431. ReadCodeLine returns with err set to &amp;Error{code, message}.
  432. For example, if expectCode is 31, an error will be returned if
  433. the status is not in the range [310,319].
  434. </p>
  435. <p>
  436. If the response is multi-line, ReadCodeLine returns an error.
  437. </p>
  438. <p>
  439. An expectCode &lt;= 0 disables the check of the status code.
  440. </p>
  441. <h3 id="Reader.ReadContinuedLine">func (*Reader) <a href="http://localhost:6060/src/net/textproto/reader.go?s=2231:2283#L80">ReadContinuedLine</a></h3>
  442. <pre>func (r *<a href="index.html#Reader">Reader</a>) ReadContinuedLine() (<a href="../../builtin/index.html#string">string</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  443. <p>
  444. ReadContinuedLine reads a possibly continued line from r,
  445. eliding the final trailing ASCII white space.
  446. Lines after the first are considered continuations if they
  447. begin with a space or tab character. In the returned data,
  448. continuation lines are separated from the previous line
  449. only by a single space: the newline and leading white space
  450. are removed.
  451. </p>
  452. <p>
  453. For example, consider this input:
  454. </p>
  455. <pre>Line 1
  456. continued...
  457. Line 2
  458. </pre>
  459. <p>
  460. The first call to ReadContinuedLine will return &#34;Line 1 continued...&#34;
  461. and the second will return &#34;Line 2&#34;.
  462. </p>
  463. <p>
  464. A line consisting of only white space is never continued.
  465. </p>
  466. <h3 id="Reader.ReadContinuedLineBytes">func (*Reader) <a href="http://localhost:6060/src/net/textproto/reader.go?s=2749:2806#L101">ReadContinuedLineBytes</a></h3>
  467. <pre>func (r *<a href="index.html#Reader">Reader</a>) ReadContinuedLineBytes() ([]<a href="../../builtin/index.html#byte">byte</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  468. <p>
  469. ReadContinuedLineBytes is like ReadContinuedLine but
  470. returns a []byte instead of a string.
  471. </p>
  472. <h3 id="Reader.ReadDotBytes">func (*Reader) <a href="http://localhost:6060/src/net/textproto/reader.go?s=10735:10782#L402">ReadDotBytes</a></h3>
  473. <pre>func (r *<a href="index.html#Reader">Reader</a>) ReadDotBytes() ([]<a href="../../builtin/index.html#byte">byte</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  474. <p>
  475. ReadDotBytes reads a dot-encoding and returns the decoded data.
  476. </p>
  477. <p>
  478. See the documentation for the DotReader method for details about dot-encoding.
  479. </p>
  480. <h3 id="Reader.ReadDotLines">func (*Reader) <a href="http://localhost:6060/src/net/textproto/reader.go?s=11045:11094#L410">ReadDotLines</a></h3>
  481. <pre>func (r *<a href="index.html#Reader">Reader</a>) ReadDotLines() ([]<a href="../../builtin/index.html#string">string</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  482. <p>
  483. ReadDotLines reads a dot-encoding and returns a slice
  484. containing the decoded lines, with the final \r\n or \n elided from each.
  485. </p>
  486. <p>
  487. See the documentation for the DotReader method for details about dot-encoding.
  488. </p>
  489. <h3 id="Reader.ReadLine">func (*Reader) <a href="http://localhost:6060/src/net/textproto/reader.go?s=872:915#L25">ReadLine</a></h3>
  490. <pre>func (r *<a href="index.html#Reader">Reader</a>) ReadLine() (<a href="../../builtin/index.html#string">string</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  491. <p>
  492. ReadLine reads a single line from r,
  493. eliding the final \n or \r\n from the returned string.
  494. </p>
  495. <h3 id="Reader.ReadLineBytes">func (*Reader) <a href="http://localhost:6060/src/net/textproto/reader.go?s=1055:1103#L31">ReadLineBytes</a></h3>
  496. <pre>func (r *<a href="index.html#Reader">Reader</a>) ReadLineBytes() ([]<a href="../../builtin/index.html#byte">byte</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  497. <p>
  498. ReadLineBytes is like ReadLine but returns a []byte instead of a string.
  499. </p>
  500. <h3 id="Reader.ReadMIMEHeader">func (*Reader) <a href="http://localhost:6060/src/net/textproto/reader.go?s=12179:12232#L458">ReadMIMEHeader</a></h3>
  501. <pre>func (r *<a href="index.html#Reader">Reader</a>) ReadMIMEHeader() (<a href="index.html#MIMEHeader">MIMEHeader</a>, <a href="../../builtin/index.html#error">error</a>)</pre>
  502. <p>
  503. ReadMIMEHeader reads a MIME-style header from r.
  504. The header is a sequence of possibly continued Key: Value lines
  505. ending in a blank line.
  506. The returned map m maps CanonicalMIMEHeaderKey(key) to a
  507. sequence of values in the same order encountered in the input.
  508. </p>
  509. <p>
  510. For example, consider this input:
  511. </p>
  512. <pre>My-Key: Value 1
  513. Long-Key: Even
  514. Longer Value
  515. My-Key: Value 2
  516. </pre>
  517. <p>
  518. Given that input, ReadMIMEHeader returns the map:
  519. </p>
  520. <pre>map[string][]string{
  521. &#34;My-Key&#34;: {&#34;Value 1&#34;, &#34;Value 2&#34;},
  522. &#34;Long-Key&#34;: {&#34;Even Longer Value&#34;},
  523. }
  524. </pre>
  525. <h3 id="Reader.ReadResponse">func (*Reader) <a href="http://localhost:6060/src/net/textproto/reader.go?s=6844:6927#L244">ReadResponse</a></h3>
  526. <pre>func (r *<a href="index.html#Reader">Reader</a>) ReadResponse(expectCode <a href="../../builtin/index.html#int">int</a>) (code <a href="../../builtin/index.html#int">int</a>, message <a href="../../builtin/index.html#string">string</a>, err <a href="../../builtin/index.html#error">error</a>)</pre>
  527. <p>
  528. ReadResponse reads a multi-line response of the form:
  529. </p>
  530. <pre>code-message line 1
  531. code-message line 2
  532. ...
  533. code message line n
  534. </pre>
  535. <p>
  536. where code is a three-digit status code. The first line starts with the
  537. code and a hyphen. The response is terminated by a line that starts
  538. with the same code followed by a space. Each line in message is
  539. separated by a newline (\n).
  540. </p>
  541. <p>
  542. See page 36 of RFC 959 (<a href="http://www.ietf.org/rfc/rfc959.txt">http://www.ietf.org/rfc/rfc959.txt</a>) for
  543. details of another form of response accepted:
  544. </p>
  545. <pre>code-message line 1
  546. message line 2
  547. ...
  548. code message line n
  549. </pre>
  550. <p>
  551. If the prefix of the status does not match the digits in expectCode,
  552. ReadResponse returns with err set to &amp;Error{code, message}.
  553. For example, if expectCode is 31, an error will be returned if
  554. the status is not in the range [310,319].
  555. </p>
  556. <p>
  557. An expectCode &lt;= 0 disables the check of the status code.
  558. </p>
  559. <h2 id="Writer">type <a href="http://localhost:6060/src/net/textproto/writer.go?s=333:390#L5">Writer</a></h2>
  560. <pre>type Writer struct {
  561. W *<a href="../../bufio/index.html">bufio</a>.<a href="../../bufio/index.html#Writer">Writer</a>
  562. <span class="comment">// contains filtered or unexported fields</span>
  563. }</pre>
  564. <p>
  565. A Writer implements convenience methods for writing
  566. requests or responses to a text protocol network connection.
  567. </p>
  568. <h3 id="NewWriter">func <a href="http://localhost:6060/src/net/textproto/writer.go?s=440:479#L11">NewWriter</a></h3>
  569. <pre>func NewWriter(w *<a href="../../bufio/index.html">bufio</a>.<a href="../../bufio/index.html#Writer">Writer</a>) *<a href="index.html#Writer">Writer</a></pre>
  570. <p>
  571. NewWriter returns a new Writer writing to w.
  572. </p>
  573. <h3 id="Writer.DotWriter">func (*Writer) <a href="http://localhost:6060/src/net/textproto/writer.go?s=1210:1253#L33">DotWriter</a></h3>
  574. <pre>func (w *<a href="index.html#Writer">Writer</a>) DotWriter() <a href="../../io/index.html">io</a>.<a href="../../io/index.html#WriteCloser">WriteCloser</a></pre>
  575. <p>
  576. DotWriter returns a writer that can be used to write a dot-encoding to w.
  577. It takes care of inserting leading dots when necessary,
  578. translating line-ending \n into \r\n, and adding the final .\r\n line
  579. when the DotWriter is closed. The caller should close the
  580. DotWriter before the next call to a method on w.
  581. </p>
  582. <p>
  583. See the documentation for Reader&#39;s DotReader method for details about dot-encoding.
  584. </p>
  585. <h3 id="Writer.PrintfLine">func (*Writer) <a href="http://localhost:6060/src/net/textproto/writer.go?s=636:705#L19">PrintfLine</a></h3>
  586. <pre>func (w *<a href="index.html#Writer">Writer</a>) PrintfLine(format <a href="../../builtin/index.html#string">string</a>, args ...interface{}) <a href="../../builtin/index.html#error">error</a></pre>
  587. <p>
  588. PrintfLine writes the formatted output followed by \r\n.
  589. </p>
  590. <div id="footer">
  591. Build version go1.6.<br>
  592. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  593. the content of this page is licensed under the
  594. Creative Commons Attribution 3.0 License,
  595. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  596. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  597. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  598. </div>
  599. </div><!-- .container -->
  600. </div><!-- #page -->
  601. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  602. <script type="text/javascript" src="../../../lib/godoc/jquery.js"></script>
  603. <script type="text/javascript" src="../../../lib/godoc/jquery.treeview.js"></script>
  604. <script type="text/javascript" src="../../../lib/godoc/jquery.treeview.edit.js"></script>
  605. <script type="text/javascript" src="../../../lib/godoc/godocs.js"></script>
  606. </body>
  607. </html>