Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
06b7a92
tools: add eslint-plugin-markdown to tools
tflanagan Feb 3, 2016
7ef37e7
build: add jslint-docs
tflanagan Feb 3, 2016
b1d72c4
doc: fix zlib.markdown code examples
tflanagan Feb 3, 2016
f33102f
doc: fix vm.markdown code examples
tflanagan Feb 3, 2016
dce6f63
doc: fix v8.markdown code examples
tflanagan Feb 3, 2016
785cf8a
doc: fix util.markdown code examples
tflanagan Feb 3, 2016
28c097e
doc: fix url.markdown code examples
tflanagan Feb 3, 2016
12c2164
doc: fix tls.markdown code examples
tflanagan Feb 3, 2016
a1ccb3f
doc: fix synopsis.markdown code examples
tflanagan Feb 3, 2016
0a8e050
doc: fix string_decoder.markdown code examples
tflanagan Feb 3, 2016
a092aff
doc: fix stream.markdown code examples
tflanagan Feb 3, 2016
844a648
doc: fix repl.markdown code examples
tflanagan Feb 3, 2016
fe84729
doc: fix readline.markdown code examples
tflanagan Feb 3, 2016
cd82e93
doc: fix querystring.markdown code examples
tflanagan Feb 3, 2016
aec9d27
doc: fix process.markdown code examples
tflanagan Feb 3, 2016
91b5733
doc: fix path.markdown code examples
tflanagan Feb 3, 2016
8a0517d
doc: fix punycode.markdown code examples
tflanagan Feb 3, 2016
2141a53
doc: fix os.markdown code examples
tflanagan Feb 3, 2016
eeb11f6
doc: fix net.markdown code examples
tflanagan Feb 3, 2016
fe80931
doc: fix modules.markdown code examples
tflanagan Feb 3, 2016
4ea4dec
doc: fix https.markdown code examples
tflanagan Feb 3, 2016
d6192c5
doc: fix http.markdown code examples
tflanagan Feb 3, 2016
4484863
doc: fix fs.markdown code examples
tflanagan Feb 3, 2016
a9e421d
doc: fix events.markdown code examples
tflanagan Feb 3, 2016
cf3685d
doc: fix errors.markdown code examples
tflanagan Feb 3, 2016
26de732
doc: fix domain.markdown code examples
tflanagan Feb 3, 2016
f9dfcef
doc: fix dgram.markdown code examplesc
tflanagan Feb 3, 2016
9f9243e
doc: fix debugger.markdown code examplesc
tflanagan Feb 3, 2016
4c16952
doc: fix addons.markdown code examples
tflanagan Feb 3, 2016
8686f19
doc: fix assert.markdown code examples
tflanagan Feb 3, 2016
3a362a9
doc: fix child_process.markdown code examples
tflanagan Feb 3, 2016
b05d621
doc: fix console.markdown code examples
tflanagan Feb 3, 2016
4c28eb4
doc: fix cluster.markdown code examples
tflanagan Feb 3, 2016
66c4081
doc: fix crypto.markdown code examples
tflanagan Feb 3, 2016
775cf49
doc: fix buffer.markdown code examples
tflanagan Feb 3, 2016
5d58b3f
build,doc: moving doc lint rules to doc/api/.eslintrc
tflanagan Feb 12, 2016
cb5c1dd
build: add jslint-docs to test
tflanagan Feb 17, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
doc: fix http.markdown code examples
  • Loading branch information
tflanagan committed Feb 10, 2016
commit d6192c5b45fb3e8af221b232453950ad1815a119
46 changes: 38 additions & 8 deletions doc/api/http.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ you intend to keep one HTTP request open for a long time and don't
want it to stay in the pool you can do something along the lines of:

```js
const http = require('http');

const options = { /* ... */ };

http.get(options, (res) => {
// Do stuff
}).on('socket', (socket) => {
Expand All @@ -80,14 +84,16 @@ Alternatively, you could just opt out of pooling entirely using
`agent:false`:

```js
const http = require('http');

http.get({
hostname: 'localhost',
port: 80,
path: '/',
agent: false // create a new agent just for this one request
}, (res) => {
// Do stuff with response
})
});
```

### new Agent([options])
Expand All @@ -113,8 +119,11 @@ To configure any of them, you must create your own [`http.Agent`][] object.
```js
const http = require('http');
var keepAliveAgent = new http.Agent({ keepAlive: true });
var options = { /* ... */ };
options.agent = keepAliveAgent;
http.request(options, onResponseCallback);
http.request(options, (res) => {
/* ... */
});
```

### agent.destroy()
Expand Down Expand Up @@ -227,7 +236,7 @@ const net = require('net');
const url = require('url');

// Create an HTTP tunneling proxy
var proxy = http.createServer( (req, res) => {
var proxy = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('okay');
});
Expand Down Expand Up @@ -317,7 +326,7 @@ A client server pair that show you how to listen for the `'upgrade'` event.
const http = require('http');

// Create an HTTP server
var srv = http.createServer( (req, res) => {
var srv = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('okay');
});
Expand Down Expand Up @@ -642,6 +651,7 @@ Note that HTTP requires the `Trailer` header to be sent if you intend to
emit trailers, with a list of the header fields in its value. E.g.,

```js
/* eslint no-undef:0 */
response.writeHead(200, { 'Content-Type': 'text/plain',
'Trailer': 'Content-MD5' });
response.write(fileData);
Expand Down Expand Up @@ -678,6 +688,7 @@ implicitly flushed.
Example:

```js
/* eslint no-unused-vars:0, no-undef:0 */
var contentType = response.getHeader('content-type');
```

Expand All @@ -692,6 +703,7 @@ Removes a header that's queued for implicit sending.
Example:

```js
/* eslint no-undef:0 */
response.removeHeader('Content-Encoding');
```

Expand All @@ -712,12 +724,14 @@ here if you need to send multiple headers with the same name.
Example:

```js
/* eslint no-undef:0 */
response.setHeader('Content-Type', 'text/html');
```

or

```js
/* eslint no-undef:0 */
response.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);
```

Expand All @@ -729,8 +743,11 @@ any headers passed to [`response.writeHead()`][], with the headers passed to
[`response.writeHead()`][] given precedence.

```js
const http = require('http');

// returns content-type = text/plain
const server = http.createServer((req,res) => {
/* eslint no-unused-vars:0 */
const server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/html');
res.setHeader('X-Foo', 'bar');
res.writeHead(200, {'Content-Type': 'text/plain'});
Expand Down Expand Up @@ -764,6 +781,7 @@ the headers get flushed.
Example:

```js
/* eslint no-undef:0 */
response.statusCode = 404;
```

Expand All @@ -780,6 +798,7 @@ code will be used.
Example:

```js
/* eslint no-undef:0 */
response.statusMessage = 'Not found';
```

Expand Down Expand Up @@ -828,6 +847,7 @@ Example:

```js
var body = 'hello world';
/* eslint no-undef:0 */
response.writeHead(200, {
'Content-Length': body.length,
'Content-Type': 'text/plain' });
Expand All @@ -844,8 +864,11 @@ any headers passed to [`response.writeHead()`][], with the headers passed to
[`response.writeHead()`][] given precedence.

```js
const http = require('http');

// returns content-type = text/plain
const server = http.createServer((req,res) => {
/* eslint no-unused-vars:0 */
const server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/html');
res.setHeader('X-Foo', 'bar');
res.writeHead(200, {'Content-Type': 'text/plain'});
Expand Down Expand Up @@ -893,6 +916,7 @@ Example:
// { 'user-agent': 'curl/7.22.0',
// host: '127.0.0.1:8000',
// accept: '*/*' }
/* eslint no-undef:0 */
console.log(request.headers);
```

Expand Down Expand Up @@ -943,6 +967,7 @@ Header names are not lowercased, and duplicates are not merged.
// '127.0.0.1:8000',
// 'ACCEPT',
// '*/*' ]
/* eslint no-undef:0 */
console.log(request.rawHeaders);
```

Expand Down Expand Up @@ -1068,6 +1093,8 @@ is that it sets the method to GET and calls `req.end()` automatically.
Example:

```js
const http = require('http');

http.get('http://www.google.com/index.html', (res) => {
console.log(`Got response: ${res.statusCode}`);
// consume response body
Expand Down Expand Up @@ -1128,6 +1155,9 @@ upload a file with a POST request, then write to the `ClientRequest` object.
Example:

```js
const querystring = require('querystring');
const http = require('http');

var postData = querystring.stringify({
'msg' : 'Hello World!'
});
Expand All @@ -1151,8 +1181,8 @@ var req = http.request(options, (res) => {
console.log(`BODY: ${chunk}`);
});
res.on('end', () => {
console.log('No more data in response.')
})
console.log('No more data in response.');
});
});

req.on('error', (e) => {
Expand Down