Skip to content

Commit

Permalink
Add some sort of timeout to underlying HTTP connection, closes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
kkamkou committed Oct 16, 2015
1 parent 6a8cb13 commit 5292abc
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM google/nodejs
FROM node:latest
WORKDIR /opt
ADD package.json ./
RUN npm install
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
node-akamai-http-api
====================
Akamai NetStorage HTTP API for the Node.js
Akamai NetStorage HTTP API for Node.js

## Installation
```
"dependencies": {
"akamai-http-api": "0.3.*"
"akamai-http-api": "0.4.*"
}
```
```npm update```
Expand All @@ -17,14 +17,18 @@ akamai.setConfig({
keyName: 'keyName',
key: 'aLongString',
host: 'changeme.akamaihd.net',
ssl: true,
verbose: false
ssl: true, // optional, default: false
verbose: false, // optional, default: false
request: { // optional, request.js options, see: https://github.com/request/request#requestoptions-callback
timeout: 20000 // 20s is the dafault value
}
});
```

### Notices
1. You have to [enable the netstorage HTTP API](https://control.akamai.com/dl/customers/NS/NetStrgHttpCM.pdf) access using the control.akamai.com website
2. Ensure there are no more than 15 operations/second on netstorage, otherwise you can expect netstorage to serve 500 errors.
3. Double check the `host` value. In case of typo (fe: `test.upload.akamai.com`), the client just sits there trying to open up a socket. Default timeout is `20s`.

## API
### Advanced
Expand Down Expand Up @@ -131,7 +135,7 @@ module.exports = myAkamai;

## Docker
```sh
# modify test/akamai.js#15 first
# modify test/akamai.js#19-21 first
[sudo] docker build -t node-akamai-http-api .
[sudo] docker run -ti --rm node-akamai-http-api
```
Expand Down
5 changes: 3 additions & 2 deletions lib/akamai.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ var akamai = Object.create(null, {
keyName: null,
host: null,
ssl: false,
verbose: false
verbose: false,
request: {timeout: 20000}
}
}
});
Expand Down Expand Up @@ -142,7 +143,7 @@ akamai.getRequestObject = function (path, params, cb) {
callback = function () {},
options = _.merge(
{url: this.getUri(path), headers: this.getHeaders(path, params.headers)},
params.request
params.request, this.getConfig().request
);

if (typeof(cb) === 'function') {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "akamai-http-api",
"version": "0.3.0",
"version": "0.4.0",
"main": "./lib/akamai.js",
"author": "Kanstantsin Kamkou <[email protected]>",
"description": "Akamai NetStorage HTTP API for the Node.js",
Expand Down
15 changes: 13 additions & 2 deletions test/akamai.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ var pathRemoteFile = '/CODE/FILE.jpg',
key: 'aLongString',
host: 'changeme.akamaihd.net',
ssl: true,
verbose: false
verbose: false,
request: {timeout: 20000}
};

// tests
Expand All @@ -32,7 +33,7 @@ module.exports = {
akamai.setConfig(config);
},

'Getters and Setters': {
'Core functionality': {
'Config set-up': function () {
akamai.getConfig().should.eql(config);
akamai.getUri('/').should.eql('https://' + config.host + '/');
Expand All @@ -48,6 +49,16 @@ module.exports = {
}
},

'Timeout': function () {
var clone = Object.create(akamai);
clone.setConfig({host: 'test.upload.akamai.com', request: {timeout: 1000}})
.du('/', function (err, result) {
should.not.exist(result);
err.should.be.an.instanceof(Error);
err.code.should.eql('ETIMEDOUT');
});
},

'Verbosity check': function (done) {
var clone = Object.create(akamai);
clone.setConfig({key: 'invalidKey', verbose: true})
Expand Down
1 change: 1 addition & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
--reporter spec
--ui exports
--check-leaks
--bail

0 comments on commit 5292abc

Please sign in to comment.