Changeset 22986 for lang/perl/Moxy
- Timestamp:
- 11/08/08 10:15:26 (2 months ago)
- Location:
- lang/perl/Moxy/trunk
- Files:
-
- 4 added
- 3 removed
- 14 modified
-
Makefile.PL (modified) (1 diff)
-
config.yaml.sample (modified) (1 diff)
-
lib/Moxy.pm (modified) (11 diffs)
-
lib/Moxy/Plugin/HTTPHeader.pm (modified) (3 diffs)
-
lib/Moxy/Plugin/UserAgentSwitcher.pm (modified) (2 diffs)
-
lib/Moxy/Plugin/UserID.pm (modified) (3 diffs)
-
lib/Moxy/Session (added)
-
lib/Moxy/Session/State (added)
-
lib/Moxy/Session/State/BasicAuth.pm (added)
-
lib/Moxy/Storage.pm (deleted)
-
lib/Moxy/Storage/DBM_File.pm (deleted)
-
t/Plugins/DisableTableTag.t (modified) (1 diff)
-
t/Plugins/FlashUseImgTag.t (modified) (1 diff)
-
t/Plugins/GPS-request.t (modified) (1 diff)
-
t/Plugins/GPS-response.t (modified) (1 diff)
-
t/Plugins/Pictogram.t (modified) (1 diff)
-
t/Plugins/RefererCutter.t (modified) (1 diff)
-
t/Plugins/Scrubber.t (modified) (1 diff)
-
t/Plugins/StripScripts.t (modified) (1 diff)
-
t/Session-State-BasicAuth.t (added)
-
t/Storage-DBM_File.t (deleted)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Moxy/trunk/Makefile.PL
r20491 r22986 29 29 requires 'HTTP::MobileAttribute'; 30 30 requires 'Path::Class'; 31 requires 'HTTP::Session' => 0.08; 31 32 32 33 test_requires('Test::More'); -
lang/perl/Moxy/trunk/config.yaml.sample
r11492 r22986 8 8 log: 9 9 level: debug 10 storage: 11 module: DBM_File 12 file: /tmp/moxy.ndbm 13 dbm_class: NDBM_File 10 session: 11 state: 12 module: BasicAuth 13 store: 14 module: DBM 15 config: 16 file: /tmp/moxy.ndbm 17 dbm_class: NDBM_File 14 18 15 19 plugins: -
lang/perl/Moxy/trunk/lib/Moxy.pm
r22899 r22986 16 16 use HTML::TreeBuilder::XPath; 17 17 use HTML::TreeBuilder; 18 use HTTP::Session; 18 19 use LWP::UserAgent; 19 20 use MIME::Base64; … … 52 53 $self->conf->{global}->{log}->{fh} ||= \*STDERR; 53 54 54 $self->_init_storage;55 56 55 return $self; 57 56 } … … 65 64 }; 66 65 } 67 68 # -------------------------------------------------------------------------69 70 sub _init_storage {71 my ($self, ) = @_;72 73 my $mod = $self->{config}->{global}->{storage}->{module};74 $mod = $mod ? "Moxy::Storage::$mod" : 'Moxy::Storage::DBM_File';75 $mod->use or die $@;76 $self->{storage} = $mod->new($self, $self->conf->{global}->{storage} || {});77 }78 79 sub storage { shift->{storage} }80 66 81 67 # ------------------------------------------------------------------------- … … 181 167 sub handle_request { 182 168 my ($self, $req) = @_; 183 184 my $session_id = join ',', $req->headers->authorization_basic; 185 $self->log(debug => "Authorization header: $session_id"); 186 if ($session_id) { 187 return $self->_make_response( 188 req => $req, 189 user_id => $session_id, 190 ); 191 } else { 169 warn "HOGE"; 170 171 my $conf = $self->conf->{global}->{session}; 172 my $state_type = $conf->{state}->{module} || 'BasicAuth'; 173 my $state = sub { 174 if ($state_type eq 'Cookie') { 175 require HTTP::Session::State::Cookie; 176 HTTP::Session::State::Cookie->new( 177 $conf->{state}->{config} 178 ); 179 } else { 180 require Moxy::Session::State::BasicAuth; 181 Moxy::Session::State::BasicAuth->new( 182 $conf->{state}->{config} || {} 183 ); 184 } 185 }->(); 186 my $store = sub { 187 my $klass = "HTTP::Session::Store::$conf->{store}->{module}"; 188 Class::MOP::load_class($klass); 189 $klass->new( $conf->{store}->{config} ); 190 }->(); 191 192 my $auth = join(',', $req->headers->authorization_basic); 193 if ($state->isa('Moxy::Session::State::BasicAuth') && !$auth) { 194 $self->log(debug => 'basicauth'); 192 195 return HTTP::Engine::Response->new( 193 196 status => 401, … … 197 200 body => 'authentication required', 198 201 ); 202 } else { 203 $self->log(debug => "session: state: $state, store: $store"); 204 my $session = HTTP::Session->new( 205 state => $state, 206 store => $store, 207 request => $req, 208 ); 209 $self->log(debug => "session: $session"); 210 my $res = $self->_make_response( 211 req => $req, 212 session => $session, 213 ); 214 $session->response_filter($res); 215 return $res; 199 216 } 200 217 } … … 204 221 my %args = validate( 205 222 @_ => +{ 206 req => { isa => 'HTTP::Engine::Request', },207 user_id => { type => SCALAR},223 req => { isa => 'HTTP::Engine::Request', }, 224 session => { type => OBJECT }, 208 225 } 209 226 ); … … 222 239 url => $url, 223 240 request => $req->as_http_request, 224 user_id => $args{user_id},241 session => $args{session}, 225 242 ); 226 243 $self->log(debug => '-- response status: ' . $res->code); … … 271 288 url => qr{^https?://}, 272 289 request => { isa => 'HTTP::Request' }, 273 user_id => { type => SCALAR},290 session => { type => OBJECT }, 274 291 } 275 292 ); … … 283 300 'request_filter_process_agent', 284 301 { request => $req, # HTTP::Request object 285 user => $args{user_id},302 session => $args{session}, 286 303 } 287 304 ); … … 294 311 request => $req, # HTTP::Request object 295 312 mobile_attribute => $mobile_attribute, 296 user => $args{user_id},313 session => $args{session}, 297 314 } 298 315 ); … … 322 339 response => $response, # HTTP::Response object 323 340 mobile_attribute => $mobile_attribute, 324 user => $args{user_id},341 session => $args{session}, 325 342 } 326 343 ); -
lang/perl/Moxy/trunk/lib/Moxy/Plugin/HTTPHeader.pm
r10675 r22986 10 10 my ($self, $context, $args) = @_; 11 11 12 my $http_header = $ context->storage->get(__PACKAGE__. $args->{user});12 my $http_header = $args->{session}->get(__PACKAGE__); 13 13 14 14 if ($http_header) { … … 35 35 params => \%params, 36 36 current_uri => $args->{response}->request->uri, 37 headers => $ context->storage->get(__PACKAGE__ . $args->{user}),37 headers => $args->{session}->get(__PACKAGE__), 38 38 } 39 39 ); … … 49 49 # store settings 50 50 my $r = CGI->new($args->{request}->content); 51 $ context->storage->set(__PACKAGE__ . $args->{user}=> $r->param('moxy_http_header'));51 $args->{session}->set(__PACKAGE__ => $r->param('moxy_http_header')); 52 52 53 53 # back -
lang/perl/Moxy/trunk/lib/Moxy/Plugin/UserAgentSwitcher.pm
r22897 r22986 12 12 my ($self, $context, $args) = @_; 13 13 14 my $user_agent = $ context->storage->get('user_agent_' . $args->{user}) || 'KDDI-TS3G UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0';14 my $user_agent = $args->{session}->get('user_agent') || 'KDDI-TS3G UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0'; 15 15 my $ua_info = $self->get_ua_info($context, $user_agent); 16 16 … … 51 51 # store settings 52 52 my $r = CGI->new($args->{request}->content); # CGI.pm は遅いやん。他になんかないんかねー 53 $ context->storage->set("user_agent_$args->{user}" => $r->param('moxy_user_agent'));53 $args->{session}->set("user_agent" => $r->param('moxy_user_agent')); 54 54 55 55 # back -
lang/perl/Moxy/trunk/lib/Moxy/Plugin/UserID.pm
r10675 r22986 9 9 my ($self, $context, $args) = @_; 10 10 11 my $key = join(',', __PACKAGE__, $args->{ user}, $args->{mobile_attribute}->user_agent);12 my $user_id = $ context->storage->get($key);11 my $key = join(',', __PACKAGE__, $args->{mobile_attribute}->user_agent); 12 my $user_id = $args->{session}->get($key); 13 13 if ($user_id) { 14 14 # au subscriber id. … … 31 31 32 32 # store to user stash. 33 my $key = join(',', __PACKAGE__, $args->{ user}, $args->{mobile_attribute}->user_agent);34 $ context->storage->set($key => $r->param('user_id'));33 my $key = join(',', __PACKAGE__, $args->{mobile_attribute}->user_agent); 34 $args->{session}->set($key => $r->param('user_id')); 35 35 36 36 my $response = HTTP::Response->new( 302, 'Moxy(UserID)' ); … … 44 44 return '' unless $args->{mobile_attribute}->is_ezweb || $args->{mobile_attribute}->is_docomo; 45 45 46 my $key = join(',', __PACKAGE__, $args->{ user}, $args->{mobile_attribute}->user_agent);47 my $user_id = $ context->storage->get($key);46 my $key = join(',', __PACKAGE__, $args->{mobile_attribute}->user_agent); 47 my $user_id = $args->{session}->get($key); 48 48 49 49 return $self->render_template( -
lang/perl/Moxy/trunk/t/Plugins/DisableTableTag.t
r9973 r22986 14 14 global => { 15 15 assets_path => catfile( $FindBin::Bin, '..', 'assets' ), 16 storage => {17 module => 'DBM_File',18 file => 't/testing.ndbm',19 dbm_class => 'NDBM_File',20 },21 16 'log' => { 22 17 level => 'info', -
lang/perl/Moxy/trunk/t/Plugins/FlashUseImgTag.t
r9973 r22986 14 14 global => { 15 15 assets_path => catfile( $FindBin::Bin, '..', 'assets' ), 16 storage => {17 module => 'DBM_File',18 file => 't/testing.ndbm',19 dbm_class => 'NDBM_File',20 },21 16 'log' => { 22 17 level => 'info', -
lang/perl/Moxy/trunk/t/Plugins/GPS-request.t
r9973 r22986 14 14 global => { 15 15 assets_path => catfile( $FindBin::Bin, '..', 'assets' ), 16 storage => {17 module => 'DBM_File',18 file => 't/testing.ndbm',19 dbm_class => 'NDBM_File',20 },21 16 'log' => { 22 17 level => 'info', -
lang/perl/Moxy/trunk/t/Plugins/GPS-response.t
r9973 r22986 15 15 global => { 16 16 assets_path => catfile( $FindBin::Bin, '..', 'assets' ), 17 storage => {18 module => 'DBM_File',19 file => 't/testing.ndbm',20 dbm_class => 'NDBM_File',21 },22 17 'log' => { 23 18 level => 'info', -
lang/perl/Moxy/trunk/t/Plugins/Pictogram.t
r10687 r22986 13 13 global => { 14 14 assets_path => File::Spec->catfile( $FindBin::Bin, '..', '..', 'assets' ), 15 storage => {16 module => 'DBM_File',17 file => 't/testing.ndbm',18 dbm_class => 'NDBM_File',19 },20 15 'log' => { 21 16 level => 'info', -
lang/perl/Moxy/trunk/t/Plugins/RefererCutter.t
r9973 r22986 11 11 global => { 12 12 assets_path => File::Spec->catfile( $FindBin::Bin, '..', 'assets' ), 13 storage => {14 module => 'DBM_File',15 file => 't/testing.ndbm',16 dbm_class => 'NDBM_File',17 },18 13 'log' => { 19 14 level => 'info', -
lang/perl/Moxy/trunk/t/Plugins/Scrubber.t
r17849 r22986 16 16 global => { 17 17 assets_path => catfile( $FindBin::Bin, '..', '..', 'assets' ), 18 storage => {19 module => 'DBM_File',20 file => 't/testing.ndbm',21 dbm_class => 'NDBM_File',22 },23 18 'log' => { 24 19 level => 'info', -
lang/perl/Moxy/trunk/t/Plugins/StripScripts.t
r17847 r22986 16 16 global => { 17 17 assets_path => catfile( $FindBin::Bin, '..', '..', 'assets' ), 18 storage => {19 module => 'DBM_File',20 file => 't/testing.ndbm',21 dbm_class => 'NDBM_File',22 },23 18 'log' => { 24 19 level => 'info',
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)