The HTTP interface designed to support http & https protocols & multiple ports simultaneously.
Members
(inner) IncomingMessage
- Source:
- Implements:
Creates the request
object used to access client status, headers and data. See IncomingMessage.
(inner) Server
Creates a new HTTP & HTTPS Server that supports multiple ports. See Server.
Example
server = new httpe.Server({ port: 8080, listen: true })
(inner) ServerResponse
- Source:
- Implements:
Creates the response
object used to define server status, headers and data. See ServerResponse.
Methods
(inner) createServer(optionsopt, connectionListeneropt) → {Server}
Creates a new HTTP & HTTPS Server that supports multiple ports.
Example
server = new httpe.createServer({ port: 8080, listen: true })
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
The options for the server or Properties
|
||||||||||||||||||||||||
connectionListener |
function |
<optional> |
The listener bound to all connections. |
Returns:
- Type
- Server
(inner) generateCertificate(props, opts) → {Object}
Generates a new SSL certificate.
Example
cert = new httpe.generateCertificate({
commonName: 'example.org',
countryName, 'US',
localityName: 'Blacksburg',
organizationName: 'Test'
})
Parameters:
Name | Type | Description |
---|---|---|
props |
Array | Object | A map of OID subject items. |
opts |
Object | Additional certificate configuration. |
Returns:
The certificate (cert
) and private key (key
).
- Type
- Object
(inner) getCharset(path) → {String|Null}
Returns the character set of a given path.
Example
httpe.getCharset('/script.js') // 'UTF-8'
Parameters:
Name | Type | Description |
---|---|---|
path |
String | The path used to determine the charset. |
Returns:
The determined charset set or null.
- Type
- String | Null
(inner) getContentType(path) → {String|Null}
Returns the content type of a given path.
Example
httpe.contentType('/script.js') // 'application/javascript; charset=utf-8'
Parameters:
Name | Type | Description |
---|---|---|
path |
String | The path used to determine the content-type. |
Returns:
The determined content-type or null.
- Type
- String | Null
(inner) getMimeType(path) → {String|Null}
Returns the mime type of a given path.
Example
httpe.getCharset('/script.js') // 'application/javascript'
Parameters:
Name | Type | Description |
---|---|---|
path |
String | The path used to determine the mimetype. |
Returns:
The determined mimetype or null.
- Type
- String | Null
(async, inner) getPathStats(path, optsopt) → {Stats}
Returns the file stats for a given path.
Example
httpe.getPathStats('/path/to/dir').then(stats => {
// get the resolved path
const isPathAFile = stats.path
// get whether the path is a file
const isPathAFile = stats.isFile()
// destructure additional custom stats
const { charset, contentLength, contentType, lastModified, mimeType, path } = stats
})
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
path |
String | The path used to get stats. |
||||||||||||||||
opts |
Object |
<optional> |
Additional configuration resolving file stats. Properties
|
Returns:
A promise resolving with the matching path and file stats, or an error if it failed.
- Type
- Stats
(async, inner) isPortAvailable(port, useAvailablePort) → {Number|Error}
Returns a promise for whether a port is available for a connection.
Examples
httpe.isPortAvailable(80).then(availablePort => {}, error => {});
httpe.isPortAvailable(80, true).then(availablePort => {}, error => {});
Parameters:
Name | Type | Description |
---|---|---|
port |
Number | The port tested for an available connection. |
useAvailablePort |
Boolean | Whether to use the first available port. |
Returns:
A promise resolving with the available port or rejecting with the error.
- Type
- Number | Error