Skip to content

Commit

Permalink
Added custom http headers to the requests sent with the HTTPService
Browse files Browse the repository at this point in the history
Signed-off-by: Dima Berastau <dima.berastau@gmail.com>
  • Loading branch information
Rasmus Bang Grouleff authored and dima committed Mar 10, 2009
1 parent 8da97c8 commit 7a6e79c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions framework/src/org/restfulx/Rx.as
Expand Up @@ -241,6 +241,11 @@ package org.restfulx {
*/
public static var sessionToken:String;

/**
* Stores any extra HTTP headers that needs to be sent to the backend
*/
public static var customHttpHeaders:Object;

/**
* Stores current authenticity token.
*/
Expand Down
13 changes: 11 additions & 2 deletions framework/src/org/restfulx/services/http/XMLHTTPServiceProvider.as
Expand Up @@ -182,7 +182,8 @@ package org.restfulx.services.http {
recursive:Boolean = false, undoRedoFlag:int = 0):void {
var httpService:HTTPService = getHTTPService(object, nestedBy);
httpService.method = URLRequestMethod.POST;
httpService.headers = {'X-HTTP-Method-Override': 'PUT'};
//httpService.headers = {'X-HTTP-Method-Override': 'PUT'};
addHeaders(httpService, {'X-HTTP-Method-Override': 'PUT'});
httpService.request = marshallToVO(object, recursive);
httpService.request["_method"] = "PUT";
httpService.url = RxUtils.addObjectIdToResourceURL(httpService.url, object, urlSuffix);
Expand All @@ -196,7 +197,8 @@ package org.restfulx.services.http {
recursive:Boolean = false, undoRedoFlag:int = 0):void {
var httpService:HTTPService = getHTTPService(object, nestedBy);
httpService.method = URLRequestMethod.POST;
httpService.headers = {'X-HTTP-Method-Override': 'DELETE'};
//httpService.headers = {'X-HTTP-Method-Override': 'DELETE'};
addHeaders(httpService, {'X-HTTP-Method-Override': 'DELETE'});
httpService.request["_method"] = "DELETE";
httpService.url = RxUtils.addObjectIdToResourceURL(httpService.url, object, urlSuffix);
var instance:Object = this;
Expand Down Expand Up @@ -373,6 +375,7 @@ package org.restfulx.services.http {
service.resultFormat = "e4x";
service.useProxy = false;
service.contentType = "application/x-www-form-urlencoded";
service.headers = Rx.customHttpHeaders;
service.url = rootUrl + RxUtils.nestResource(object, nestedBy, urlSuffix);
return service;
}
Expand Down Expand Up @@ -471,5 +474,11 @@ package org.restfulx.services.http {
}
return result;
}

protected function addHeaders(service:HTTPService, headers:Object):void {
for (var key:String in headers) {
service.headers[key] = headers[key];
}
}
}
}

0 comments on commit 7a6e79c

Please sign in to comment.