Sophie

Sophie

distrib > Mageia > 6 > x86_64 > by-pkgid > 4642cf16cdfb16e1cdaefd0999c41911 > files > 71

nodejs-docs-6.17.1-8.mga6.noarch.rpm

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>HTTPS | Node.js v6.17.1 Documentation</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic">
  <link rel="stylesheet" href="assets/style.css">
  <link rel="stylesheet" href="assets/sh.css">
  <link rel="canonical" href="https://nodejs.org/api/https.html">
</head>
<body class="alt apidoc" id="api-section-https">
  <div id="content" class="clearfix">
    <div id="column2" class="interior">
      <div id="intro" class="interior">
        <a href="/" title="Go back to the home page">
          Node.js
        </a>
      </div>
      <ul>
<li><a class="nav-documentation" href="documentation.html">About these Docs</a></li>
<li><a class="nav-synopsis" href="synopsis.html">Usage &amp; Example</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-assert" href="assert.html">Assertion Testing</a></li>
<li><a class="nav-buffer" href="buffer.html">Buffer</a></li>
<li><a class="nav-addons" href="addons.html">C++ Addons</a></li>
<li><a class="nav-n-api" href="n-api.html">C/C++ Addons - N-API</a></li>
<li><a class="nav-child_process" href="child_process.html">Child Processes</a></li>
<li><a class="nav-cluster" href="cluster.html">Cluster</a></li>
<li><a class="nav-cli" href="cli.html">Command Line Options</a></li>
<li><a class="nav-console" href="console.html">Console</a></li>
<li><a class="nav-crypto" href="crypto.html">Crypto</a></li>
<li><a class="nav-debugger" href="debugger.html">Debugger</a></li>
<li><a class="nav-dns" href="dns.html">DNS</a></li>
<li><a class="nav-domain" href="domain.html">Domain</a></li>
<li><a class="nav-errors" href="errors.html">Errors</a></li>
<li><a class="nav-events" href="events.html">Events</a></li>
<li><a class="nav-fs" href="fs.html">File System</a></li>
<li><a class="nav-globals" href="globals.html">Globals</a></li>
<li><a class="nav-http" href="http.html">HTTP</a></li>
<li><a class="nav-https active" href="https.html">HTTPS</a></li>
<li><a class="nav-intl" href="intl.html">Internationalization</a></li>
<li><a class="nav-modules" href="modules.html">Modules</a></li>
<li><a class="nav-net" href="net.html">Net</a></li>
<li><a class="nav-os" href="os.html">OS</a></li>
<li><a class="nav-path" href="path.html">Path</a></li>
<li><a class="nav-process" href="process.html">Process</a></li>
<li><a class="nav-punycode" href="punycode.html">Punycode</a></li>
<li><a class="nav-querystring" href="querystring.html">Query Strings</a></li>
<li><a class="nav-readline" href="readline.html">Readline</a></li>
<li><a class="nav-repl" href="repl.html">REPL</a></li>
<li><a class="nav-stream" href="stream.html">Stream</a></li>
<li><a class="nav-string_decoder" href="string_decoder.html">String Decoder</a></li>
<li><a class="nav-timers" href="timers.html">Timers</a></li>
<li><a class="nav-tls" href="tls.html">TLS/SSL</a></li>
<li><a class="nav-tty" href="tty.html">TTY</a></li>
<li><a class="nav-dgram" href="dgram.html">UDP/Datagram</a></li>
<li><a class="nav-url" href="url.html">URL</a></li>
<li><a class="nav-util" href="util.html">Utilities</a></li>
<li><a class="nav-v8" href="v8.html">V8</a></li>
<li><a class="nav-vm" href="vm.html">VM</a></li>
<li><a class="nav-zlib" href="zlib.html">ZLIB</a></li>
</ul>
<div class="line"></div>

<ul>
<li><a class="nav-https-github-com-nodejs-node" href="https://github.com/nodejs/node">GitHub Repo &amp; Issue Tracker</a></li>
<li><a class="nav-http-groups-google-com-group-nodejs" href="http://groups.google.com/group/nodejs">Mailing List</a></li>
</ul>

    </div>

    <div id="column1" data-id="https" class="interior">
      <header>
        <h1>Node.js v6.17.1 Documentation</h1>
        <div id="gtoc">
          <ul>
            <li>
              <a href="index.html" name="toc">Index</a>
            </li>
            <li>
              <a href="all.html">View on single page</a>
            </li>
            <li>
              <a href="https.json">View as JSON</a>
            </li>
            
    <li class="version-picker">
      <a href="#">View another version <span>&#x25bc;</span></a>
      <ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v9.x/api/https.html">9.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v8.x/api/https.html">8.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v7.x/api/https.html">7.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v6.x/api/https.html">6.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v5.x/api/https.html">5.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v4.x/api/https.html">4.x <b>LTS</b></a></li>
<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/https.html">0.12.x</a></li>
<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/https.html">0.10.x</a></li></ol>
    </li>
  
          </ul>
        </div>
        <hr>
      </header>

      <div id="toc">
        <h2>Table of Contents</h2>
        <ul>
<li><span class="stability_2"><a href="#https_https">HTTPS</a></span><ul>
<li><span class="stability_undefined"><a href="#https_class_https_agent">Class: https.Agent</a></span></li>
<li><span class="stability_undefined"><a href="#https_class_https_server">Class: https.Server</a></span><ul>
<li><span class="stability_undefined"><a href="#https_server_headerstimeout">server.headersTimeout</a></span></li>
<li><span class="stability_undefined"><a href="#https_server_settimeout_msecs_callback">server.setTimeout([msecs][, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#https_server_timeout_msecs">server.timeout([msecs])</a></span></li>
<li><span class="stability_undefined"><a href="#https_server_keepalivetimeout">server.keepAliveTimeout</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#https_https_createserver_options_requestlistener">https.createServer(options[, requestListener])</a></span><ul>
<li><span class="stability_undefined"><a href="#https_server_close_callback">server.close([callback])</a></span></li>
<li><span class="stability_undefined"><a href="#https_server_listen_handle_callback">server.listen(handle[, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#https_server_listen_path_callback">server.listen(path[, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#https_server_listen_port_host_backlog_callback">server.listen([port][, host][, backlog][, callback])</a></span></li>
</ul>
</li>
<li><span class="stability_undefined"><a href="#https_https_get_options_callback">https.get(options[, callback])</a></span></li>
<li><span class="stability_undefined"><a href="#https_https_globalagent">https.globalAgent</a></span></li>
<li><span class="stability_undefined"><a href="#https_https_request_options_callback">https.request(options[, callback])</a></span></li>
</ul>
</li>
</ul>

      </div>

      <div id="apicontent">
        <h1>HTTPS<span><a class="mark" href="#https_https"id="https_https">#</a></span></h1>
<!--introduced_in=v0.10.0-->
<div class="api_stability api_stability_2"><a href="documentation.html#documentation_stability_index">Stability: 2</a> - Stable</div><p>HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a
separate module.</p>
<h2>Class: https.Agent<span><a class="mark" href="#https_class_https_agent"id="https_class_https_agent">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.4.5</span>
</div><p>An Agent object for HTTPS similar to <a href="http.html#http_class_http_agent"><code>http.Agent</code></a>. See <a href="#https_https_request_options_callback"><code>https.request()</code></a>
for more information.</p>
<h2>Class: https.Server<span><a class="mark" href="#https_class_https_server"id="https_class_https_server">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.3.4</span>
</div><p>This class is a subclass of <code>tls.Server</code> and emits events same as
<a href="http.html#http_class_http_server"><code>http.Server</code></a>. See <a href="http.html#http_class_http_server"><code>http.Server</code></a> for more information.</p>
<h3>server.headersTimeout<span><a class="mark" href="#https_server_headerstimeout"id="https_server_headerstimeout">#</a></span></h3>
<div class="signature"><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> <strong>Default:</strong> <code>40000</code></li>
</ul>
</div><p>See <a href="http.html#http_server_headerstimeout"><code>http.Server#headersTimeout</code></a>.</p>
<h3>server.setTimeout([msecs][, callback])<span><a class="mark" href="#https_server_settimeout_msecs_callback"id="https_server_settimeout_msecs_callback">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.11.2</span>
</div><ul>
<li><code>msecs</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> Defaults to 120000 (2 minutes).</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>See <a href="http.html#http_server_settimeout_msecs_callback"><code>http.Server#setTimeout()</code></a>.</p>
<h3>server.timeout([msecs])<span><a class="mark" href="#https_server_timeout_msecs"id="https_server_timeout_msecs">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.11.2</span>
</div><ul>
<li><code>msecs</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> Defaults to 120000 (2 minutes).</li>
</ul>
<p>See <a href="http.html#http_server_timeout"><code>http.Server#timeout</code></a>.</p>
<h3>server.keepAliveTimeout<span><a class="mark" href="#https_server_keepalivetimeout"id="https_server_keepalivetimeout">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v6.17.0</span>
</div><ul>
<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a> Defaults to 5000 (5 seconds).</li>
</ul>
<p>See <a href="http.html#http_server_keepalivetimeout"><code>http.Server#keepAliveTimeout</code></a>.</p>
<h2>https.createServer(options[, requestListener])<span><a class="mark" href="#https_https_createserver_options_requestlistener"id="https_https_createserver_options_requestlistener">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.3.4</span>
</div><ul>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> Accepts <code>options</code> from <a href="tls.html#tls_tls_createserver_options_secureconnectionlistener"><code>tls.createServer()</code></a> and <a href="tls.html#tls_tls_createsecurecontext_options"><code>tls.createSecureContext()</code></a>.</li>
<li><code>requestListener</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a> A listener to be added to the <code>request</code> event.</li>
</ul>
<p>Example:</p>
<pre><code class="lang-js">// curl -k https://localhost:8000/
const https = require(&#39;https&#39;);
const fs = require(&#39;fs&#39;);

const options = {
  key: fs.readFileSync(&#39;test/fixtures/keys/agent2-key.pem&#39;),
  cert: fs.readFileSync(&#39;test/fixtures/keys/agent2-cert.pem&#39;)
};

https.createServer(options, (req, res) =&gt; {
  res.writeHead(200);
  res.end(&#39;hello world\n&#39;);
}).listen(8000);
</code></pre>
<p>Or</p>
<pre><code class="lang-js">const https = require(&#39;https&#39;);
const fs = require(&#39;fs&#39;);

const options = {
  pfx: fs.readFileSync(&#39;test/fixtures/test_cert.pfx&#39;),
  passphrase: &#39;sample&#39;
};

https.createServer(options, (req, res) =&gt; {
  res.writeHead(200);
  res.end(&#39;hello world\n&#39;);
}).listen(8000);
</code></pre>
<h3>server.close([callback])<span><a class="mark" href="#https_server_close_callback"id="https_server_close_callback">#</a></span></h3>
<div class="api_metadata">
<span>Added in: v0.1.90</span>
</div><ul>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>See <a href="http.html#http_server_close_callback"><code>http.close()</code></a> for details.</p>
<h3>server.listen(handle[, callback])<span><a class="mark" href="#https_server_listen_handle_callback"id="https_server_listen_handle_callback">#</a></span></h3>
<div class="signature"><ul>
<li><code>handle</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
</div><h3>server.listen(path[, callback])<span><a class="mark" href="#https_server_listen_path_callback"id="https_server_listen_path_callback">#</a></span></h3>
<div class="signature"><ul>
<li><code>path</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
</div><h3>server.listen([port][, host][, backlog][, callback])<span><a class="mark" href="#https_server_listen_port_host_backlog_callback"id="https_server_listen_port_host_backlog_callback">#</a></span></h3>
<div class="signature"><ul>
<li><code>port</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>hostname</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a></li>
<li><code>backlog</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&lt;number&gt;</a></li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
</div><p>See <a href="http.html#http_server_listen_port_hostname_backlog_callback"><code>http.listen()</code></a> for details.</p>
<h2>https.get(options[, callback])<span><a class="mark" href="#https_https_get_options_callback"id="https_https_get_options_callback">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.3.6</span>
</div><ul>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Accepts the same <code>options</code> as
<a href="#https_https_request_options_callback"><code>https.request()</code></a>, with the <code>method</code> always set to <code>GET</code>.</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>Like <a href="http.html#http_http_get_options_callback"><code>http.get()</code></a> but for HTTPS.</p>
<p><code>options</code> can be an object or a string. If <code>options</code> is a string, it is
automatically parsed with <a href="url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost"><code>url.parse()</code></a>.</p>
<p>Example:</p>
<pre><code class="lang-js">const https = require(&#39;https&#39;);

https.get(&#39;https://encrypted.google.com/&#39;, (res) =&gt; {
  console.log(&#39;statusCode:&#39;, res.statusCode);
  console.log(&#39;headers:&#39;, res.headers);

  res.on(&#39;data&#39;, (d) =&gt; {
    process.stdout.write(d);
  });

}).on(&#39;error&#39;, (e) =&gt; {
  console.error(e);
});
</code></pre>
<h2>https.globalAgent<span><a class="mark" href="#https_https_globalagent"id="https_https_globalagent">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.5.9</span>
</div><p>Global instance of <a href="#https_class_https_agent"><code>https.Agent</code></a> for all HTTPS client requests.</p>
<h2>https.request(options[, callback])<span><a class="mark" href="#https_https_request_options_callback"id="https_https_request_options_callback">#</a></span></h2>
<div class="api_metadata">
<span>Added in: v0.3.6</span>
</div><ul>
<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&lt;Object&gt;</a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&lt;string&gt;</a> Accepts all <code>options</code> from <a href="http.html#http_http_request_options_callback"><code>http.request()</code></a>,
with some differences in default values:<ul>
<li><code>protocol</code> Defaults to <code>https:</code></li>
<li><code>port</code> Defaults to <code>443</code>.</li>
<li><code>agent</code> Defaults to <code>https.globalAgent</code>.</li>
</ul>
</li>
<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&lt;Function&gt;</a></li>
</ul>
<p>Makes a request to a secure web server.</p>
<p>The following additional <code>options</code> from <a href="tls.html#tls_tls_connect_options_callback"><code>tls.connect()</code></a> are also accepted when using a
  custom <a href="#https_class_https_agent"><code>Agent</code></a>:
  <code>pfx</code>, <code>key</code>, <code>passphrase</code>, <code>cert</code>, <code>ca</code>, <code>ciphers</code>, <code>rejectUnauthorized</code>, <code>secureProtocol</code>, <code>servername</code></p>
<p><code>options</code> can be an object or a string. If <code>options</code> is a string, it is
automatically parsed with <a href="url.html#url_url_parse_urlstring_parsequerystring_slashesdenotehost"><code>url.parse()</code></a>.</p>
<p>Example:</p>
<pre><code class="lang-js">const https = require(&#39;https&#39;);

const options = {
  hostname: &#39;encrypted.google.com&#39;,
  port: 443,
  path: &#39;/&#39;,
  method: &#39;GET&#39;
};

const req = https.request(options, (res) =&gt; {
  console.log(&#39;statusCode:&#39;, res.statusCode);
  console.log(&#39;headers:&#39;, res.headers);

  res.on(&#39;data&#39;, (d) =&gt; {
    process.stdout.write(d);
  });
});

req.on(&#39;error&#39;, (e) =&gt; {
  console.error(e);
});
req.end();
</code></pre>
<p>Example using options from <a href="tls.html#tls_tls_connect_options_callback"><code>tls.connect()</code></a>:</p>
<pre><code class="lang-js">const options = {
  hostname: &#39;encrypted.google.com&#39;,
  port: 443,
  path: &#39;/&#39;,
  method: &#39;GET&#39;,
  key: fs.readFileSync(&#39;test/fixtures/keys/agent2-key.pem&#39;),
  cert: fs.readFileSync(&#39;test/fixtures/keys/agent2-cert.pem&#39;)
};
options.agent = new https.Agent(options);

const req = https.request(options, (res) =&gt; {
  // ...
});
</code></pre>
<p>Alternatively, opt out of connection pooling by not using an <code>Agent</code>.</p>
<p>Example:</p>
<pre><code class="lang-js">const options = {
  hostname: &#39;encrypted.google.com&#39;,
  port: 443,
  path: &#39;/&#39;,
  method: &#39;GET&#39;,
  key: fs.readFileSync(&#39;test/fixtures/keys/agent2-key.pem&#39;),
  cert: fs.readFileSync(&#39;test/fixtures/keys/agent2-cert.pem&#39;),
  agent: false
};

const req = https.request(options, (res) =&gt; {
  // ...
});
</code></pre>

      </div>
    </div>
  </div>
  <script src="assets/sh_main.js"></script>
  <script src="assets/sh_javascript.min.js"></script>
  <script>highlight(undefined, undefined, 'pre');</script>
  <!-- __TRACKING__ -->
</body>
</html>