Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added got support #2

Merged
merged 2 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ http.get('http://localhost:9200', { agent })
.end()
```

## Integrations

Following you can find the list of userland http libraries that are tested with this agent.

### [got](https://github.com/sindresorhus/got)

```js
got('http://localhost:9200', {
agent: {
http: 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 @@ -38,6 +38,7 @@
},
"devDependencies": {
"ava": "^3.10.1",
"got": "^11.5.1",
"proxy": "^1.0.2",
"standard": "^14.3.4",
"tsd": "^0.13.1"
Expand Down
111 changes: 111 additions & 0 deletions test/got.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
'use strict'

const got = require('got')
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 got(`http://${server.address().address}:${server.address().port}`, {
agent: {
http: new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: `http://${proxy.address().address}:${proxy.address().port}`
})
}
})

t.is(response.body, '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 got(`http://${server.address().address}:${server.address().port}`, {
agent: {
http: new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: `https://${proxy.address().address}:${proxy.address().port}`
})
}
})

t.is(response.body, '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 got(`https://${server.address().address}:${server.address().port}`, {
agent: {
http: new HttpsProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: `http://${proxy.address().address}:${proxy.address().port}`
})
}
})

t.is(response.body, '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 got(`https://${server.address().address}:${server.address().port}`, {
agent: {
http: new HttpsProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: `https://${proxy.address().address}:${proxy.address().port}`
})
}
})

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

server.close()
proxy.close()
})
3 changes: 0 additions & 3 deletions test/http-https.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict'

// We are using self-signed certificates
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0

const https = require('https')
const test = require('ava')
const { createSecureServer, createProxy } = require('./utils')
Expand Down
3 changes: 0 additions & 3 deletions test/https-http.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict'

// We are using self-signed certificates
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0

const http = require('http')
const test = require('ava')
const { createServer, createSecureProxy } = require('./utils')
Expand Down
3 changes: 0 additions & 3 deletions test/https-https.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict'

// We are using self-signed certificates
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0

const https = require('https')
const test = require('ava')
const { createSecureServer, createSecureProxy } = require('./utils')
Expand Down
3 changes: 3 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
'use strict'

// We are using self-signed certificates
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0

const proxy = require('proxy')
const { readFileSync } = require('fs')
const { join } = require('path')
Expand Down