Skip to content

Commit e003bfa

Browse files
properly support an HTTP method of '0'
This is valid according to RFC9110: see https://datatracker.ietf.org/doc/html/rfc9110#appendix-A for the full ABNF, which is equivalent to the regex: ^[a-zA-Z0-9!#$%&'*+.^_`|~-]+$
1 parent 9a985b1 commit e003bfa

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Revision history for HTTP-Message
22

33
{{$NEXT}}
4+
- now handling HTTP method '0' (Karen Etheridge)
45

56
7.00 2024-10-07 15:31:56Z
67
- Stop transforming LF into CRLF. Fixes #69 (GH#196) (Olaf Alders)

lib/HTTP/Request.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ sub as_string
118118
my($eol) = @_;
119119
$eol = "\n" unless defined $eol;
120120

121-
my $req_line = $self->method || "-";
121+
my $req_line = (defined $self->method) ? $self->method : "-";
122122
my $uri = $self->uri;
123123
$uri = (defined $uri) ? $uri->as_string : "-";
124124
$req_line .= " $uri";
@@ -131,7 +131,7 @@ sub as_string
131131
sub dump
132132
{
133133
my $self = shift;
134-
my @pre = ($self->method || "-", $self->uri || "-");
134+
my @pre = ((defined $self->method) ? $self->method : "-", (defined $self->uri) ? $self->uri : "-");
135135
if (my $prot = $self->protocol) {
136136
push(@pre, $prot);
137137
}

t/request.t

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use strict;
55
use warnings;
66

77
use Test::More;
8-
plan tests => 39;
8+
plan tests => 43;
99

1010
use HTTP::Request;
1111
use Try::Tiny qw( catch try );
@@ -166,3 +166,13 @@ $r2 = HTTP::Request->parse('methonly http://www.example.com/');
166166
is( $r2->method, 'methonly' );
167167
is( $r2->uri, 'http://www.example.com/' );
168168
is( $r2->protocol, undef );
169+
170+
my $r3 = HTTP::Request->new(0 => "0");
171+
is($r3->method, '0', '0 is a valid HTTP method');
172+
is($r3->uri, '0', '0 is a valid URI');
173+
is($r3->as_string, "0 0\n\n", 'parsed zero method, zero uri req');
174+
is($r3->dump, <<EOT, 'dumped zero method, zero uri req');
175+
0 0
176+
177+
(no content)
178+
EOT

0 commit comments

Comments
 (0)