Skip to content

Commit

Permalink
Merge a162e15 into 908c20b
Browse files Browse the repository at this point in the history
  • Loading branch information
Rebecca Rice committed Dec 18, 2019
2 parents 908c20b + a162e15 commit 0cae9aa
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 98 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: node_js
node_js:
- 6
- 8
- 10

sudo: false

Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
## changelog

## Unreleased

- Node 10 support
- Swaps request with needle

## 2.1.1

- Update agentkeepalive dependency to v4.0.2. This will prevent this._evictSession error
- Update agentkeepalive dependency to v4.0.2. This will prevent this._evictSession error_

## 2.1.0

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ Transform GeoJSON into Mapnik XML.

### url markers

If your GeoJSON object has one or more features with a `marker-url` property, `mapnikify()` will write the images found at the url into a file in a temporary directory and use that path in the Mapnik XML. This uses the [request library](https://www.npmjs.com/package/request) to handle the http file fetching.
If your GeoJSON object has one or more features with a `marker-url` property, `mapnikify()` will write the images found at the url into a file in a temporary directory and use that path in the Mapnik XML. This uses the [needle library](https://www.npmjs.com/package/needle) to handle the http file fetching.

By default the request will attempt to fetch binary data from the specified url. If the url is `http` and not `https` , Mapnikify will use [agentkeepalive](https://www.npmjs.com/package/agentkeepalive) to speed up requesting multiple images. There is also a default timeout of 5 seconds.

You can customize the defaults passed to `request()` . Simply set a custom wrapper defined with `request.defaults` . See [request's documentation on defaults](https://www.npmjs.com/package/request#requestdefaultsoptions) for more information. For a quick example, this will set a longer timeout:
You can customize the defaults passed to `needle()` . Simply set a custom wrapper defined with `needle.defaults` . See [needle's documentation on defaults](https://www.npmjs.com/package/needle#overriding-defaults) for more information. For a quick example, this will set a longer timeout:

```javascript
var mapnikify = require('mapnikify');
var myRequest = require('request').defaults({
var myRequest = require('needle').defaults({
timeout: 10000,
followRedirect: false
});
Expand Down
24 changes: 11 additions & 13 deletions lib/get.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var AgentKeepAlive = require('agentkeepalive'),
var AgentKeepAlive = require('agentkeepalive').HttpsAgent,
xtend = require('xtend'),
requestLib = require('request');
needle = require('needle');

// Use a single agent for all requests so that requests to the same
// host can use keep-alive for performance.
Expand All @@ -18,13 +18,13 @@ var agent = new AgentKeepAlive({
* @param {function} callback
*/
module.exports = function get(options, callback) {
var request = getClient();
var request = getClientSettings();
var params = normalizeParams(options);
if(!params) { callback(new Error('Invalid parameters: ' + JSON.stringify(options))); }

// This might load the same file multiple times, but the overhead should
// be very little.
request(params, function(err, resp, data) {
request.get(options, { agent: agent }, function(err, resp, data) {
// Use err.status of 400 as it's not an unexpected application error,
// but likely due to a bad request. Catches ECONNREFUSED,
// getaddrinfo ENOENT, etc.
Expand All @@ -35,7 +35,7 @@ module.exports = function get(options, callback) {
}
// request 2.2.x *always* returns the response body as a string.
// @TODO remove this once request is upgraded.
if (!(data instanceof Buffer)) data = new Buffer(data, 'binary');
if (!(data instanceof Buffer)) data = new Buffer.from(data, 'binary');
// Restrict data length.
if (data.length > 32768) return callback(new Error('Marker loaded from URL is too large.'));
callback(null, data);
Expand Down Expand Up @@ -63,13 +63,11 @@ function normalizeParams(options) {
}

// allows passing in a custom request handler
function getClient() {
if (module.exports.requestClient) { return module.exports.requestClient; }
return requestLib.defaults({
timeout: 5000,
encoding: 'binary',
headers: {
'accept-encoding': 'binary'
}
function getClientSettings() {
module.exports.requestClient ?
module.exports.requestClient :
needle.defaults({
response_timeout: 4000
});
return needle;
}

0 comments on commit 0cae9aa

Please sign in to comment.