<commit_before>package Net::CouchDB::Request;
use warnings;
use strict;

BEGIN {
    our @ISA = 'Exporter';
    our @EXPORT = qw( request );
}

sub request {
    my $self         = shift;
    my $method       = shift;
    my $relative_uri = !ref( $_[0] ) ? shift() : '';
    my $args         = shift || {};

    my $uri = URI->new_abs( $relative_uri, $self->uri );
    $uri->query_form( $args->{params} ) if $args->{params};
    my $req = HTTP::Request->new( $method, $uri );
    $req->header( Accept => 'application/json' );

    # set the request headers, if specified
    while ( my ($header, $value) = each %{ $args->{headers} || {} } ) {
        $req->header( $header => $value );
    }

    # set the request body if specified
    if ( my $body = $args->{content} ) {
        $req->content( ref $body ? Net::CouchDB->json->encode($body) : $body );
    }

    if ($ENV{DEBUG}) {
        warn "---- Request ----\n";
        warn $req->as_string;<commit_msg>Add Content-Length header when we send content<commit_after>package Net::CouchDB::Request;
use warnings;
use strict;

BEGIN {
    our @ISA = 'Exporter';
    our @EXPORT = qw( request );
}

sub request {
    my $self         = shift;
    my $method       = shift;
    my $relative_uri = !ref( $_[0] ) ? shift() : '';
    my $args         = shift || {};

    my $uri = URI->new_abs( $relative_uri, $self->uri );
    $uri->query_form( $args->{params} ) if $args->{params};
    my $req = HTTP::Request->new( $method, $uri );
    $req->header( Accept => 'application/json' );

    # set the request headers, if specified
    while ( my ($header, $value) = each %{ $args->{headers} || {} } ) {
        $req->header( $header => $value );
    }

    # set the request body if specified
    if ( my $body = $args->{content} ) {
        $req->content( ref $body ? Net::CouchDB->json->encode($body) : $body );
        $req->header('Content-Length' => length $req->content);
    }

    if ($ENV{DEBUG}) {
        warn "---- Request ----\n";
        warn $req->as_string;
{'fraction_non_alphanumeric': 0.19465081723625557, 'fraction_numerical': 0.0009905894006934125, 'mean_word_length': 2.452991452991453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, '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': '4708448', 'n_tokens_mistral': 683, 'n_tokens_neox': 663, 'n_words': 176}