Skip to content

Commit

Permalink
Added needle support (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
delvedor authored Jul 17, 2020
1 parent 0c0b587 commit 1d8b7a1
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ got('http://localhost:9200', {
})
```

### [needle](https://github.com/tomas/needle)

```js
needle('get', 'http://localhost:9200', {
agent: new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: 'http://localhost:8080'
})
})
```

## License

This software is licensed under the [MIT](./LICENSE).
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"devDependencies": {
"ava": "^3.10.1",
"got": "^11.5.1",
"needle": "^2.5.0",
"proxy": "^1.0.2",
"standard": "^14.3.4",
"tsd": "^0.13.1"
Expand Down
103 changes: 103 additions & 0 deletions test/needle.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
'use strict'

const needle = require('needle')
const test = require('ava')
const {
createServer,
createSecureServer,
createProxy,
createSecureProxy
} = require('./utils')
const { HttpProxyAgent, HttpsProxyAgent } = require('../')

test('http to http', async t => {
const server = await createServer()
const proxy = await createProxy()
server.on('request', (req, res) => res.end('ok'))

const response = await needle('get', `http://${server.address().address}:${server.address().port}`, {
agent: new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: `http://${proxy.address().address}:${proxy.address().port}`
})
})

t.is(response.body.toString(), 'ok')
t.is(response.statusCode, 200)

server.close()
proxy.close()
})

test('https to http', async t => {
const server = await createServer()
const proxy = await createSecureProxy()
server.on('request', (req, res) => res.end('ok'))

const response = await needle('get', `http://${server.address().address}:${server.address().port}`, {
agent: new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: `https://${proxy.address().address}:${proxy.address().port}`
})
})

t.is(response.body.toString(), 'ok')
t.is(response.statusCode, 200)

server.close()
proxy.close()
})

test('http to https', async t => {
const server = await createSecureServer()
const proxy = await createProxy()
server.on('request', (req, res) => res.end('ok'))

const response = await needle('get', `https://${server.address().address}:${server.address().port}`, {
agent: new HttpsProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: `http://${proxy.address().address}:${proxy.address().port}`
})
})

t.is(response.body.toString(), 'ok')
t.is(response.statusCode, 200)

server.close()
proxy.close()
})

test('https to https', async t => {
const server = await createSecureServer()
const proxy = await createSecureProxy()
server.on('request', (req, res) => res.end('ok'))

const response = await needle('get', `https://${server.address().address}:${server.address().port}`, {
agent: new HttpsProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: `https://${proxy.address().address}:${proxy.address().port}`
})
})

t.is(response.body.toString(), 'ok')
t.is(response.statusCode, 200)

server.close()
proxy.close()
})

0 comments on commit 1d8b7a1

Please sign in to comment.