Permalink
Browse files

Allow path to be overridden in HttpClient by HttpRequest

  • Loading branch information...
1 parent 937229e commit 6ca207c353436c7f9a34538d743f5422f9d681da @lsegal lsegal committed Mar 14, 2013
Showing with 12 additions and 7 deletions.
  1. +4 −2 lib/http.js
  2. +1 −0 lib/service_interface/json.js
  3. +1 −0 lib/service_interface/query.js
  4. +5 −4 test/http_request.spec.coffee
  5. +1 −1 test/signers/s3.spec.coffee
View
@@ -107,12 +107,14 @@ AWS.HttpRequest = inherit({
* @api private
*/
constructor: function HttpRequest(endpoint, region) {
+ endpoint = new AWS.Endpoint(endpoint);
this.method = 'POST';
- this.path = '/';
+ this.path = endpoint.path || '/';
this.headers = {};
this.headers['User-Agent'] = AWS.util.userAgent();
this.body = '';
- this.endpoint = AWS.util.copy(endpoint);
+ this.endpoint = endpoint;
+ this.host
this.region = region;
},
@@ -25,6 +25,7 @@ AWS.ServiceInterface.Json = {
var target = api.targetPrefix + '.' + api.operations[req.operation].name;
var version = api.jsonVersion || '1.0';
+ httpRequest.path = '/';
httpRequest.body = JSON.stringify(req.params || {});
httpRequest.headers['Content-Type'] = 'application/x-amz-json-' + version;
httpRequest.headers['X-Amz-Target'] = target;
@@ -25,6 +25,7 @@ AWS.ServiceInterface.Query = {
buildRequest: function buildRequest(req) {
var operation = req.client.api.operations[req.operation];
var httpRequest = req.httpRequest;
+ httpRequest.path = '/';
httpRequest.headers['Content-Type'] =
'application/x-www-form-urlencoded; charset=utf-8';
httpRequest.params = new AWS.QueryParamList();
@@ -17,7 +17,7 @@ describe 'AWS.HttpRequest', ->
request = null
beforeEach ->
- request = new AWS.HttpRequest()
+ request = new AWS.HttpRequest('http://domain.com')
describe 'constructor', ->
@@ -33,12 +33,13 @@ describe 'AWS.HttpRequest', ->
it 'defaults body to empty string', ->
expect(request.body).toEqual('')
- it 'defaults endpoint to undefined', ->
- expect(request.endpoint).toEqual(undefined)
-
it 'defaults endpointPrefix to undefined', ->
expect(request.endpointPrefix).toEqual(undefined)
+ it 'uses the path from the endpoint if provided', ->
+ request = new AWS.HttpRequest('http://domain.com/path')
+ expect(request.path).toEqual('/path')
+
describe 'pathname', ->
it 'defaults to /', ->
@@ -40,7 +40,7 @@ describe 'AWS.Signers.S3', ->
sessionToken = null
buildRequest = () ->
- req = new AWS.HttpRequest()
+ req = new AWS.HttpRequest('https://s3.amazonaws.com')
req.method = method
req.path = path
req.headers = headers

0 comments on commit 6ca207c

Please sign in to comment.