Skip to content
Myr

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

5 files+157 added−10 removed

modified:docs/api.html+67 added-9 removed
316 unmodified lines
317<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���:321322</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 lines
411<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 lines
501</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>506response header, and responds with 404 / 500 appropriately.</p>507508<h2></h2>509510<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>514515</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>535536<h2>Examples</h2>537
40 unmodified lines
578</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>583584<h2></h2>585586<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>592593</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>603604<h2></h2>605
145 unmodified lines
751</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 lines
799<li><p><strong>param</strong>: <em>String</em> env &hellip;</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>803755<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 lines
968<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 972973</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 lines
10491050<ul>1051<li><strong>api</strong>: <em>public</em></li>1052</ul>1005] %10531054</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 lines
10641065<ul>1066<li><strong>type</strong>: <em>Object</em></li>1067</ul>1020 10681069</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 lines
1098<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 lines
1164<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 });11701171## 1172 - **param**: _String_ url11731174 - **param**: _Number_ code11751176 - **api**: _public_11771178 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 lines
modified:docs/guide.1+44 added
257 unmodified lines
258.fi259.260.IP "" 0261.262.SS "ServerResponse#sendfile(path)"263Used by \fBres\.download()\fR to transfer an arbitrary file\.264.265.IP "" 4266.267.nf268269res\.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])"279Transfer the given \fIfile\fR as an attachment with optional alternative \fIfilename\fR\.280.281.IP "" 4282.283.nf284285res\.download(\'path/to/image\.png\');286res\.download(\'path/to/image\.png\', \'foo\.png\');287.288.fi289.290.IP "" 0291.292.P293This is equivalent to:294.295.IP "" 4296.297.nf298299res\.attachment(file);300res\.sendfile(file);301.302.fi303.304.IP "" 0305.306.SS "ServerRequest#send(body|status[, headers|status[, status]])"307The \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 "" 4
86 unmodified lines
modified:docs/guide.html+24 added
342 unmodified lines
343344<pre><code> res.attachment('path/to/my/image.png');345</code></pre>346347<h3 id="ServerResponse-sendfile-path-">ServerResponse#sendfile(path)</h3>348349<p>Used by <code>res.download()</code> to transfer an arbitrary file.</p>350351<pre><code>res.sendfile('path/to/my.file');352</code></pre>353354<p><strong>NOTE</strong>: this is <em>not</em> a replacement for Connect's <em>staticProvider</em> middleware,355nor does it perform any security checks, use with caution when using in a dynamic manor.</p>356357<h3 id="ServerResponse-download-file-filename-">ServerResponse#download(file[, filename])</h3>358359<p>Transfer the given <em>file</em> as an attachment with optional alternative <em>filename</em>.</p>360361<pre><code>res.download('path/to/image.png');362res.download('path/to/image.png', 'foo.png');363</code></pre>364365<p>This is equivalent to:</p>366367<pre><code>res.attachment(file);368res.sendfile(file);369</code></pre>370371<h3 id="ServerRequest-send-body-status-headers-status-status-">ServerRequest#send(body|status[, headers|status[, status]])</h3>372373<p>The <code>res.send()</code> method is a high level response utility allowing you to pass374objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status
61 unmodified lines
modified:docs/guide.md+21 added
166 unmodified lines
167Sets the _Content-Disposition_ response header to "attachment", with optional _filename_.168169 res.attachment('path/to/my/image.png');170171### ServerResponse#sendfile(path)172173Used by `res.download()` to transfer an arbitrary file. 174175 res.sendfile('path/to/my.file');176177**NOTE**: this is _not_ a replacement for Connect's _staticProvider_ middleware,178nor does it perform any security checks, use with caution when using in a dynamic manor.179180### ServerResponse#download(file[, filename])181182Transfer the given _file_ as an attachment with optional alternative _filename_.183184 res.download('path/to/image.png');185 res.download('path/to/image.png', 'foo.png');186187This is equivalent to:188189 res.attachment(file);190 res.sendfile(file);191192### ServerRequest#send(body|status[, headers|status[, status]])193194The `res.send()` method is a high level response utility allowing you to pass195objects to respond with json, strings for html, arbitrary _Buffer_s or numbers for status
50 unmodified lines
modified:lib/express/response.js+1 added-1 removed
151 unmodified lines
152 * @api public153 */154155http.ServerResponse.prototype.download = function(file, filename){156 this.attachment(filename || path.basename(file)).sendfile(file);156 this.attachment(filename || file).sendfile(file);157};158159/**160 * Set or get response header `name` with optional `val`.
75 unmodified lines