• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright Joyent, Inc. and other Node contributors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a
4// copy of this software and associated documentation files (the
5// "Software"), to deal in the Software without restriction, including
6// without limitation the rights to use, copy, modify, merge, publish,
7// distribute, sublicense, and/or sell copies of the Software, and to permit
8// persons to whom the Software is furnished to do so, subject to the
9// following conditions:
10//
11// The above copyright notice and this permission notice shall be included
12// in all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22'use strict';
23
24const {
25  ObjectDefineProperty,
26} = primordials;
27
28const httpAgent = require('_http_agent');
29const { ClientRequest } = require('_http_client');
30const { methods } = require('_http_common');
31const { IncomingMessage } = require('_http_incoming');
32const { OutgoingMessage } = require('_http_outgoing');
33const {
34  _connectionListener,
35  STATUS_CODES,
36  Server,
37  ServerResponse
38} = require('_http_server');
39let maxHeaderSize;
40
41function createServer(opts, requestListener) {
42  return new Server(opts, requestListener);
43}
44
45function request(url, options, cb) {
46  return new ClientRequest(url, options, cb);
47}
48
49function get(url, options, cb) {
50  const req = request(url, options, cb);
51  req.end();
52  return req;
53}
54
55module.exports = {
56  _connectionListener,
57  METHODS: methods.slice().sort(),
58  STATUS_CODES,
59  Agent: httpAgent.Agent,
60  ClientRequest,
61  IncomingMessage,
62  OutgoingMessage,
63  Server,
64  ServerResponse,
65  createServer,
66  get,
67  request
68};
69
70ObjectDefineProperty(module.exports, 'maxHeaderSize', {
71  configurable: true,
72  enumerable: true,
73  get() {
74    if (maxHeaderSize === undefined) {
75      const { getOptionValue } = require('internal/options');
76      maxHeaderSize = getOptionValue('--max-http-header-size');
77    }
78
79    return maxHeaderSize;
80  }
81});
82
83ObjectDefineProperty(module.exports, 'globalAgent', {
84  configurable: true,
85  enumerable: true,
86  get() {
87    return httpAgent.globalAgent;
88  },
89  set(value) {
90    httpAgent.globalAgent = value;
91  }
92});
93