<commit_before>package RSP;

use strict;
use warnings;

use URI;
use JavaScript;
use RSP::Config;
use RSP::Transaction;

use Scalar::Util qw( blessed );
use Module::Load ();
use HTTP::Response;

sub handle {
  my $class = shift;
  my $req   = shift;

  my $tx = RSP::Transaction->start( $req ); 
  my $op = $tx->run;
 
  ## handle blessed objects, like filesystem objects...
  if ( blessed( $op->[ 3 ] ) ) {
    $op->[3] = $op->[3]->as_string;
  }
  
  my $resp  = HTTP::Response->new( @$op );
  $tx->end;
  return $resp;
}

1;<commit_msg>bandwidth logging<commit_after>package RSP;

use strict;
use warnings;

use URI;
use Encode;
use JavaScript;
use RSP::Config;
use RSP::Transaction;

use Scalar::Util qw( blessed );
use Module::Load ();
use HTTP::Response;

sub handle {
  my $class = shift;
  my $req   = shift;

  my $ib = Encode::encode("ascii", $req->as_string );
  my $ib_bw = length( $ib );
  
  my $tx = RSP::Transaction->start( $req ); 
  my $op = $tx->run;
 
  ## handle blessed objects, like filesystem objects...
  if ( blessed( $op->[ 3 ] ) ) {
    $op->[3] = $op->[3]->as_string;
  }
  
  my $resp  = HTTP::Response->new( @$op );

  my $ob = Encode::encode("ascii", $resp->as_string );
  my $ob_bw = length($ob);

  $tx->log_billing( $ib_bw + $ob_bw, "bandwidth", );

  $tx->end;

  return $resp;
}

1;
{'fraction_non_alphanumeric': 0.1910538286580743, 'fraction_numerical': 0.006065200909780136, 'mean_word_length': 3.370860927152318, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '6757253', 'n_tokens_mistral': 524, 'n_tokens_neox': 504, 'n_words': 135}