Changeset 11941
- Timestamp:
- 05/19/08 00:11:10 (5 years ago)
- Location:
- lang/perl/Moobal/trunk/lib/Moobal
- Files:
-
- 7 modified
-
Component/BackendHTTP.pm (modified) (18 diffs)
-
Component/ClientHTTP.pm (modified) (3 diffs)
-
Component/HTTP.pm (modified) (10 diffs)
-
Component/Proxy.pm (modified) (7 diffs)
-
HTTPHeaders.pm (modified) (3 diffs)
-
Role/SocketHandler.pm (modified) (2 diffs)
-
Service.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Moobal/trunk/lib/Moobal/Component/BackendHTTP.pm
r11937 r11941 6 6 # 7 7 8 package Moobal:: BackendHTTP;8 package Moobal::Component::BackendHTTP; 9 9 use Moose; 10 10 11 with 'Moobal::Role::SocketContainer';11 extends 'Moobal::Component::HTTP'; 12 12 13 13 # Moobal::Component::Proxy connection, or undef … … 254 254 255 255 sub close { 256 my $self = shift; # Moobal:: BackendHTTP256 my $self = shift; # Moobal::Component::BackendHTTP 257 257 258 258 # OSX Gives EPIPE on bad connects, and doesn't fail the connect … … 286 286 # or set our generation if given a parameter 287 287 sub generation { 288 my Moobal:: BackendHTTP $self = $_[0];288 my Moobal::Component::BackendHTTP $self = $_[0]; 289 289 return $self->{generation} unless $_[1]; 290 290 return $self->{generation} = $_[1]; … … 293 293 # return what ip and port combination we're using 294 294 sub ipport { 295 my Moobal:: BackendHTTP $self = $_[0];295 my Moobal::Component::BackendHTTP $self = $_[0]; 296 296 return $self->{ipport}; 297 297 } … … 299 299 # called to tell backend that the client has gone on to do something else now. 300 300 sub forget_client { 301 my Moobal:: BackendHTTP $self = $_[0];301 my Moobal::Component::BackendHTTP $self = $_[0]; 302 302 $self->{client} = undef; 303 303 } … … 307 307 # returns true if client assignment was accepted. 308 308 sub assign_client { 309 my $self = shift; # Moobal:: BackendHTTP309 my $self = shift; # Moobal::Component::BackendHTTP 310 310 my Moobal::Component::Proxy $client = shift; 311 311 return 0 if $self->{client}; … … 390 390 # it has an upload ready on disk 391 391 sub invoke_buffered_upload_mode { 392 my $self = shift; # Moobal:: BackendHTTP392 my $self = shift; # Moobal::Component::BackendHTTP 393 393 394 394 # so, we're receiving a buffered upload, we need to go ahead and … … 402 402 # Backend 403 403 sub event_write { 404 my $self = shift; # Moobal:: BackendHTTP404 my $self = shift; # Moobal::Component::BackendHTTP 405 405 print "Backend $self is writeable!\n" if &Moobal::DEBUG >= 2; 406 406 … … 453 453 454 454 sub verify_failure { 455 my $self = shift; # Moobal:: BackendHTTP455 my $self = shift; # Moobal::Component::BackendHTTP 456 456 $NoVerify{$self->{ipport}} = time() + 60; 457 457 $self->{reportto}->note_bad_backend_connect($self); … … 461 461 462 462 sub event_read_waiting_options { # : void 463 my $self = shift; # Moobal:: BackendHTTP463 my $self = shift; # Moobal::Component::BackendHTTP 464 464 if ($self->{content_length_remain}) { 465 465 # the HTTP/1.1 spec says OPTIONS responses can have content-lengths, … … 488 488 489 489 sub handle_response { # : void 490 my $self = shift; # Moobal:: BackendHTTP490 my $self = shift; # Moobal::Component::BackendHTTP 491 491 my $hd = $self->{res_headers}; # Moobal::HTTPHeaders 492 492 my $client = $self->{client}; # Moobal::Component::Proxy … … 607 607 608 608 sub may_reproxy { 609 my $self = shift; # Moobal:: BackendHTTP609 my $self = shift; # Moobal::Component::BackendHTTP 610 610 my $svc = $self->{service}; # Moobal::Service 611 611 return 0 unless $svc; … … 615 615 # Backend 616 616 sub event_read { 617 my $self = shift; # Moobal:: BackendHTTP617 my $self = shift; # Moobal::Component::BackendHTTP 618 618 print "Backend $self is readable!\n" if &Moobal::DEBUG >= 2; 619 619 … … 674 674 # if $initial is on, then don't increment use count 675 675 sub next_request { 676 my Moobal:: BackendHTTP $self = $_[0];676 my Moobal::Component::BackendHTTP $self = $_[0]; 677 677 my $initial = $_[1]; 678 678 … … 740 740 # Backend: bad connection to backend 741 741 sub event_err { 742 my $self = shift; # Moobal:: BackendHTTP742 my $self = shift; # Moobal::Component::BackendHTTP 743 743 744 744 # FIXME: we get this after backend is done reading and we disconnect, … … 771 771 # Backend 772 772 sub event_hup { 773 my $self = shift; # Moobal:: BackendHTTP773 my $self = shift; # Moobal::Component::BackendHTTP 774 774 print "HANGUP for $self\n" if &Moobal::DEBUG; 775 775 $self->close("after_hup"); … … 777 777 778 778 sub as_string { 779 my $self = shift; # Moobal:: BackendHTTP779 my $self = shift; # Moobal::Component::BackendHTTP 780 780 781 781 my $ret = $self->SUPER::as_string; … … 797 797 sub die_gracefully { 798 798 # see if we need to die 799 my $self = shift; # Moobal:: BackendHTTP799 my $self = shift; # Moobal::Component::BackendHTTP 800 800 $self->close('graceful_death') if $self->state eq 'bored'; 801 801 } -
lang/perl/Moobal/trunk/lib/Moobal/Component/ClientHTTP.pm
r11938 r11941 26 26 has 'put_fh' => ( 27 27 is => 'rw', 28 isa => ' FileHandle',28 isa => 'Maybe[FileHandle]', 29 29 ); 30 30 … … 114 114 # one-time routing of new request to the right handlers 115 115 sub handle_request { 116 my Moobal::Component::ClientHTTP$self = shift;116 my $self = shift; 117 117 my $hd = $self->{req_headers}; 118 118 … … 123 123 124 124 # notify that we're about to serve 125 return if $self-> {service}->run_hook('start_web_request', $self);126 return if $self-> {service}->run_hook('start_http_request', $self);125 return if $self->service->run_hook('start_web_request', $self); 126 return if $self->service->run_hook('start_http_request', $self); 127 127 128 128 # GET/HEAD requests (local, from disk) -
lang/perl/Moobal/trunk/lib/Moobal/Component/HTTP.pm
r11938 r11941 69 69 has 'post_sendfile_cb' => ( 70 70 is => 'rw', 71 isa => ' CodeRef'71 isa => 'Maybe[CodeRef]' 72 72 ); 73 73 … … 83 83 has 'selector_svc' => ( 84 84 is => 'rw' 85 ); 86 87 has 'closed' => ( 88 is => 'rw', 89 isa => 'Bool', 90 default => 0 85 91 ); 86 92 … … 129 135 130 136 # now pass up the line 131 $self-> socket->close(@_);137 $self->danga_socket->close(@_); 132 138 } 133 139 … … 235 241 # NOTE: because we only speak 1.0 to clients they can't have 236 242 # pipeline in a read that we haven't read yet. 243 237 244 $self->watch_read(1); 238 245 $self->watch_write(0); … … 313 320 314 321 my $postread = sub { 315 return if $self-> {closed};322 return if $self->closed; 316 323 317 324 my $sent = Moobal::Socket::sendfile($self->{fd}, … … 428 435 Moobal::AIO::aio_stat($file, sub { 429 436 # client's gone anyway 430 return if $self-> {closed};437 return if $self->closed; 431 438 unless (-e _) { 432 439 return if $self->{service}->run_hook('static_get_poststat_file_missing', $self); … … 515 522 516 523 # if client's gone, just close filehandle and abort 517 if ($self-> {closed}) {524 if ($self->closed) { 518 525 CORE::close($rp_fh) if $rp_fh; 519 526 return; … … 583 590 $remain--; 584 591 $statinfo{$file} = $! ? [] : [ stat(_) ]; 585 return if $remain || $self-> {closed};592 return if $remain || $self->closed; 586 593 $self->_serve_request_multiple_poststat($hd, $dirbase, \@multiple_files, \%statinfo); 587 594 }); … … 677 684 678 685 # if client's gone, just close filehandle and abort 679 if ($self-> {closed}) {686 if ($self->closed) { 680 687 CORE::close($rp_fh) if $rp_fh; 681 688 return; … … 761 768 # now see if it exists 762 769 Moobal::AIO::aio_stat($fullpath, sub { 763 return if $self-> {closed};770 return if $self->closed; 764 771 return $self->try_index_files($hd, $res, $uri, $filepos + 1) unless -f _; 765 772 -
lang/perl/Moobal/trunk/lib/Moobal/Component/Proxy.pm
r11937 r11941 15 15 has 'backend' => ( 16 16 is => 'rw', 17 isa => 'Moobal:: BackendHTTP'17 isa => 'Moobal::Component::BackendHTTP' 18 18 ); 19 19 20 20 my @fields = ( 21 21 # use fields ( 22 'backend', # Moobal:: BackendHTTP object (or undef if disconnected)22 'backend', # Moobal::Component::BackendHTTP object (or undef if disconnected) 23 23 'backend_requested', # true if we've requested a backend for this request 24 24 'reconnect_count', # number of times we've tried to reconnect to backend … … 197 197 sub too_far_behind_backend { 198 198 my $self = $_[0]; # Moobal::Component::Proxy 199 my $backend = $self->{backend} or return 0; # Moobal:: BackendHTTP199 my $backend = $self->{backend} or return 0; # Moobal::Component::BackendHTTP 200 200 201 201 # if a backend doesn't have a service, it's a … … 218 218 sub use_reproxy_backend { 219 219 my $self = $_[0]; # Moobal::Component::Proxy 220 my $be = $_[1]; # Moobal:: BackendHTTP220 my $be = $_[1]; # Moobal::Component::BackendHTTP 221 221 222 222 # get a URI … … 255 255 sub backend_response_received { 256 256 my $self = $_[0]; # Moobal::Component::Proxy 257 my $be = $_[1]; # Moobal:: BackendHTTP257 my $be = $_[1]; # Moobal::Component::BackendHTTP 258 258 259 259 # a response means that we are no longer currently waiting on a reproxy, and … … 406 406 sub backend_ready { 407 407 my Moobal::Component::Proxy $self = $_[0]; 408 my Moobal:: BackendHTTP $be = $_[1];408 my Moobal::Component::BackendHTTP $be = $_[1]; 409 409 410 410 # if we'd turned ourselves off while we waited for a backend, turn … … 1033 1033 sub continue_buffered_upload { 1034 1034 my $self = shift; # Moobal::Component::Proxy 1035 my $be = shift; # Moobal:: BackendHTTP1035 my $be = shift; # Moobal::Component::BackendHTTP 1036 1036 return unless $self && $be; 1037 1037 … … 1194 1194 sub should_retry_after_500 { 1195 1195 my $self = shift; # Moobal::Component::Proxy 1196 my $be = shift; # Moobal:: BackendHTTP1196 my $be = shift; # Moobal::Component::BackendHTTP 1197 1197 my $svc = $be->{service}; 1198 1198 return 0 unless $svc->{enable_error_retries}; -
lang/perl/Moobal/trunk/lib/Moobal/HTTPHeaders.pm
r11724 r11941 78 78 $self->{type} = "httpres"; 79 79 80 Moobal::objctor($self, $self->{type});81 80 return $self; 82 81 } … … 101 100 $self->{uri} = undef; 102 101 $self->{type} = ($is_response ? "res" : "req"); 103 Moobal::objctor($self, $self->{type});104 102 105 103 # check request line … … 465 463 } 466 464 467 468 sub DESTROY {469 my Moobal::HTTPHeaders $self = shift;470 Moobal::objdtor($self, $self->{type});471 }472 473 465 1; 474 466 -
lang/perl/Moobal/trunk/lib/Moobal/Role/SocketHandler.pm
r11932 r11941 18 18 is => 'rw', 19 19 isa => 'Danga::Socket', 20 handles => [ qw(watch_write watch_read peer_ip_string tcp_cork read) ] 20 21 ); 21 22 … … 345 346 346 347 my $ret; 347 if ($ret = $self-> SUPER::write(@_)) {348 if ($ret = $self->danga_socket->write(@_)) { 348 349 # Mark this socket alive so we don't time out 349 350 $self->{alive_time} = $Moobal::tick_time; -
lang/perl/Moobal/trunk/lib/Moobal/Service.pm
r11937 r11941 55 55 does => 'Maybe[Moobal::Role::Listener]' 56 56 ); 57 58 has 'always_trusted' => ( 59 is => 'rw', 60 isa => 'Bool' 61 ); 62 63 has 'trusted_upstream_proxies' => ( 64 is => 'rw', 65 isa => 'Maybe[Net::Netmask]' 66 ); 67 57 68 58 69 sub enable { shift->enabled(1) } … … 130 141 return 1; 131 142 } 143 144 # called by BackendHTTP to ask if a client's IP is in our trusted list 145 sub trusted_ip { 146 my $self = shift; # Moobal::Service 147 my $ip = shift; 148 149 return 1 if $self->always_trusted; 150 151 my $tmap = $self->trusted_upstream_proxies; 152 return 0 unless $tmap; 153 154 # try to use it as a Net::Netmask object 155 return 1 if eval { $tmap->match($ip); }; 156 return 0; 157 } 158 159 sub run_hook {} 132 160 133 161 1; … … 896 924 } 897 925 898 # called by BackendHTTP to ask if a client's IP is in our trusted list899 sub trusted_ip {900 my $self = shift; # Moobal::Service901 my $ip = shift;902 903 return 1 if $self->{'always_trusted'};904 905 my $tmap = $self->{trusted_upstream_proxies};906 return 0 unless $tmap;907 908 # try to use it as a Net::Netmask object909 return 1 if eval { $tmap->match($ip); };910 return 0;911 }912 913 926 # manage some header stuff 914 927 sub header_management {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)