| 1 | # HTTP method line | ||
| 2 | # from RFC 2616, 2518 | ||
| 3 | # | ||
| 4 | # subclass of HTTP:Part; see that for interface requirements | ||
| 5 | # | ||
| 6 | |||
| 7 | package IDS::DataSource::HTTP::MethodLine; | ||
| 8 | use base qw(IDS::DataSource::HTTP::Part); | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use warnings; | ||
| 12 | use Carp qw(carp); | ||
| 13 | use IDS::DataSource::HTTP::URI; | ||
| 14 | |||
| 15 | $IDS::DataSource::HTTP::MethodLine::VERSION = "1.0"; | ||
| 16 | |||
| 17 | sub parse { | ||
| 18 | my $self = shift; | ||
| 19 | my $line = $self->{"data"}; # convenience | ||
| 20 | my @tokens; | ||
| 21 | |||
| 22 | $self->mesg(1, *parse{PACKAGE} . "::parse: data '$line'"); | ||
| 23 | |||
| 24 | my @pieces = split /\s+/, $line; | ||
| 25 | |||
| 26 | $self->{"method"} = $pieces[0]; | ||
| 27 | push @tokens, "Method: $pieces[0]"; | ||
| 28 | # verify method is listed in RFC 2616 or RFC 2518 | ||
| 29 | unless ($pieces[0] =~ /OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT|PROPFIND|PROPPATCH|MKCOL|COPY|MOVE|LOCK|UNLOCK/) { | ||
| 30 | my $pmsg = ${$self->{"params"}}{"source"} . | ||
| 31 | " contains an invalid method: '$pieces[0]'\n"; | ||
| 32 | $self->warn($pmsg, \@tokens, "!Invalid method: '$pieces[0]'"); | ||
| 33 | } | ||
| 34 | |||
| 35 | if (defined($pieces[1])) { | ||
| 36 | $self->{"path"} = new IDS::DataSource::HTTP::URIPath($self->{"params"}, $pieces[1]); | ||
| 37 | push @tokens, $self->{"path"}->tokens(); | ||
| 38 | } else { | ||
| 39 | $self->{"path"} = "NO Path!"; | ||
| 40 | my $pmsg = "No Path (line: '$line') in " . ${$self->{"params"}}{"source"}; | ||
| 41 | $self->warn($pmsg, \@tokens, $self->{"path"}); | ||
| 42 | } | ||
| 43 | |||
| 44 | if (defined($pieces[2]) && $pieces[2]) { | ||
| 45 | $self->{"http-version"} = $pieces[2]; | ||
| 46 | if ($pieces[2] =~ /\d+\.\d+/) { | ||
| 47 | push @tokens, "HTTP Version: $pieces[2]"; | ||
| 48 | } else { | ||
| 49 | my $pmsg = "Invalid HTTP Version: $pieces[2] in " . ${$self->{"params"}}{"source"}; | ||
| 50 | $self->warn($pmsg, \@tokens, "!Invalid HTTP Version: $pieces[2]"); | ||
| 51 | } | ||
| 52 | } else { | ||
| 53 | push @tokens, "Implied HTTP version: <= 1.0"; | ||
| 54 | } | ||
| 55 | |||
| 56 | $self->mesg(2, *parse{PACKAGE} . "::parse: tokens\n ", | ||
| 57 | "\n ", \@tokens); | ||
| 58 | $self->{"tokens"} = \@tokens; | ||
| 59 | } | ||
| 60 | |||
| 61 | sub empty { | ||
| 62 | my $self = shift; | ||
| 63 | undef $self->{"data"}; | ||
| 64 | undef $self->{"tokens"}; | ||
| 65 | } | ||
| 66 | |||
| 67 | # accessor functions not provided by the superclass | ||
| 68 | sub path { | ||
| 69 | my $self = shift; | ||
| 70 | return $self->{"path"} eq "NO Path!" ? "" : $self->{"path"}->path; | ||
| 71 | } | ||
| 72 | |||
| 73 | sub method { | ||
| 74 | my $self = shift; | ||
| 75 | return $self->{"method"}; | ||
| 76 | } | ||
| 77 | |||
| 78 | sub http_version { | ||
| 79 | my $self = shift; | ||
| 80 | return $self->{"http-version"}; | ||
| 81 | } | ||
| 82 | |||
| 83 | =head1 AUTHOR INFORMATION | ||
| 84 | |||
| 85 | Copyright 2005-2007, Kenneth Ingham. All rights reserved. | ||
| 86 | |||
| 87 | This library is free software; you can redistribute it and/or modify | ||
| 88 | it under the same terms as Perl itself. | ||
| 89 | |||
| 90 | Address bug reports and comments to: ids_test at i-pi.com. When sending | ||
| 91 | bug reports, please provide the versions of IDS::Test.pm, IDS::Algorithm.pm, | ||
| 92 | IDS::DataSource.pm, the version of Perl, and the name and version of the | ||
| 93 | operating system you are using. Since Kenneth is a PhD student, the | ||
| 94 | speed of the reponse depends on how the research is proceeding. | ||
| 95 | |||
| 96 | =head1 BUGS | ||
| 97 | |||
| 98 | Please report them. | ||
| 99 | |||
| 100 | =head1 SEE ALSO | ||
| 101 | |||
| 102 | L<IDS::Algorithm>, L<IDS::DataSource> | ||
| 103 | |||
| 104 | =cut | ||
| 105 | |||
| 106 | 1; |