summaryrefslogtreecommitdiff
path: root/lib/http.js
Commit message (Collapse)AuthorAgeFilesLines
* http: refactor to use more primordialsAntoine du Hamel2020-12-291-1/+3
| | | | | | PR-URL: https://github.com/nodejs/node/pull/36194 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
* http: tidy up exposure of header validationOsher2020-05-251-2/+5
| | | | | | | | PR-URL: https://github.com/nodejs/node/pull/33371 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
* http: expose http.validate-header-name/valueosher2020-05-091-0/+3
| | | | | | | | | | | | The use-case is for any framework that provides user mw a response replacement, that collects the desired response state, and applies them only on conclusion. As such a framework, I'd want to validate the header names and values as soon as the user-code provides them. This - to eliminate errors on response-send time, and provide developer stack trace that contains the line that submits the offending values. PR-URL: https://github.com/nodejs/node/pull/33119 Reviewed-By: Anna Henningsen <anna@addaleax.net>
* lib: flatten access to primordialsMichaël Zasso2019-11-251-3/+5
| | | | | | | | | | | | | | Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
* lib: enforce the use of Object from primordialsMichaël Zasso2019-04-121-0/+2
| | | | | | | | | | | PR-URL: https://github.com/nodejs/node/pull/27146 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
* benchmark,lib: change var to constRuben Bridgewater2019-03-301-1/+1
| | | | | | | | | Refs: https://github.com/nodejs/node/pull/26679 PR-URL: https://github.com/nodejs/node/pull/26915 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com>
* lib: support overriding http\s.globalAgentRoy Sommer2019-01-081-3/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | Overriding `require('http[s]').globalAgent` is now respected by consequent requests. In order to achieve that, the following changes were made: 1. Implmentation in `http`: `module.exports.globalAgent` is now defined through `Object.defineProperty`. Its getter and setter return \ set `require('_http_agent').globalAgent`. 2. Implementation in `https`: the https `globalAgent` is not the same as `_http_agent`, and is defined in `https` module itself. Therefore, the fix here was to simply use `module.exports.globalAgent` to support mutation. 3. According tests were added for both `http` and `https`, where in both we create a server, set the default agent to a newly created instance and make a request to that server. We then assert that the given instance was actually used by inspecting its sockets property. Fixes: https://github.com/nodejs/node/issues/23281 PR-URL: https://github.com/nodejs/node/pull/25170 Reviewed-By: James M Snell <jasnell@gmail.com>
* http: add maxHeaderSize propertycjihrig2018-12-201-0/+14
| | | | | | | | | | | | This commit exposes the value of --max-http-header-size as a property of the http module. PR-URL: https://github.com/nodejs/node/pull/24860 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* http: allow url and options to be passed to http*.request and http*.getSam Ruby2018-07-131-4/+4
| | | | | | | | | Fixes: https://github.com/nodejs/node/issues/20795 PR-URL: https://github.com/nodejs/node/pull/21616 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
* http: support server options on createServerWes Todd2018-03-251-2/+2
| | | | | | | | PR-URL: https://github.com/nodejs/node/pull/19461 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
* http: use more destructuringTobias Nießen2018-03-221-15/+18
| | | | | | | | PR-URL: https://github.com/nodejs/node/pull/19481 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jackson Tian <shyvo1987@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
* lib: use destructuring for some constantsWeijia Wang2017-10-161-3/+2
| | | | | | | | | | | | | This change is to unify the declaration for constants into using destructuring on the top-level-module scope, reducing some redundant code. PR-URL: https://github.com/nodejs/node/pull/16063 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
* http: use more efficient module.exports patternJames M Snell2017-03-201-21/+29
| | | | | | | PR-URL: https://github.com/nodejs/node/pull/11594 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
* meta: restore original copyright headerJames M Snell2017-03-101-0/+21
| | | | | | | | | | | | | | | A prior io.js era commit inappropriately removed the original copyright statements from the source. This restores those in any files still remaining from that edit. Ref: https://github.com/nodejs/TSC/issues/174 Ref: https://github.com/nodejs/node/pull/10599 PR-URL: https://github.com/nodejs/node/pull/10155 Note: This PR was required, reviewed-by and approved by the Node.js Foundation Legal Committee and the TSC. There is no `Approved-By:` meta data.
* http: name anonymous functions in httpmaasencioh2016-10-181-3/+3
| | | | | | | | | Refs: https://github.com/nodejs/node/issues/8913 PR-URL: https://github.com/nodejs/node/pull/9055 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
* http: remove deprecated Client interfaceBrian White2016-08-291-76/+10
| | | | | | | PR-URL: https://github.com/nodejs/node/pull/8104 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
* lib,src: remove usage of events.EventEmitterSakthipriyan Vairamani2015-09-231-1/+1
| | | | | | | | | | | The `events` module already exports `EventEmitter` constructor function So, we don't have to use `events.EventEmitter` to access it. Refer: https://github.com/nodejs/node/pull/2896 PR-URL: https://github.com/nodejs/node/pull/2921 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Michaël Zasso <mic.besace@gmail.com>
* util: prepend '(node) ' to deprecation messagesSakthipriyan Vairamani2015-07-031-4/+4
| | | | | | | | | | | | | | | | | | | Changes included in this commit are 1. Making the deprecation messages consistent. The messages will be in the following format x is deprecated. Use y instead. If there is no alternative for `x`, then the ` Use y instead.` part will not be there in the message. 2. All the internal deprecation messages are printed with the prefix `(node) `, except when the `--trace-deprecation` flag is set. Fixes: https://github.com/nodejs/io.js/issues/1883 PR-URL: https://github.com/nodejs/io.js/pull/1892 Reviewed-By: Roman Reiss <me@silverwind.io>
* http: replace util._extend() with [].slice()Jonathan Ong2015-02-021-1/+1
| | | | | | | PR-URL: https://github.com/iojs/io.js/pull/634 Reviewed-BY: Nicu Micleușanu <micnic90@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
* lib: use const to define constantscjihrig2015-01-211-9/+9
| | | | | | | | This commit replaces a number of var statements throughout the lib code with const statements. PR-URL: https://github.com/iojs/io.js/pull/541 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
* Remove excessive copyright/license boilerplateisaacs2015-01-121-21/+0
| | | | | | | The copyright and license notice is already in the LICENSE file. There is no justifiable reason to also require that it be included in every file, since the individual files are not individually distributed except as part of the entire package.
* lib: turn on strict modeBen Noordhuis2014-11-221-0/+2
| | | | | | | | | Turn on strict mode for the files in the lib/ directory. It helps catch bugs and can have a positive effect on performance. PR-URL: https://github.com/node-forward/node/pull/64 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
* lib: unexport http.parsersBen Noordhuis2014-09-051-1/+0
| | | | | | | | | | | | | | | Unexport the http.parsers freelist. It was originally exported by Ryan in commit 0003c701 but the commit log doesn't mention why and it's never been documented. It's unclear if there are any users. The lifecycle of parser objects changed recently and it seems better to not let people shoot themselves in the foot so easily. If it turns out there are actually users, we can always re-export it again - probably under a slightly different name, to force people to update their code to the new way of things. Reviewed-by: Trevor Norris <trev.norris@gmail.com>
* lib: remove unused variablesBrian White2014-06-111-5/+3
| | | | Signed-off-by: Fedor Indutny <fedor@indutny.com>
* http, https: don't depend on `globalAgent`Nathan Rajlich2014-02-261-2/+4
| | | | | | | | | | | | | | For the `request()` and `get()` functions. I could never really understand why these two functions go through agent first... Especially since the user could be passing `agent: false` or a different Agent instance completely, in which `globalAgent` will be completely bypassed. Moved the relevant logic from `Agent#request()` into the `ClientRequest` constructor. Incidentally, this commit fixes #7012 (which was the original intent of this commit).
* http: expose supported methodsBen Noordhuis2013-10-281-0/+1
| | | | | | | Expose the list of supported HTTP methods as a property on the 'http' module object. Fixes #6422.
* lib: remove unused variables and functionsBrian White2013-08-151-3/+1
|
* http: Fix overlooked agent.globalAgent exportisaacs2013-08-051-2/+1
| | | | Noticed by @bnoordhuis in https://github.com/joyent/node/pull/5991#discussion_r5575946
* http: Add agent.get/request methodsisaacs2013-07-091-24/+4
|
* http: don't escape request path, reject bad charsBen Noordhuis2013-05-151-5/+8
| | | | | | | | | | | | | | | Commit 38149bb changes http.get() and http.request() to escape unsafe characters. However, that creates an incompatibility with v0.10 that is difficult to work around: if you escape the path manually, then in v0.11 it gets escaped twice. Change lib/http.js so it no longer tries to fix up bad request paths, simply reject them with an exception. The actual check is rather basic right now. The full check for illegal characters is difficult to implement efficiently because it requires a few characters of lookahead. That's why it currently only checks for spaces because those are guaranteed to create an invalid request. Fixes #5474.
* http: split Client into _http_client.jsTimothy J Fontaine2013-04-171-460/+2
|
* http: move Server and ServerResponse outTimothy J Fontaine2013-04-171-428/+6
|
* http: move OutgoingMessage into it's own fileTimothy J Fontaine2013-04-171-614/+6
|
* http: move parsers into _http_common.jsTimothy J Fontaine2013-04-171-180/+3
|
* http: move IncomingMessage into its own fileTimothy J Fontaine2013-04-171-153/+4
|
* http: split Agent into its own fileTimothy J Fontaine2013-04-171-130/+3
|
* http: escape unsafe characters in request pathBen Noordhuis2013-04-121-0/+5
| | | | | | | | | | Make http.request() and friends escape unsafe characters in the request path. That is, a request for '/foo bar' is now escaped as '/foo%20bar'. Before this commit, the path was used as-is in the request status line, creating an invalid HTTP request ("GET /foo bar HTTP/1.1"). Fixes #4381.
* http: Support write(data, 'hex')isaacs2013-04-081-3/+6
| | | | | | | | We were assuming that any string can be concatenated safely to CRLF. However, for hex, base64, or binary encoded writes, this is not the case, and results in sending the incorrect response. An unusual edge case, but certainly a bug.
* http: Remove legacy ECONNRESET workaround codeisaacs2013-04-031-17/+1
| | | | Fix #5179
* http client: Ensure socket cleanup on response endisaacs2013-04-021-2/+8
| | | | | | | | | | | | | | | | | | If an http response has an 'end' handler that throws, then the socket will never be released back into the pool. Granted, we do NOT guarantee that throwing will never have adverse effects on Node internal state. Such a guarantee cannot be reasonably made in a shared-global mutable-state side-effecty language like JavaScript. However, in this case, it's a rather trivial patch to increase our resilience a little bit, so it seems like a win. There is no semantic change in this case, except that some event listeners are removed, and the `'free'` event is emitted on nextTick, so that you can schedule another request which will re-use the same socket. From the user's point of view, there should be no detectable difference. Closes #5107
* http: Don't hot-path end() for large buffersisaacs2013-03-141-0/+8
| | | | | | | | | | | | The benefits of the hot-path optimization below start to fall off when the buffer size gets up near 128KB, because the cost of the copy is more than the cost of the extra write() call. Switch to the write/end method at that point. Heuristics and magic numbers are awful, but slow http responses are worse. Fix #4975
* stream: Don't emit 'end' unless read() calledisaacs2013-03-101-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This solves the problem of calling `readable.pipe(writable)` after the readable stream has already emitted 'end', as often is the case when writing simple HTTP proxies. The spirit of streams2 is that things will work properly, even if you don't set them up right away on the first tick. This approach breaks down, however, because pipe()ing from an ended readable will just do nothing. No more data will ever arrive, and the writable will hang open forever never being ended. However, that does not solve the case of adding a `on('end')` listener after the stream has received the EOF chunk, if it was the first chunk received (and thus, length was 0, and 'end' got emitted). So, with this, we defer the 'end' event emission until the read() function is called. Also, in pipe(), if the source has emitted 'end' already, we call the cleanup/onend function on nextTick. Piping from an already-ended stream is thus the same as piping from a stream that is in the process of ending. Updates many tests that were relying on 'end' coming immediately, even though they never read() from the req. Fix #4942
* http: ServerRequest does not timeout after 'end'koichik2013-03-101-1/+1
| | | | Fixes #4967
* http: Do not setTimeout a not-yet-existent socketisaacs2013-03-101-1/+10
| | | | Fixes #4967
* http: check if incoming parser has already been freedhc2013-03-091-1/+1
| | | | | | | | | | | Fix #4948 This adds a check before setting the incoming parser to null. Under certain circumstances it'll already be set to null by freeParser(). Otherwise this will cause node to crash as it tries to set null on something that is already null.
* Revert "http: check if incoming parser has already been freed"isaacs2013-03-081-1/+1
| | | | This reverts commit 9f4c3b0d45f858d3d3021ef4b8edebf6005008ff.
* http: check if incoming parser has already been freedhheennrryy@gmail.com2013-03-081-1/+1
| | | | | | | | | | | Fix #4948 This adds a check before setting the incoming parser to null. Under certain circumstances it'll already be set to null by freeParser(). Otherwise this will cause node to crash as it tries to set null on something that is already null.
* http: More useful setTimeout API on serverisaacs2013-03-061-3/+37
| | | | | | | | | | | | | | | | | | | | | | | This adds the following to HTTP: * server.setTimeout(msecs, callback) Sets all new connections to time out after the specified time, at which point it emits 'timeout' on the server, passing the socket as an argument. In this way, timeouts can be handled in one place consistently. * req.setTimeout(), res.setTimeout() Essentially an alias to req/res.socket.setTimeout(), but without having to delve into a "buried" object. Adds a listener on the req/res object, but not on the socket. * server.timeout Number of milliseconds before incoming connections time out. (Default=1000*60*2, as before.) Furthermore, if the user sets up their own timeout listener on either the server, the request, or the response, then the default behavior (destroying the socket) is suppressed. Fix #3460
* http: fix multiple timeout eventsEugene Girshov2013-03-061-2/+5
| | | | | Fixed up slightly by @isaacs so as not to miss 'timeout' events in some cases.
* Merge remote-tracking branch 'origin/v0.8'Ben Noordhuis2013-03-021-1/+1
|\ | | | | | | | | | | Conflicts: doc/api/http.markdown test/simple/test-crypto.js