Skip to content
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
64 changes: 50 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ const client = addProxyToClient(new S3Client({}));
// `client` now has HTTP proxy config at 'http://127.0.0.1'
```

or

```ts
import { S3Client } from '@aws-sdk/client-s3';
import { addProxyToClient } from 'aws-sdk-v3-proxy';

const client = addProxyToClient(new S3Client({}), {
httpProxy: 'http://127.0.0.1',
});
// `client` now has HTTP proxy config at 'http://127.0.0.1'
```

### HTTPS Proxy

```ts
Expand All @@ -48,6 +60,18 @@ const client = addProxyToClient(new S3Client({}));
// `client` now has HTTPS proxy config at 'https://127.0.0.1'
```

or

```ts
import { S3Client } from '@aws-sdk/client-s3';
import { addProxyToClient } from 'aws-sdk-v3-proxy';

const client = addProxyToClient(new S3Client({}), {
httpsProxy: 'https://127.0.0.1',
});
// `client` now has HTTPS proxy config at 'https://127.0.0.1'
```

### No Proxy with exception disabled

```ts
Expand Down Expand Up @@ -112,6 +136,18 @@ Default: `false`

Toggles additional logging for debugging.

##### httpProxy

Type: `string`

The URL for the HTTP proxy server.
If not specified, the value of `process.env.http_proxy` or `process.env.HTTP_RPOXY` will be used.

##### httpsProxy

The URL for the HTTPS proxy server.
If not specified, the value of `process.env.https_proxy` or `process.env.HTTPS_RPOXY` will be used.

##### agentOptions

Type: `HttpsProxyAgentOptions`
Expand All @@ -126,17 +162,17 @@ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more inform

This project is licensed under the Apache-2.0 License.

[build-img]:https://github.com/awslabs/aws-sdk-v3-js-proxy/actions/workflows/release.yml/badge.svg
[build-url]:https://github.com/awslabs/aws-sdk-v3-js-proxy/actions/workflows/release.yml
[downloads-img]:https://img.shields.io/npm/dt/aws-sdk-v3-proxy
[downloads-url]:https://www.npmtrends.com/aws-sdk-v3-proxy
[npm-img]:https://img.shields.io/npm/v/aws-sdk-v3-proxy
[npm-url]:https://www.npmjs.com/package/aws-sdk-v3-proxy
[issues-img]:https://img.shields.io/github/issues/awslabs/aws-sdk-v3-js-proxy
[issues-url]:https://github.com/awslabs/aws-sdk-v3-js-proxy/issues
[codecov-img]:https://codecov.io/gh/awslabs/aws-sdk-v3-js-proxy/branch/main/graph/badge.svg
[codecov-url]:https://codecov.io/gh/awslabs/aws-sdk-v3-js-proxy
[semantic-release-img]:https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
[semantic-release-url]:https://github.com/semantic-release/semantic-release
[commitizen-img]:https://img.shields.io/badge/commitizen-friendly-brightgreen.svg
[commitizen-url]:http://commitizen.github.io/cz-cli/
[build-img]: https://github.com/awslabs/aws-sdk-v3-js-proxy/actions/workflows/release.yml/badge.svg
[build-url]: https://github.com/awslabs/aws-sdk-v3-js-proxy/actions/workflows/release.yml
[downloads-img]: https://img.shields.io/npm/dt/aws-sdk-v3-proxy
[downloads-url]: https://www.npmtrends.com/aws-sdk-v3-proxy
[npm-img]: https://img.shields.io/npm/v/aws-sdk-v3-proxy
[npm-url]: https://www.npmjs.com/package/aws-sdk-v3-proxy
[issues-img]: https://img.shields.io/github/issues/awslabs/aws-sdk-v3-js-proxy
[issues-url]: https://github.com/awslabs/aws-sdk-v3-js-proxy/issues
[codecov-img]: https://codecov.io/gh/awslabs/aws-sdk-v3-js-proxy/branch/main/graph/badge.svg
[codecov-url]: https://codecov.io/gh/awslabs/aws-sdk-v3-js-proxy
[semantic-release-img]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
[semantic-release-url]: https://github.com/semantic-release/semantic-release
[commitizen-img]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg
[commitizen-url]: http://commitizen.github.io/cz-cli/
4 changes: 2 additions & 2 deletions src/add-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export const addProxyToClient = <T>(
httpsOnly = false,
throwOnNoProxy = true,
agentOptions = {},
httpProxy = getHttpProxy(),
httpsProxy = getHttpsProxy(),
...opts
}: AddProxyOptions = {}
): T => {
const httpProxy = getHttpProxy();
const httpsProxy = getHttpsProxy();
const httpAgent = httpProxy
? new HttpsProxyAgent({ proxy: httpProxy, ...agentOptions })
: undefined;
Expand Down
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ export interface AddProxyOptions
* @default false
*/
httpsOnly?: boolean;
/**
* The URL for the HTTP proxy server.
* If not specified, the value of `process.env.http_proxy` or `process.env.HTTP_RPOXY` will be used.
*/
httpProxy?: string;
/**
* The URL for the HTTPS proxy server.
* If not specified, the value of `process.env.https_proxy` or `process.env.HTTPS_RPOXY` will be used.
*/
httpsProxy?: string;
/**
* Options to be provided to the proxy agent. This can be used for modifyi
*/
Expand Down
16 changes: 16 additions & 0 deletions test/add-proxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,21 @@ describe('add-proxy', () => {
expect.objectContaining(opts)
);
});

it('should attach an httpAgent AND httpsAgent when both proxies are set by options', () => {
const opts: AddProxyOptions = {
httpProxy: 'http://localhost',
httpsProxy: 'https://localhost',
};

addProxyToClient(client, opts);

expect(proxyAgentSpy).toHaveBeenNthCalledWith(1, {
proxy: 'http://localhost',
});
expect(proxyAgentSpy).toHaveBeenNthCalledWith(2, {
proxy: 'https://localhost',
});
});
});
});