Docs for new res methods
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent da5a480 · Browse files · 5 files·+157 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+157 added−10 removed
- other:+157 added−10 removed
Provenance
- Commit
b08dab9- Tree
dc552fd- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
da5a480
5 files changed+157 added−10 removed
modified:docs/api.html+67 added-9 removed
316 unmodified lines317 <li><p><strong>param</strong>: <em>String</em> name</p></li>318 <li><p><strong>return</strong>: <em>String</em></p></li>319 <li><p><strong>api</strong>: <em>public</em></p></li>320 </ul>321-���:321+322 </td>323 <td class="code">324 <pre><code><span class="variable">http</span>.<span class="class">IncomingMessage</span>.<span class="variable">prototype</span>.<span class="variable">param</span> = <span class="keyword">function</span>(<span class="variable">name</span>){325 <span class="comment">// Route params like /user/:id</span>85 unmodified lines411 <td class="docs">412 <p>Module dependencies.</p>413 </td>414 <td class="code">415-<pre><code><span class="keyword">var</span> <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),415+<pre><code><span class="keyword">var</span> <span class="variable">fs</span> = <span class="variable">require</span>(<span class="string">'fs'</span>),416+ <span class="variable">http</span> = <span class="variable">require</span>(<span class="string">'http'</span>),417 <span class="variable">path</span> = <span class="variable">require</span>(<span class="string">'path'</span>),418 <span class="variable">utils</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>),419 <span class="variable">mime</span> = <span class="variable">require</span>(<span class="string">'connect/utils'</span>).<span class="variable">mime</span>,420 <span class="class">Buffer</span> = <span class="variable">require</span>(<span class="string">'buffer'</span>).<span class="class">Buffer</span>;</code></pre>80 unmodified lines501 </td>502 </tr>503 <tr class="code">504 <td class="docs">505+<p>Transfer the given <code>file</code>. Automatically sets the <em>Content-Type</em>506+response header, and responds with 404 / 500 appropriately.</p>507+508+<h2></h2>509+510+<ul>511+<li><p><strong>param</strong>: <em>String</em> file</p></li>512+<li><p><strong>api</strong>: <em>public</em></p></li>513+</ul>514+515+</td>516+<td class="code">517+<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">sendfile</span> = <span class="keyword">function</span>(<span class="variable">file</span>){518+ <span class="keyword">var</span> <span class="variable">self</span> = <span class="this">this</span>;519+ <span class="variable">fs</span>.<span class="variable">readFile</span>(<span class="variable">file</span>, <span class="keyword">function</span>(<span class="variable">err</span>, <span class="variable">buf</span>){520+ <span class="keyword">if</span> (<span class="variable">err</span>) {521+ <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">err</span>.<span class="variable">errno</span> === <span class="variable">process</span>.<span class="class">ENOENT</span>522+ ? <span class="number integer">404</span>523+ : <span class="number integer">500</span>);524+ } <span class="keyword">else</span> {525+ <span class="variable">self</span>.<span class="variable">contentType</span>(<span class="variable">file</span>);526+ <span class="variable">self</span>.<span class="variable">send</span>(<span class="variable">buf</span>);527+ }528+ });529+};</code></pre>530+</td>531+</tr>532+<tr class="code">533+<td class="docs">534 <p>Set <em>Content-Type</em> response header passed through <code>mime.type()</code>.</p>535 536 <h2>Examples</h2>537 40 unmodified lines578 </td>579 </tr>580 <tr class="code">581 <td class="docs">582+<p>Transfer the given <code>file</code> with optional <code>filename</code> as an attachment.</p>583+584+<h2></h2>585+586+<ul>587+<li><p><strong>param</strong>: <em>String</em> file</p></li>588+<li><p><strong>param</strong>: <em>String</em> filename</p></li>589+<li><p><strong>return</strong>: <em>Type</em></p></li>590+<li><p><strong>api</strong>: <em>public</em></p></li>591+</ul>592+593+</td>594+<td class="code">595+<pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">download</span> = <span class="keyword">function</span>(<span class="variable">file</span>, <span class="variable">filename</span>){596+ <span class="this">this</span>.<span class="variable">attachment</span>(<span class="variable">filename</span> || <span class="variable">file</span>).<span class="variable">sendfile</span>(<span class="variable">file</span>);597+};</code></pre>598+</td>599+</tr>600+<tr class="code">601+<td class="docs">602 <p>Set or get response header <code>name</code> with optional <code>val</code>.</p>603 604 <h2></h2>605 145 unmodified lines751 </td>752 </tr>753 <tr class="code">754 <td class="docs">705-<p>Inherit from <code>connect.Server</code>.</p>N %755+<p>Inherit from <code>connect.Server</code>.</p>756 </td>757 <td class="code">758 <pre><code><span class="variable">sys</span>.<span class="variable">inherits</span>(<span class="class">Server</span>, <span class="variable">connect</span>.<span class="class">Server</span>);</code></pre>759 </td>39 unmodified lines799 <li><p><strong>param</strong>: <em>String</em> env …</p></li>800 <li><p><strong>return</strong>: <em>Server</em> for chaining</p></li>801 <li><p><strong>api</strong>: <em>public</em></p></li>802 </ul>753-;</p>803 755-<h2><804 </td>805 <td class="code">806 <pre><code><span class="class">Server</span>.<span class="variable">prototype</span>.<span class="variable">runConfig</span> = <span class="keyword">function</span>(){807 <span class="keyword">for</span> (<span class="keyword">var</span> <span class="variable">i</span> = <span class="number integer">0</span>, <span class="variable">len</span> = <span class="variable">arguments</span>.<span class="variable">length</span>; <span class="variable">i</span> &<span class="variable">lt</span>; <span class="variable">len</span>; ++<span class="variable">i</span>) {160 unmodified lines968 <li><p><strong>param</strong>: <em>String</em> str</p></li>969 <li><p><strong>return</strong>: <em>String</em></p></li>970 <li><p><strong>api</strong>: <em>public</em></p></li>971 </ul>924-972+973 </td>974 <td class="code">975 <pre><code><span class="variable">exports</span>.<span class="variable">miniMarkdown</span> = <span class="keyword">function</span>(<span class="variable">str</span>){976 <span class="keyword">return</span> <span class="class">String</span>(<span class="variable">str</span>)72 unmodified lines1049 1050 <ul>1051 <li><strong>api</strong>: <em>public</em></li>1052 </ul>1005-] %1053+1054 </td>1055 <td class="code">1056 <pre><code><span class="variable">exports</span>.<span class="variable">clearCache</span> = <span class="keyword">function</span>(){1057 <span class="variable">viewCache</span> = {};6 unmodified lines1064 1065 <ul>1066 <li><strong>type</strong>: <em>Object</em></li>1067 </ul>1020-1068+1069 </td>1070 <td class="code">1071 <pre><code><span class="keyword">var</span> <span class="variable">helpers</span> = <span class="variable">exports</span>.<span class="variable">helpers</span> = {};</code></pre>1072 </td>25 unmodified lines1098 <li><p><strong>param</strong>: <em>Object | Array</em> options or collection</p></li>1099 <li><p><strong>return</strong>: <em>String</em></p></li>1100 <li><p><strong>api</strong>: <em>public</em></p></li>1101 </ul>1054- %1102+ %1103 </td>1104 <td class="code">1105 <pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">partial</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">ext</span>){1106 <span class="keyword">if</span> (<span class="variable">ext</span> &<span class="variable">amp</span>;&<span class="variable">amp</span>; <span class="variable">view</span>.<span class="variable">indexOf</span>(<span class="string">'.'</span>) &<span class="variable">lt</span>; <span class="number integer">0</span>) {57 unmodified lines1164 <li><p><strong>param</strong>: <em>Object</em> options</p></li>1165 <li><p><strong>param</strong>: <em>Function</em> fn</p></li>1166 <li><p><strong>api</strong>: <em>public</em></p></li>1167 </ul>1168+ res.redirect('comments');1169+ });1170 1171+## 1172+ - **param**: _String_ url1173+1174+ - **param**: _Number_ code1175+1176+ - **api**: _public_1177+1178+ 1179 </td>1180 <td class="code">1181 <pre><code><span class="variable">http</span>.<span class="class">ServerResponse</span>.<span class="variable">prototype</span>.<span class="variable">render</span> = <span class="keyword">function</span>(<span class="variable">view</span>, <span class="variable">options</span>, <span class="variable">fn</span>){1182 <span class="variable">options</span> = <span class="variable">options</span> || {};93 unmodified linesmodified:docs/guide.1+44 added
257 unmodified lines258 .fi259 .260 .IP "" 0261 .262+.SS "ServerResponse#sendfile(path)"263+Used by \fBres\.download()\fR to transfer an arbitrary file\.264+.265+.IP "" 4266+.267+.nf268+269+res\.sendfile(\'path/to/my\.file\');270+.271+.fi272+.273+.IP "" 0274+.275+.P276+\fBNOTE\fR: this is \fInot\fR a replacement for Connect\'s \fIstaticProvider\fR middleware, nor does it perform any security checks, use with caution when using in a dynamic manor\.277+.278+.SS "ServerResponse#download(file[, filename])"279+Transfer the given \fIfile\fR as an attachment with optional alternative \fIfilename\fR\.280+.281+.IP "" 4282+.283+.nf284+285+res\.download(\'path/to/image\.png\');286+res\.download(\'path/to/image\.png\', \'foo\.png\');287+.288+.fi289+.290+.IP "" 0291+.292+.P293+This is equivalent to:294+.295+.IP "" 4296+.297+.nf298+299+res\.attachment(file);300+res\.sendfile(file);301+.302+.fi303+.304+.IP "" 0305+.306 .SS "ServerRequest#send(body|status[, headers|status[, status]])"307 The \fBres\.send()\fR method is a high level response utility allowing you to pass objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status code based responses\. The following are all valid uses:308 .309 .IP "" 486 unmodified linesmodified:docs/guide.html+24 added
342 unmodified lines343 344 <pre><code> res.attachment('path/to/my/image.png');345 </code></pre>346 347+<h3 id="ServerResponse-sendfile-path-">ServerResponse#sendfile(path)</h3>348+349+<p>Used by <code>res.download()</code> to transfer an arbitrary file.</p>350+351+<pre><code>res.sendfile('path/to/my.file');352+</code></pre>353+354+<p><strong>NOTE</strong>: this is <em>not</em> a replacement for Connect's <em>staticProvider</em> middleware,355+nor does it perform any security checks, use with caution when using in a dynamic manor.</p>356+357+<h3 id="ServerResponse-download-file-filename-">ServerResponse#download(file[, filename])</h3>358+359+<p>Transfer the given <em>file</em> as an attachment with optional alternative <em>filename</em>.</p>360+361+<pre><code>res.download('path/to/image.png');362+res.download('path/to/image.png', 'foo.png');363+</code></pre>364+365+<p>This is equivalent to:</p>366+367+<pre><code>res.attachment(file);368+res.sendfile(file);369+</code></pre>370+371 <h3 id="ServerRequest-send-body-status-headers-status-status-">ServerRequest#send(body|status[, headers|status[, status]])</h3>372 373 <p>The <code>res.send()</code> method is a high level response utility allowing you to pass374 objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status61 unmodified linesmodified:docs/guide.md+21 added
166 unmodified lines167 Sets the _Content-Disposition_ response header to "attachment", with optional _filename_.168 169 res.attachment('path/to/my/image.png');170 171+### ServerResponse#sendfile(path)172+173+Used by `res.download()` to transfer an arbitrary file. 174+175+ res.sendfile('path/to/my.file');176+177+**NOTE**: this is _not_ a replacement for Connect's _staticProvider_ middleware,178+nor does it perform any security checks, use with caution when using in a dynamic manor.179+180+### ServerResponse#download(file[, filename])181+182+Transfer the given _file_ as an attachment with optional alternative _filename_.183+184+ res.download('path/to/image.png');185+ res.download('path/to/image.png', 'foo.png');186+187+This is equivalent to:188+189+ res.attachment(file);190+ res.sendfile(file);191+192 ### ServerRequest#send(body|status[, headers|status[, status]])193 194 The `res.send()` method is a high level response utility allowing you to pass195 objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status50 unmodified linesmodified:lib/express/response.js+1 added-1 removed
151 unmodified lines152 * @api public153 */154 155 http.ServerResponse.prototype.download = function(file, filename){156- this.attachment(filename || path.basename(file)).sendfile(file);156+ this.attachment(filename || file).sendfile(file);157 };158 159 /**160 * Set or get response header `name` with optional `val`.75 unmodified lines