Skip to content

Commit

Permalink
Add ability to proxy requests (#34)
Browse files Browse the repository at this point in the history
* Add ability to proxy requests

* Convert proxy settings to struct
  • Loading branch information
barronbud authored Aug 31, 2020
1 parent 2d4629e commit 04d4d8a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ aws = new path.to.awscfml.aws(
);
```

*Note: An optional `httpProxy` argument is available when initializing the core `aws` component (a struct with `server` and `port` keys). When set this will proxy all AWS requests.*

### ColdBox Module

To use the library as a ColdBox Module, add the init arguments to the `moduleSettings` struct in `config/Coldbox.cfc`:
Expand Down
5 changes: 3 additions & 2 deletions aws.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ component {
string awsKey = '',
string awsSecretKey = '',
string defaultRegion = '',
struct constructorArgs = { }
struct constructorArgs = { },
struct httpProxy = { server: '', port: 80 }
) {
this.api = new com.api( awsKey, awsSecretKey, defaultRegion );
this.api = new com.api( awsKey, awsSecretKey, defaultRegion, httpProxy );

for ( var service in variables.services ) {
if ( structKeyExists( arguments.constructorArgs, service ) ) {
Expand Down
5 changes: 3 additions & 2 deletions com/api.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ component accessors="true" {
public any function init(
required string awsKey,
required string awsSecretKey,
required string defaultRegion
required string defaultRegion,
struct httpProxy = { server: '', port: 80 }
) {
variables.utils = new utils();
variables.httpService = server.keyExists( 'lucee' ) ? new http.lucee( utils ) : new http.coldfusion( utils );
variables.httpService = server.keyExists( 'lucee' ) ? new http.lucee( utils, httpProxy ) : new http.coldfusion( utils, httpProxy );
variables.credentials = new credentials( awsKey, awsSecretKey, this );
variables.signer = new signature_v4( this );
variables.defaultRegion = arguments.defaultRegion.len() ? arguments.defaultRegion : utils.getSystemSetting(
Expand Down
5 changes: 3 additions & 2 deletions com/http/coldfusion.cfc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
component {

public any function init(
required any utils
required any utils,
struct httpProxy = { server: '', port: 80 }
) {
variables.utils = utils;
return this;
Expand All @@ -21,7 +22,7 @@ component {
var request_headers = utils.parseHeaders( headers );
var urlPath = 'http' & ( useSSL ? 's' : '' ) & '://' & fullPath;

cfhttp(url=urlPath, method=httpMethod, result="result", timeout=timeout) {
cfhttp(url=urlPath, method=httpMethod, result="result", timeout=timeout, proxyserver=httpProxy.server, proxyport=httpProxy.port) {
for ( var header in request_headers ) {
if ( header.name == 'host' ) continue;
cfhttpparam(type="header", name=lCase( header.name ), value=header.value);
Expand Down
6 changes: 4 additions & 2 deletions com/http/lucee.cfc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
component {

public any function init(
required any utils
required any utils,
struct httpProxy = { server: '', port: 80 }
) {
variables.utils = utils;
variables.httpProxy = httpProxy;
return this;
}

Expand All @@ -21,7 +23,7 @@ component {
var request_headers = utils.parseHeaders( headers );
var urlPath = 'http' & ( useSSL ? 's' : '' ) & '://' & fullPath;

http url=urlPath method=httpMethod result="result" encodeurl=false timeout=timeout {
http url=urlPath method=httpMethod result="result" encodeurl=false timeout=timeout proxyServer=httpProxy.server proxyPort=httpProxy.port {
for ( var header in request_headers ) {
if ( header.name == 'host' ) continue;
httpparam type="header" name=lCase( header.name ) value=header.value;
Expand Down

0 comments on commit 04d4d8a

Please sign in to comment.