<commit_before># Copyright (C) 2008-2010, <NAME>.

package Mojo::Transaction;

use strict;
use warnings;

use base 'Mojo::Stateful';

use Carp 'croak';

__PACKAGE__->attr([qw/connection kept_alive/]);
__PACKAGE__->attr([qw/local_address local_port remote_port/]);
__PACKAGE__->attr(continue_timeout => 5);
__PACKAGE__->attr(keep_alive       => 0);

__PACKAGE__->attr('_real_state');

# Please don't eat me! I have a wife and kids. Eat them!
sub client_is_writing { shift->_is_writing }

sub client_leftovers {
    croak 'Method "client_leftovers" not implemented by subclass';
}

sub client_read  { croak 'Method "client_read" not implemented by subclass' }
sub client_write { croak 'Method "client_write" not implemented by subclass' }

sub is_paused { shift->is_state('paused') }

sub is_websocket {0}

sub pause {
    my $self = shift;

    # Already paused
    return $self if $self->_real_state;

    # Save state
    $self->_real_state($self->state);

    # Pause
    $self->state('paused');

    return $self;
}

sub remote_address {
    my ($self, $address) = @_;

    # Set
    if ($address) {
        $self->{remote_address} = $address;

        # Activate reverse proxy support for local requests
        $ENV{MOJO_REVERSE_PROXY} ||= 1 if $address eq '127.0.0.1';

        return $self;
    }

    # Get
    return $self->{remote_address};
}

sub resume {
    my $self = shift;

    # Not paused
    return unless my $state = $self->_real_state;

    # Resume
    $self->_real_state(undef);
    $self->state($state);

    return $self;
}

sub server_is_writing { shift->_is_writing }

sub server_leftovers {
    croak 'Method "server_leftovers" not implemented by subclass';
}

sub server_read { croak 'Method "server_read" not implemented by subclass' }

sub server_write { croak 'Method "server_write" not implemented by subclass' }

sub _is_writing {
    shift->is_state(
        qw/start write write_start_line write_headers write_body/);
}

1;
__END__

=head1 NAME

Mojo::Transaction - HTTP 1.1 Transaction Base Class

=head1 SYNOPSIS

    use base 'Mojo::transaction';

=head1 DESCRIPTION

L<Mojo::Transaction> is an abstract base class for HTTP 1.1 and WebSocket
transactions.

=head1 ATTRIBUTES

L<Mojo::Transaction> inherits all attributes from L<Mojo::Stateful> and
implements the following new ones.<commit_msg>fixed typo<commit_after># Copyright (C) 2008-2010, <NAME>.

package Mojo::Transaction;

use strict;
use warnings;

use base 'Mojo::Stateful';

use Carp 'croak';

__PACKAGE__->attr([qw/connection kept_alive/]);
__PACKAGE__->attr([qw/local_address local_port remote_port/]);
__PACKAGE__->attr(continue_timeout => 5);
__PACKAGE__->attr(keep_alive       => 0);

__PACKAGE__->attr('_real_state');

# Please don't eat me! I have a wife and kids. Eat them!
sub client_is_writing { shift->_is_writing }

sub client_leftovers {
    croak 'Method "client_leftovers" not implemented by subclass';
}

sub client_read  { croak 'Method "client_read" not implemented by subclass' }
sub client_write { croak 'Method "client_write" not implemented by subclass' }

sub is_paused { shift->is_state('paused') }

sub is_websocket {0}

sub pause {
    my $self = shift;

    # Already paused
    return $self if $self->_real_state;

    # Save state
    $self->_real_state($self->state);

    # Pause
    $self->state('paused');

    return $self;
}

sub remote_address {
    my ($self, $address) = @_;

    # Set
    if ($address) {
        $self->{remote_address} = $address;

        # Activate reverse proxy support for local requests
        $ENV{MOJO_REVERSE_PROXY} ||= 1 if $address eq '127.0.0.1';

        return $self;
    }

    # Get
    return $self->{remote_address};
}

sub resume {
    my $self = shift;

    # Not paused
    return unless my $state = $self->_real_state;

    # Resume
    $self->_real_state(undef);
    $self->state($state);

    return $self;
}

sub server_is_writing { shift->_is_writing }

sub server_leftovers {
    croak 'Method "server_leftovers" not implemented by subclass';
}

sub server_read { croak 'Method "server_read" not implemented by subclass' }

sub server_write { croak 'Method "server_write" not implemented by subclass' }

sub _is_writing {
    shift->is_state(
        qw/start write write_start_line write_headers write_body/);
}

1;
__END__

=head1 NAME

Mojo::Transaction - Transaction Base Class

=head1 SYNOPSIS

    use base 'Mojo::Transaction';

=head1 DESCRIPTION

L<Mojo::Transaction> is an abstract base class for transactions.

=head1 ATTRIBUTES

L<Mojo::Transaction> inherits all attributes from L<Mojo::Stateful> and
implements the following new ones.
{'fraction_non_alphanumeric': 0.11574174044482834, 'fraction_numerical': 0.010796804145972791, 'mean_word_length': 3.7950310559006213, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2096255', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1524, 'n_words': 432}