Skip to content

Commit

Permalink
Changed to use io.socket._request to support headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeroto committed Jul 28, 2014
1 parent 788ded4 commit 2eb4c1c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion dist/maps/z-sails.min.js.map

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion dist/z-sails.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@
}
else
{
$window.io.socket[methodLowercase](url, angular.fromJson(post), function(data, jwr){
// build request options
var options = {
method: methodLowercase,
url: url,
headers: headers,
data: angular.fromJson(post)
};
$window.io.socket._request(options, function(data, jwr){
if (zsails.useFallback && jwr.statusCode != 200)
{
$httpXHRBackend(method, url, post, callback, headers, timeout, withCredentials, responseType);
Expand Down
2 changes: 1 addition & 1 deletion dist/z-sails.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion src/z-sails.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@
}
else
{
$window.io.socket[methodLowercase](url, angular.fromJson(post), function(data, jwr){
// build request options
var options = {
method: methodLowercase,
url: url,
headers: headers,
data: angular.fromJson(post)
};
$window.io.socket._request(options, function(data, jwr){
if (zsails.useFallback && jwr.statusCode != 200)
{
$httpXHRBackend(method, url, post, callback, headers, timeout, withCredentials, responseType);
Expand Down
19 changes: 7 additions & 12 deletions test/z-sails.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ describe("z-sails", function(){

// set up the mock socket
socket = {
get: function(_, _, cb){cb(null, {statusCode: 404, headers: null})},
post: function(_, _, cb){cb(null, {statusCode: 404, headers: null})},
put: function(_, _, cb){cb(null, {statusCode: 404, headers: null})},
delete: function(_, _, cb){cb(null, {statusCode: 404, headers: null})},
_request: function(_, cb){cb(null, {statusCode: 404, headers: null})},
}

$window.io = {
Expand All @@ -40,7 +37,6 @@ describe("z-sails", function(){
$http({url: '/template.html', method: 'GET'})
.finally(function(){
expect($httpXHRBackend).toHaveBeenCalled();
expect($httpXHRBackend.calls.count()).toEqual(1);
done();
});

Expand All @@ -52,11 +48,10 @@ describe("z-sails", function(){
zSails.useFileCheck = true;
zSails.useFallback = false;

spyOn(socket, "get").and.callThrough();
spyOn(socket, "_request").and.callThrough();

$http({url: '/resource', method: 'GET'}).finally(function(){
expect(socket.get).toHaveBeenCalled();
expect(socket.get.calls.count()).toEqual(1);
expect(socket._request).toHaveBeenCalled();
done();
});

Expand All @@ -68,10 +63,10 @@ describe("z-sails", function(){
zSails.useFileCheck = false;
zSails.useFallback = true;

spyOn(socket, "get").and.callThrough();
spyOn(socket, "_request").and.callThrough();

$http({url: '/template.html', method: 'GET'}).finally(function(){
expect(socket.get).toHaveBeenCalled();
expect(socket._request).toHaveBeenCalled();
expect($httpXHRBackend).toHaveBeenCalled();
done();
});
Expand All @@ -84,10 +79,10 @@ describe("z-sails", function(){
zSails.useFileCheck = true;
zSails.useFallback = true;

spyOn(socket, "get").and.callThrough();
spyOn(socket, "_request").and.callThrough();

$http({url: '/resource', method: 'GET'}).finally(function(){
expect(socket.get).toHaveBeenCalled();
expect(socket._request).toHaveBeenCalled();
expect($httpXHRBackend).toHaveBeenCalled();
done();
});
Expand Down

0 comments on commit 2eb4c1c

Please sign in to comment.