-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathTODO.patch
2039 lines (1714 loc) · 68.9 KB
/
TODO.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-### fs.watchFile(filename, [options], listener)
+## fs.watchFile(filename, [options], listener)
Watch for changes on `filename`. The callback `listener` will be called each
time the file is accessed.
The second argument is optional. The `options` if provided should be an object
-containing two members a boolean, `persistent`, and `interval`, a polling
-value in milliseconds. The default is `{ persistent: true, interval: 0 }`.
+containing two members a boolean, `persistent`, and `interval`. `persistent`
+indicates whether the process should continue to run as long as files are
+being watched. `interval` indicates how often the target should be polled,
+in milliseconds. (On Linux systems with inotify, `interval` is ignored.) The
+default is `{ persistent: true, interval: 0 }`.
The `listener` gets two arguments the current stat object and the previous
stat object:
@@ -399,13 +413,44 @@ If you want to be notified when the file
-## fs.Stats
+## fs.watch(filename, [options], listener)
+
+Watch for changes on `filename`, where `filename` is either a file or a
+directory. The returned object is [fs.FSWatcher](#fs.FSWatcher).
+
+The second argument is optional. The `options` if provided should be an object
+containing a boolean member `persistent`, which indicates whether the process
+should continue to run as long as files are being watched. The default is
+`{ persistent: true }`.
+
+The listener callback gets two arguments `(event, filename)`. `event` is either
+'rename' or 'change', and `filename` is the name of the file which triggered
+the event.
+
+***Warning:***
+Providing `filename` argument in the callback is not supported
+on every platform (currently it's only supported on Linux and Windows). Even
+on supported platforms `filename` is not always guaranteed to be provided.
+Therefore, don't assume that `filename` argument is always provided in the
+callback, and have some fallback logic if it is null.
+
+ fs.watch('somedir', function (event, filename) {
+ console.log('event is: ' + event);
+ if (filename) {
+ console.log('filename provided: ' + filename);
+ } else {
+ console.log('filename not provided');
+ }
+ });
+
+## Class: fs.Stats
-Objects returned from `fs.stat()` and `fs.lstat()` are of this type.
+Objects returned from `fs.stat()`, `fs.lstat()` and `fs.fstat()` and their
+synchronous counterparts are of this type.
- `stats.isFile()`
- `stats.isDirectory()`
@@ -415,18 +460,38 @@ Objects returned from `fs.stat()` and `f
- `stats.isFIFO()`
- `stats.isSocket()`
+For a regular file `util.inspect(stats)` would return a string very
+similar to this:
-## fs.ReadStream
-
-`ReadStream` is a `Readable Stream`.
-
-### Event: 'open'
+ { dev: 2114,
+ ino: 48064969,
+ mode: 33188,
+ nlink: 1,
+ uid: 85,
+ gid: 100,
+ rdev: 0,
+ size: 527,
+ blksize: 4096,
+ blocks: 8,
+ atime: Mon, 10 Oct 2011 23:24:11 GMT,
+ mtime: Mon, 10 Oct 2011 23:24:11 GMT,
+ ctime: Mon, 10 Oct 2011 23:24:11 GMT }
+
+Please note that `atime`, `mtime` and `ctime` are instances
+of [Date][MDN-Date] object and to compare the values of
+these objects you should use appropriate methods. For most
+general uses [getTime()][MDN-Date-getTime] will return
+the number of milliseconds elapsed since _1 January 1970
+00:00:00 UTC_ and this integer should be sufficient for
+any comparison, however there additional methods which can
+be used for displaying fuzzy information. More details can
+be found in the [MDN JavaScript Reference][MDN-Date] page.
-`function (fd) { }`
+[MDN-Date]: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date
+[MDN-Date-getTime]: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date/getTime
- `fd` is the file descriptor used by the ReadStream.
-### fs.createReadStream(path, [options])
+## fs.createReadStream(path, [options])
Returns a new ReadStream object (See `Readable Stream`).
@@ -448,17 +513,18 @@ An example to read the last 10 bytes of
fs.createReadStream('sample.txt', {start: 90, end: 99});
-## fs.WriteStream
+## Class: fs.ReadStream
-`WriteStream` is a `Writable Stream`.
+`ReadStream` is a [Readable Stream](stream.html#readable_stream).
### Event: 'open'
`function (fd) { }`
- `fd` is the file descriptor used by the WriteStream.
+ `fd` is the file descriptor used by the ReadStream.
+
-### fs.createWriteStream(path, [options])
+## fs.createWriteStream(path, [options])
Returns a new WriteStream object (See `Writable Stream`).
@@ -467,3 +533,45 @@ Returns a new WriteStream object (See `W
{ flags: 'w',
encoding: null,
mode: 0666 }
+
+`options` may also include a `start` option to allow writing data at
+some position past the beginning of the file. Modifying a file rather
+than replacing it may require a `flags` mode of `r+` rather than the
+default mode `w`.
+
+## fs.WriteStream
+
+`WriteStream` is a [Writable Stream](stream.html#writable_stream).
+
+### Event: 'open'
+
+`function (fd) { }`
+
+ `fd` is the file descriptor used by the WriteStream.
+
+### file.bytesWritten
+
+The number of bytes written so far. Does not include data that is still queued
+for writing.
+
+## Class: fs.FSWatcher
+
+Objects returned from `fs.watch()` are of this type.
+
+### watcher.close()
+
+Stop watching for changes on the given `fs.FSWatcher`.
+
+### Event: 'change'
+
+* `event` {String} The type of fs change
+* `filename` {String} The filename that changed (if relevant/available)
+
+Emitted when something changes in a watched directory or file.
+See more details in [fs.watch](#fs.watch).
+
+### Event: 'error'
+
+`function (exception) {}`
+
+Emitted when an error occurs.
diff -upr ./api_v0.4.12/http.markdown ./api_v0.6.12/http.markdown
--- ./api_v0.4.12/http.markdown 2011-09-21 00:45:54.000000000 +0400
+++ ./api_v0.6.12/http.markdown 2012-03-08 01:22:12.000000000 +0400
@@ -1,4 +1,4 @@
-## HTTP
+# HTTP
To use the HTTP server and client one must `require('http')`.
@@ -23,7 +23,14 @@ parsing only. It parses a message into h
parse the actual headers or the body.
-## http.Server
+## http.createServer([requestListener])
+
+Returns a new web server object.
+
+The `requestListener` is a function which is automatically
+added to the `'request'` event.
+
+## Class: http.Server
This is an `EventEmitter` with the following events:
@@ -31,7 +38,7 @@ This is an `EventEmitter` with the follo
`function (request, response) { }`
-Emitted each time there is request. Note that there may be multiple requests
+Emitted each time there is a request. Note that there may be multiple requests
per connection (in the case of keep-alive connections).
`request` is an instance of `http.ServerRequest` and `response` is
an instance of `http.ServerResponse`
@@ -46,7 +53,7 @@ per connection (in the case of keep-aliv
### Event: 'close'
-`function (errno) { }`
+`function () { }`
Emitted when the server closes.
@@ -88,13 +95,6 @@ sent to the server on that socket.
If a client connection emits an 'error' event - it will forwarded here.
-### http.createServer([requestListener])
-
-Returns a new web server object.
-
-The `requestListener` is a function which is automatically
-added to the `'request'` event.
-
### server.listen(port, [hostname], [callback])
Begin accepting connections on the specified port and hostname. If the
@@ -103,40 +103,44 @@ IPv4 address (`INADDR_ANY`).
To listen to a unix socket, supply a filename instead of port and hostname.
-This function is asynchronous. The last parameter `callback` will be called
-when the server has been bound to the port.
+This function is asynchronous. The last parameter `callback` will be added as
+a listener for the ['listening'](net.html#event_listening_) event.
+See also [net.Server.listen()](net.html#server.listen).
### server.listen(path, [callback])
Start a UNIX socket server listening for connections on the given `path`.
-This function is asynchronous. The last parameter `callback` will be called
-when the server has been bound.
+This function is asynchronous. The last parameter `callback` will be added as
+a listener for the ['listening'](net.html#event_listening_) event.
+See also [net.Server.listen()](net.html#server.listen).
### server.close()
Stops the server from accepting new connections.
+See [net.Server.close()](net.html#server.close).
-## http.ServerRequest
+## Class: http.ServerRequest
This object is created internally by a HTTP server -- not by
the user -- and passed as the first argument to a `'request'` listener.
-This is an `EventEmitter` with the following events:
+The request implements the [Readable Stream](stream.html#readable_stream)
+interface. This is an `EventEmitter` with the following events:
### Event: 'data'
`function (chunk) { }`
-Emitted when a piece of the message body is received.
+Emitted when a piece of the message body is received. The chunk is a string if
+an encoding has been set with `request.setEncoding()`, otherwise it's a
+[Buffer](buffer.html).
-Example: A chunk of the body is given as the single
-argument. The transfer-encoding has been decoded. The
-body chunk is a string. The body encoding is set with
-`request.setEncoding()`.
+Note that the __data will be lost__ if there is no listener when a
+`ServerRequest` emits a `'data'` event.
### Event: 'end'
@@ -147,20 +151,11 @@ will be emitted on the request.
### Event: 'close'
-`function (err) { }`
+`function () { }`
Indicates that the underlaying connection was terminated before
`response.end()` was called or able to flush.
-The `err` parameter is always present and indicates the reason for the timeout:
-
-`err.code === 'timeout'` indicates that the underlaying connection timed out.
-This may happen because all incoming connections have a default timeout of 2
-minutes.
-
-`err.code === 'aborted'` means that the client has closed the underlaying
-connection prematurely.
-
Just like `'end'`, this event occurs only once per request, and no more `'data'`
events will fire afterwards.
@@ -222,7 +217,7 @@ Also `request.httpVersionMajor` is the f
`request.httpVersionMinor` is the second.
-### request.setEncoding(encoding=null)
+### request.setEncoding([encoding])
Set the encoding for the request body. Either `'utf8'` or `'binary'`. Defaults
to `null`, which means that the `'data'` event will emit a `Buffer` object..
@@ -248,10 +243,20 @@ authentication details.
-## http.ServerResponse
+## Class: http.ServerResponse
This object is created internally by a HTTP server--not by the user. It is
-passed as the second parameter to the `'request'` event. It is a `Writable Stream`.
+passed as the second parameter to the `'request'` event.
+
+The response implements the [Writable Stream](stream.html#writable_stream)
+interface. This is an `EventEmitter` with the following events:
+
+### Event: 'close'
+
+`function () { }`
+
+Indicates that the underlaying connection was terminated before
+`response.end()` was called or able to flush.
### response.writeContinue()
@@ -302,7 +307,7 @@ status code which was sent out.
### response.setHeader(name, value)
Sets a single header value for implicit headers. If this header already exists
-in the to-be-sent headers, it's value will be replaced. Use an array of strings
+in the to-be-sent headers, its value will be replaced. Use an array of strings
here if you need to send multiple headers with the same name.
Example:
@@ -333,7 +338,7 @@ Example:
response.removeHeader("Content-Encoding");
-### response.write(chunk, encoding='utf8')
+### response.write(chunk, [encoding])
If this method is called and `response.writeHead()` has not been called, it will
switch to implicit header mode and flush the implicit headers.
@@ -367,7 +372,7 @@ Note that HTTP requires the `Trailer` he
emit trailers, with a list of the header fields in its value. E.g.,
response.writeHead(200, { 'Content-Type': 'text/plain',
- 'Trailer': 'TraceInfo' });
+ 'Trailer': 'Content-MD5' });
response.write(fileData);
response.addTrailers({'Content-MD5': "7895bf4b8828b55ceaf47747b4bca667"});
response.end();
@@ -387,21 +392,29 @@ followed by `response.end()`.
## http.request(options, callback)
Node maintains several connections per server to make HTTP requests.
-This function allows one to transparently issue requests.
+This function allows one to transparently issue requests. `options` align
+with [url.parse()](url.html#url.parse).
Options:
- `host`: A domain name or IP address of the server to issue the request to.
-- `port`: Port of remote server.
-- `method`: A string specifying the HTTP request method. Possible values:
- `'GET'` (default), `'POST'`, `'PUT'`, and `'DELETE'`.
-- `path`: Request path. Should include query string and fragments if any.
- E.G. `'/index.html?page=12'`
+ Defaults to `'localhost'`.
+- `hostname`: To support `url.parse()` `hostname` is preferred over `host`
+- `port`: Port of remote server. Defaults to 80.
+- `socketPath`: Unix Domain Socket (use one of host:port or socketPath)
+- `method`: A string specifying the HTTP request method. Defaults to `'GET'`.
+- `path`: Request path. Defaults to `'/'`. Should include query string if any.
+ E.G. `'/index.html?page=12'`
- `headers`: An object containing request headers.
-- `agent`: Controls `Agent` behavior. Possible values:
- - `undefined` (default): use default `Agent` for this host and port.
+- `auth`: Basic authentication i.e. `'user:password'` to compute an
+ Authorization header.
+- `agent`: Controls [Agent](#http.Agent) behavior. When an Agent is used
+ request will default to `Connection: keep-alive`. Possible values:
+ - `undefined` (default): use [global Agent](#http.globalAgent) for this host
+ and port.
- `Agent` object: explicitly use the passed in `Agent`.
- - `false`: explicitly generate a new `Agent` for this host and port. `Agent` will not be re-used.
+ - `false`: opts out of connection pooling with an Agent, defaults request to
+ `Connection: close`.
`http.request()` returns an instance of the `http.ClientRequest`
class. The `ClientRequest` instance is a writable stream. If one needs to
@@ -454,6 +467,9 @@ There are a few special headers that sho
and listen for the `continue` event. See RFC2616 Section 8.2.3 for more
information.
+* Sending an Authorization header will override using the `auth` option
+ to compute basic authentication.
+
## http.get(options, callback)
Since most requests are GET requests without bodies, Node provides this
@@ -475,85 +491,59 @@ Example:
});
-## http.Agent
-## http.getAgent(host, port)
-
-`http.request()` uses a special `Agent` for managing multiple connections to
-an HTTP server. Normally `Agent` instances should not be exposed to user
-code, however in certain situations it's useful to check the status of the
-agent. The `http.getAgent()` function allows you to access the agents.
+## Class: http.Agent
-### Event: 'upgrade'
-
-`function (response, socket, head) { }`
-
-Emitted each time a server responds to a request with an upgrade. If this
-event isn't being listened for, clients receiving an upgrade header will have
-their connections closed.
+In node 0.5.3+ there is a new implementation of the HTTP Agent which is used
+for pooling sockets used in HTTP client requests.
-A client server pair that show you how to listen for the `upgrade` event using `http.getAgent`:
+Previously, a single agent instance help the pool for single host+port. The
+current implementation now holds sockets for any number of hosts.
- var http = require('http');
- var net = require('net');
+The current HTTP Agent also defaults client requests to using
+Connection:keep-alive. If no pending HTTP requests are waiting on a socket
+to become free the socket is closed. This means that node's pool has the
+benefit of keep-alive when under load but still does not require developers
+to manually close the HTTP clients using keep-alive.
+
+Sockets are removed from the agent's pool when the socket emits either a
+"close" event or a special "agentRemove" event. This means that if 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:
- // Create an HTTP server
- var srv = http.createServer(function (req, res) {
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.end('okay');
- });
- srv.on('upgrade', function(req, socket, upgradeHead) {
- socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
- 'Upgrade: WebSocket\r\n' +
- 'Connection: Upgrade\r\n' +
- '\r\n\r\n');
-
- socket.ondata = function(data, start, end) {
- socket.write(data.toString('utf8', start, end), 'utf8'); // echo back
- };
+ http.get(options, function(res) {
+ // Do stuff
+ }).on("socket", function (socket) {
+ socket.emit("agentRemove");
});
- // now that server is running
- srv.listen(1337, '127.0.0.1', function() {
-
- // make a request
- var agent = http.getAgent('127.0.0.1', 1337);
-
- var options = {
- agent: agent,
- port: 1337,
- host: '127.0.0.1',
- headers: {
- 'Connection': 'Upgrade',
- 'Upgrade': 'websocket'
- }
- };
-
- var req = http.request(options);
- req.end();
-
- agent.on('upgrade', function(res, socket, upgradeHead) {
- console.log('got upgraded!');
- socket.end();
- process.exit(0);
- });
- });
+Alternatively, you could just opt out of pooling entirely using `agent:false`:
+ http.get({host:'localhost', port:80, path:'/', agent:false}, function (res) {
+ // Do stuff
+ })
### agent.maxSockets
-By default set to 5. Determines how many concurrent sockets the agent can have open.
+By default set to 5. Determines how many concurrent sockets the agent can have
+open per host.
### agent.sockets
-An array of sockets currently in use by the Agent. Do not modify.
+An object which contains arrays of sockets currently in use by the Agent. Do not
+modify.
+
+### agent.requests
-### agent.queue
+An object which contains queues of requests that have not yet been assigned to
+sockets. Do not modify.
-A queue of requests waiting to be sent to sockets.
+## http.globalAgent
+Global instance of Agent which is used as the default for all http client
+requests.
-## http.ClientRequest
+## Class: http.ClientRequest
This object is created internally and returned from `http.request()`. It
represents an _in-progress_ request whose header has already been queued. The
@@ -590,19 +580,11 @@ event, the entire body will be caught.
}, 10);
});
-This is a `Writable Stream`.
Note: Node does not check whether Content-Length and the length of the body
which has been transmitted are equal or not.
-This is an `EventEmitter` with the following events:
-
-### Event: 'continue'
-
-`function () { }`
-
-Emitted when the server sends a '100 Continue' HTTP response, usually because
-the request contained 'Expect: 100-continue'. This is an instruction that
-the client should send the request body.
+The request implements the [Writable Stream](stream.html#writable_stream)
+interface. This is an `EventEmitter` with the following events:
### Event 'response'
@@ -611,8 +593,79 @@ the client should send the request body.
Emitted when a response is received to this request. This event is emitted only once. The
`response` argument will be an instance of `http.ClientResponse`.
+Options:
+
+- `host`: A domain name or IP address of the server to issue the request to.
+- `port`: Port of remote server.
+- `socketPath`: Unix Domain Socket (use one of host:port or socketPath)
-### request.write(chunk, encoding='utf8')
+### Event: 'socket'
+
+`function (socket) { }`
+
+Emitted after a socket is assigned to this request.
+
+### Event: 'upgrade'
+
+`function (response, socket, head) { }`
+
+Emitted each time a server responds to a request with an upgrade. If this
+event isn't being listened for, clients receiving an upgrade header will have
+their connections closed.
+
+A client server pair that show you how to listen for the `upgrade` event using `http.getAgent`:
+
+ var http = require('http');
+ var net = require('net');
+
+ // Create an HTTP server
+ var srv = http.createServer(function (req, res) {
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ res.end('okay');
+ });
+ srv.on('upgrade', function(req, socket, upgradeHead) {
+ socket.write('HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
+ 'Upgrade: WebSocket\r\n' +
+ 'Connection: Upgrade\r\n' +
+ '\r\n\r\n');
+
+ socket.ondata = function(data, start, end) {
+ socket.write(data.toString('utf8', start, end), 'utf8'); // echo back
+ };
+ });
+
+ // now that server is running
+ srv.listen(1337, '127.0.0.1', function() {
+
+ // make a request
+ var options = {
+ port: 1337,
+ host: '127.0.0.1',
+ headers: {
+ 'Connection': 'Upgrade',
+ 'Upgrade': 'websocket'
+ }
+ };
+
+ var req = http.request(options);
+ req.end();
+
+ req.on('upgrade', function(res, socket, upgradeHead) {
+ console.log('got upgraded!');
+ socket.end();
+ process.exit(0);
+ });
+ });
+
+### Event: 'continue'
+
+`function () { }`
+
+Emitted when the server sends a '100 Continue' HTTP response, usually because
+the request contained 'Expect: 100-continue'. This is an instruction that
+the client should send the request body.
+
+### request.write(chunk, [encoding])
Sends a chunk of the body. By calling this method
many times, the user can stream a request body to a
@@ -620,11 +673,10 @@ server--in that case it is suggested to
`['Transfer-Encoding', 'chunked']` header line when
creating the request.
-The `chunk` argument should be an array of integers
-or a string.
+The `chunk` argument should be a [buffer](buffer.html) or a string.
-The `encoding` argument is optional and only
-applies when `chunk` is a string.
+The `encoding` argument is optional and only applies when `chunk` is a string.
+Defaults to `'utf8'`.
### request.end([data], [encoding])
@@ -633,20 +685,39 @@ Finishes sending the request. If any par
unsent, it will flush them to the stream. If the request is
chunked, this will send the terminating `'0\r\n\r\n'`.
-If `data` is specified, it is equivalent to calling `request.write(data, encoding)`
-followed by `request.end()`.
+If `data` is specified, it is equivalent to calling
+`request.write(data, encoding)` followed by `request.end()`.
### request.abort()
Aborts a request. (New since v0.3.8.)
+### request.setTimeout(timeout, [callback])
+
+Once a socket is assigned to this request and is connected
+[socket.setTimeout(timeout, [callback])](net.html#socket.setTimeout)
+will be called.
+
+### request.setNoDelay([noDelay])
+
+Once a socket is assigned to this request and is connected
+[socket.setNoDelay(noDelay)](net.html#socket.setNoDelay)
+will be called.
+
+### request.setSocketKeepAlive([enable], [initialDelay])
+
+Once a socket is assigned to this request and is connected
+[socket.setKeepAlive(enable, [initialDelay])](net.html#socket.setKeepAlive)
+will be called.
## http.ClientResponse
This object is created when making a request with `http.request()`. It is
passed to the `'response'` event of the request object.
-The response implements the `Readable Stream` interface.
+The response implements the [Readable Stream](stream.html#readable_stream)
+interface. This is an `EventEmitter` with the following events:
+
### Event: 'data'
@@ -654,6 +725,9 @@ The response implements the `Readable St
Emitted when a piece of the message body is received.
+Note that the __data will be lost__ if there is no listener when a
+`ClientResponse` emits a `'data'` event.
+
### Event: 'end'
@@ -690,10 +764,11 @@ The response headers object.
The response trailers object. Only populated after the 'end' event.
-### response.setEncoding(encoding=null)
+### response.setEncoding([encoding])
-Set the encoding for the response body. Either `'utf8'`, `'ascii'`, or `'base64'`.
-Defaults to `null`, which means that the `'data'` event will emit a `Buffer` object..
+Set the encoding for the response body. Either `'utf8'`, `'ascii'`, or
+`'base64'`. Defaults to `null`, which means that the `'data'` event will emit
+a `Buffer` object.
### response.pause()
diff -upr ./api_v0.4.12/https.markdown ./api_v0.6.12/https.markdown
--- ./api_v0.4.12/https.markdown 2011-09-21 00:45:30.000000000 +0400
+++ ./api_v0.6.12/https.markdown 2012-03-08 01:22:12.000000000 +0400
@@ -1,16 +1,16 @@
-## HTTPS
+# HTTPS
HTTPS is the HTTP protocol over TLS/SSL. In Node this is implemented as a
separate module.
-## https.Server
+## Class: https.Server
This class is a subclass of `tls.Server` and emits events same as
`http.Server`. See `http.Server` for more information.
## https.createServer(options, [requestListener])
-Returns a new HTTPS web server object. The `options` is similer to
+Returns a new HTTPS web server object. The `options` is similar to
`tls.createServer()`. The `requestListener` is a function which is
automatically added to the `'request'` event.
@@ -34,7 +34,7 @@ Example:
## https.request(options, callback)
Makes a request to a secure web server.
-Similar options to `http.request()`.
+All options from [http.request()](http.html#http.request) are valid.
Example:
@@ -67,11 +67,69 @@ The options argument has the following o
- port: port of host to request to. Defaults to 443.
- path: Path to request. Default `'/'`.
- method: HTTP request method. Default `'GET'`.
-- key: Private key to use for SSL. Default `null`.
-- cert: Public x509 certificate to use. Default `null`.
-- ca: An authority certificate or array of authority certificates to check
+
+- `host`: A domain name or IP address of the server to issue the request to.
+ Defaults to `'localhost'`.
+- `hostname`: To support `url.parse()` `hostname` is preferred over `host`
+- `port`: Port of remote server. Defaults to 443.
+- `method`: A string specifying the HTTP request method. Defaults to `'GET'`.
+- `path`: Request path. Defaults to `'/'`. Should include query string if any.
+ E.G. `'/index.html?page=12'`
+- `headers`: An object containing request headers.
+- `auth`: Basic authentication i.e. `'user:password'` to compute an
+ Authorization header.
+- `agent`: Controls [Agent](#https.Agent) behavior. When an Agent is
+ used request will default to `Connection: keep-alive`. Possible values:
+ - `undefined` (default): use [globalAgent](#https.globalAgent) for this
+ host and port.
+ - `Agent` object: explicitly use the passed in `Agent`.
+ - `false`: opts out of connection pooling with an Agent, defaults request to
+ `Connection: close`.
+
+The following options from [tls.connect()](tls.html#tls.connect) can also be
+specified. However, a [globalAgent](#https.globalAgent) silently ignores these.
+
+- `key`: Private key to use for SSL. Default `null`.
+- `passphrase`: A string of passphrase for the private key. Default `null`.
+- `cert`: Public x509 certificate to use. Default `null`.
+- `ca`: An authority certificate or array of authority certificates to check
the remote host against.
+In order to specify these options, use a custom `Agent`.
+
+Example:
+
+ var options = {
+ host: 'encrypted.google.com',
+ port: 443,
+ path: '/',
+ method: 'GET',
+ key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
+ cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
+ };
+ options.agent = new https.Agent(options);
+
+ var req = https.request(options, function(res) {
+ ...
+ }
+
+Or does not use an `Agent`.
+
+Example:
+
+ var options = {
+ host: 'encrypted.google.com',
+ port: 443,
+ path: '/',
+ method: 'GET',
+ key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
+ cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
+ agent: false
+ };
+
+ var req = https.request(options, function(res) {
+ ...
+ }
## https.get(options, callback)
@@ -94,5 +152,13 @@ Example:
});
+## Class: https.Agent
+
+An Agent object for HTTPS similar to [http.Agent](http.html#http.Agent).
+See [https.request()](#https.request) for more information.
+
+## https.globalAgent
+Global instance of [https.Agent](#https.Agent) which is used as the default
+for all HTTPS client requests.
diff -upr ./api_v0.4.12/modules.markdown ./api_v0.6.12/modules.markdown
--- ./api_v0.4.12/modules.markdown 2011-09-21 00:45:54.000000000 +0400
+++ ./api_v0.6.12/modules.markdown 2012-03-08 01:22:12.000000000 +0400
@@ -1,4 +1,6 @@
-## Modules
+# Modules
+
+<!--name=module-->
Node has a simple module loading system. In Node, files and modules are in
one-to-one correspondence. As an example, `foo.js` loads the module
@@ -30,7 +32,67 @@ Variables
local to the module will be private. In this example the variable `PI` is
private to `circle.js`.
-### Core Modules
+The module system is implemented in the `require("module")` module.
+
+## Cycles
+
+<!--type=misc-->
+
+When there are circular `require()` calls, a module might not be
+done being executed when it is returned.
+
+Consider this situation:
+
+`a.js`:
+
+ console.log('a starting');
+ exports.done = false;
+ var b = require('./b.js');
+ console.log('in a, b.done = %j', b.done);
+ exports.done = true;
+ console.log('a done');
+
+`b.js`:
+
+ console.log('b starting');
+ exports.done = false;
+ var a = require('./a.js');
+ console.log('in b, a.done = %j', a.done);
+ exports.done = true;
+ console.log('b done');
+
+`main.js`:
+
+ console.log('main starting');
+ var a = require('./a.js');
+ var b = require('./b.js');
+ console.log('in main, a.done=%j, b.done=%j', a.done, b.done);
+
+When `main.js` loads `a.js`, then `a.js` in turn loads `b.js`. At that
+point, `b.js` tries to load `a.js`. In order to prevent an infinite
+loop an **unfinished copy** of the `a.js` exports object is returned to the
+`b.js` module. `b.js` then finishes loading, and its exports object is
+provided to the `a.js` module.
+
+By the time `main.js` has loaded both modules, they're both finished.
+The output of this program would thus be:
+
+ $ node main.js
+ main starting
+ a starting
+ b starting
+ in b, a.done = false
+ b done
+ in a, b.done = true
+ a done
+ in main, a.done=true, b.done=true
+
+If you have cyclic module dependencies in your program, make sure to
+plan accordingly.
+
+## Core Modules
+
+<!--type=misc-->
Node has several modules compiled into the binary. These modules are
described in greater detail elsewhere in this documentation.
@@ -41,13 +103,16 @@ Core modules are always preferentially l
passed to `require()`. For instance, `require('http')` will always
return the built in HTTP module, even if there is a file by that name.
-### File Modules
+## File Modules
+
+<!--type=misc-->
If the exact filename is not found, then node will attempt to load the
-required filename with the added extension of `.js`, and then `.node`.
+required filename with the added extension of `.js`, `.json`, and then `.node`.
-`.js` files are interpreted as JavaScript text files, and `.node` files
-are interpreted as compiled addon modules loaded with `dlopen`.
+`.js` files are interpreted as JavaScript text files, and `.json` files are
+parsed as JSON text files. `.node` files are interpreted as compiled addon
+modules loaded with `dlopen`.
A module prefixed with `'/'` is an absolute path to the file. For
example, `require('/home/marco/foo.js')` will load the file at
@@ -60,7 +125,9 @@ That is, `circle.js` must be in the same
Without a leading '/' or './' to indicate a file, the module is either a
"core module" or is loaded from a `node_modules` folder.
-### Loading from `node_modules` Folders
+## Loading from `node_modules` Folders
+
+<!--type=misc-->
If the module identifier passed to `require()` is not a native module,
and does not begin with `'/'`, `'../'`, or `'./'`, then node starts at the
@@ -82,7 +149,9 @@ this order:
This allows programs to localize their dependencies, so that they do not
clash.
-### Folders as Modules
+## Folders as Modules
+
+<!--type=misc-->
It is convenient to organize programs and libraries into self-contained
directories, and then provide a single entry point to that library.
@@ -110,7 +179,9 @@ example, then `require('./some-library')
* `./some-library/index.js`
* `./some-library/index.node`
-### Caching
+## Caching
+
+<!--type=misc-->
Modules are cached after the first time they are loaded. This means
(among other things) that every call to `require('foo')` will get
@@ -124,7 +195,9 @@ dependencies to be loaded even when they
If you want to have a module execute code multiple times, then export a
function, and call that function.
-#### Module Caching Caveats
+### Module Caching Caveats
+
+<!--type=misc-->
Modules are cached based on their resolved filename. Since modules may
resolve to a different filename based on the location of the calling
@@ -132,8 +205,22 @@ module (loading from `node_modules` fold
that `require('foo')` will always return the exact same object, if it
would resolve to different files.
+## The `module` Object
+
+<!-- type=var -->
+<!-- name=module -->
+