This repository has been archived by the owner on Apr 30, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
vti
committed
Aug 21, 2012
1 parent
059df39
commit a66deec
Showing
14 changed files
with
144 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package SockJS::Middleware::JSessionID; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use parent 'Plack::Middleware'; | ||
|
||
use Plack::Util; | ||
|
||
sub call { | ||
my $self = shift; | ||
my ($env) = @_; | ||
|
||
my $res = $self->app->(@_); | ||
return $res unless $env->{'sockjs.transport'}; | ||
|
||
return $self->response_cb( | ||
$res => sub { | ||
my $res = shift; | ||
|
||
my $h = Plack::Util::headers($res->[1]); | ||
|
||
if (my $cookie = $env->{HTTP_COOKIE}) { | ||
if ($cookie =~ m/(?:^|;|\s)JSESSIONID\s*=\s*(.+?)(?:\s|;|$)/) { | ||
$h->push('Set-Cookie' => "JSESSIONID=$1; Path=/"); | ||
} | ||
} | ||
elsif ($self->{cookie}) { | ||
$h->push('Set-Cookie' => 'JSESSIONID=dummy; Path=/'); | ||
} | ||
} | ||
); | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package SockJS::Transport::Base; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
sub new { | ||
my $class = shift; | ||
|
||
my $self = {@_}; | ||
bless $self, $class; | ||
|
||
return $self; | ||
} | ||
|
||
sub name {shift->{name}} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package MiddlewareJSessionIDTest; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use base 'TestBase'; | ||
|
||
use Test::More; | ||
|
||
use SockJS::Middleware::JSessionID; | ||
|
||
sub echo_cookie : Test { | ||
my $self = shift; | ||
|
||
my $mw = $self->_build_middleware; | ||
|
||
$mw->wrap(sub { [200, [], []] }); | ||
|
||
my $env = { | ||
'HTTP_COOKIE' => 'JSESSIONID=abcde', | ||
'sockjs.transport' => 'xhr_polling' | ||
}; | ||
|
||
my $response = $mw->call($env); | ||
|
||
is_deeply($response->[1], ['Set-Cookie' => 'JSESSIONID=abcde; Path=/']); | ||
} | ||
|
||
sub echo_cookie_smart : Test { | ||
my $self = shift; | ||
|
||
my $mw = $self->_build_middleware; | ||
|
||
$mw->wrap(sub { [200, [], []] }); | ||
|
||
my $env = { | ||
'HTTP_COOKIE' => 'foo=bar;JSESSIONID = abcde;bar=baz', | ||
'sockjs.transport' => 'xhr_polling' | ||
}; | ||
|
||
my $response = $mw->call($env); | ||
|
||
is_deeply($response->[1], ['Set-Cookie' => 'JSESSIONID=abcde; Path=/']); | ||
} | ||
|
||
sub set_default_cookie : Test { | ||
my $self = shift; | ||
|
||
my $mw = $self->_build_middleware(cookie => 1); | ||
|
||
$mw->wrap(sub { [200, [], []] }); | ||
|
||
my $env = {'sockjs.transport' => 'xhr_polling'}; | ||
|
||
my $response = $mw->call($env); | ||
|
||
is_deeply($response->[1], ['Set-Cookie' => 'JSESSIONID=dummy; Path=/']); | ||
} | ||
|
||
sub _build_middleware { | ||
my $self = shift; | ||
|
||
return SockJS::Middleware::JSessionID->new(@_); | ||
} | ||
|
||
1; |