Four patches for LWP (and comments)
Marc Hedlund (hedlund@best.com)
Sun, 6 Aug 1995 17:06:55 -0700
--============_-1404368481==_============
Content-Type: text/plain; charset="us-ascii"
Attached are four uuendcoded patches for LWP 0.2. 'patch.a' and 'patch.b'
update LWP::StatusCode and LWP::MIMEheaders (respectively) to the August 3
draft of HTTP/1.0, <draft-ietf-http-v10-spec-01.ps>, so they are strongly
recommended. 'patch.c'adds the Response-Header fields to LWP::MIMEheaders,
which may not be necessary within LWP but certainly makes that module more
reusable (for me, at least!). 'patch.d' makes a change to
LWP::MIMEheader's handling of unknown headers. I think it is an
improvement, but it is not critical to anything I'm working on and could be
omitted without complaint.
Please note that these patches do NOT increment the RCS revision numbers of
the files they modify. (Can someone please tell me what the standard
practice for this would be? Should contributed patches mess with version
numbers in any way, or should that be left to the maintainer(s)?) Feel
free to request these patches from me if uudecoding doesn't work for you,
or if I've screwed it up.
Some details on the patches---
patch.a (StatusCode.pm): updates the status code messages under the August
3rd HTTP/1.0 draft. '203' became 'Non-Authoritative Information', '303'
became 'See Other', and a new code, '411 Authorization Refused', was added.
Updates both the mnemonic listings and the %StatusCode hash.
patch.b (MIMEheaders.pm): corrects and updates the @header_order listing of
standard headers according to the Augst 3rd draft. In 'General Headers',
removed 'Message-ID' and added 'Pragma'. In 'Request Headers', removed
'Praga' [sic], and added 'Orig-URI'. In 'Entity Headers', added 'Allow',
removed 'Location', 'Version', and 'Derived-From', and changed 'URI-header'
to 'URI'.
patch.c (MIMEheaders.pm): added in Response Header fields: 'Location',
'Public', 'Retry-After', 'Server', and 'WWW-Authenticate'.
patch.d (MIMEheaders.pm): moved 'unknown header' handling from &scan to
&header. The old implementation was forcing all unknown header-words to
begin with an uppercase (as it should be), but disallowed other uppercase
letters. Under the old implementation,
header('new-header', 'value') output "New-Header: value"
header('New-Header', 'value') output "New-Header: value"
but
header('NEW-Header', 'value') output "New-Header: value"
I discovered this when I tried to use
header('URI' => '<some-uri>')
MIMEheaders was looking for 'URI-header' instead of 'URI', so I got back
"Uri: <some-uri>"
This patch takes an unknown header and uppercases the first letter of each
header-word, but does not lower case the rest of the string before doing
so.
-----
I would like to reiterate that I think there are probably better naming
schemes. Some revisions and additions to my earlier comments:
* The LWP::MIMEheaders module doesn't rely on the MIME spec for its
definition, it relies on the HTTP spec. The HTTP spec goes to some lengths
to say that it does not define a MIME-compliant application, but instead
uses some MIME-style constructs -- really, in this case, RFC822 headers.
Shouldn't this module be named LWP::HTTPheaders, or better yet,
HTTP::Headers?
* I completely agree that LWP::Date should be a standard Perl
module -- there's no particular reason why it should be under the heading
of LWP. How about Date::RFC1123?
* The key argument in my mind for dividing LWP into LWP and HTTP is
that LWP is focussed on the HTTP request -- note the omission of all
response headers from MIMEheaders.pm! The modules that support HTTP
messages -- Message.pm, Request.pm, Response.pm, MIMEheader.pm, and
StatusCode.pm -- are all tremendously worthwhile for response-based
applications (like CGI scripts or mini-servers). They shouldn't be
'hidden' in a request-based distribution.
I remember Martijn saying something at one point like "just because a name
space is available doesn't mean we own it." This makes good sense, but as
the perlstyle man page says, "Think about reusability." An HTTP::
distribution that could be tarred with LWP::, CGI::, and whatever else
wanted it, would be a Good and Reusable Thing.
I advocate for, at least,
HTTP::
::Message
::Request
::Response
::Headers
::Status
I am only taking such a strong interest because I am so happy with what you
have! Nice work all around.
Marc Hedlund <hedlund@best.com>
--============_-1404368481==_============
Content-Type: text/plain; name="patch.a"; charset="us-ascii"
Content-Disposition: attachment; filename="patch.a"
*** StatusCode.pm.orig Sun Aug 6 14:46:32 1995
--- StatusCode.pm Sun Aug
6 14:50:21 1995
***************
*** 29,40 ****
RC_OK
RC_CREATED
RC_ACCEPTED
! RC_PROVISIONAL_INFORMATION
RC_NO_CONTENT
RC_MULTIPLE_CHOICES
RC_MOVED_PERMANENTLY
RC_MOVED_TEMPORARILY
!
RC_METHOD
RC_NOT_MODIFIED
RC_BAD_REQUEST
RC_UNAUTHORIZED
--- 29,40 ----
RC_OK
RC_CREATED
RC_ACCEPTED
! RC_NON_AUTHORITATIVE_INFORMATION
RC_NO_CONTENT
RC_MULTIPLE_CHOICES
RC_MOVED_PERMANENTLY
RC_MOVED_TEMPORARILY
!
RC_SEE_OTHER
RC_NOT_MODIFIED
RC_BAD_REQUEST
RC_UNAUTHORIZED
***************
*** 47,52 ****
--- 47,53 ----
RC_REQUEST_TIMEOUT
RC_CONFLICT
RC_GONE
+
RC_AUTHORIZATION_NEEDED
RC_INTERNAL_SERVER_ERROR
RC_NOT_IMPLEMENTED
RC_BAD_GATEWAY
***************
*** 75,86 ****
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
! 203 =>
'Provisional Information',
204 => 'No Content',
300 =>
'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Moved
Temporarily',
! 303 => 'Method',
304 => 'Not Modified',
400
=> 'Bad Request',
401 => 'Unauthorized',
--- 76,87 ----
200 =>
'OK',
201 => 'Created',
202 => 'Accepted',
! 203 =>
'Non-Authoritative Information',
204 => 'No Content',
300 =>
'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Moved
Temporarily',
! 303 => 'See Other',
304 => 'Not Modified',
400 => 'Bad Request',
401 => 'Unauthorized',
***************
***
93,98 ****
--- 94,100 ----
408 => 'Request Timeout',
409 =>
'Conflict',
410 => 'Gone',
+ 411 => 'Authorization Refused',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502
=> 'Bad Gateway',
--============_-1404368481==_============
Content-Type: text/plain; name="patch.b"; charset="us-ascii"
Content-Disposition: attachment; filename="patch.b"
*** MIMEheader.pm.orig Sun Aug 6 13:34:40 1995
--- MIMEheader.pm Sun Aug
6 13:50:09 1995
***************
*** 34,51 ****
# - General-Headers
#
- Request-Headers
# - Entity-Headers
! # (From
draft-ietf-http-v10-spec-00.ps)
my @header_order = qw(
! Date
Forwarded Message-ID MIME-Version
Accept Accept-Charset
Accept-Encoding Accept-Language
! Authorization From If-Modified-Since
Praga Referer User-Agent
!
! Content-Encoding Content-Language
Content-Length
! Content-Transfer-Encoding Content-Type Derived-From
!
Expires Last-Modified Link Location Title URI-Header
! Version
);
# Make alternative representations of @header_order. This is used
---
34,50 ----
# - General-Headers
# - Request-Headers
# -
Entity-Headers
! # (From draft-ietf-http-v10-spec-01.ps)
my
@header_order = qw(
! Date Forwarded MIME-Version Pragma
Accept
Accept-Charset Accept-Encoding Accept-Language
! Authorization From
If-Modified-Since Orig-URI Referer User-Agent
!
! Allow
Content-Encoding Content-Language Content-Length
!
Content-Transfer-Encoding Content-Type
! Expires Last-Modified Link
Title URI
);
# Make alternative representations of @header_order.
This is used
--============_-1404368481==_============
Content-Type: text/plain; name="patch.c"; charset="us-ascii"
Content-Disposition: attachment; filename="patch.c"
*** MIMEheader.pm.orig Sun Aug 6 13:52:12 1995
--- MIMEheader.pm Sun Aug
6 13:53:34 1995
***************
*** 33,38 ****
--- 33,39 ----
# "Good
Practice" order of HTTP message headers:
# - General-Headers
# -
Request-Headers
+ # - Response-Headers
# - Entity-Headers
# (From
draft-ietf-http-v10-spec-01.ps)
***************
*** 41,46 ****
--- 42,49
----
Accept Accept-Charset Accept-Encoding Accept-Language
Authorization From If-Modified-Since Orig-URI Referer User-Agent
+
+
Location Public Retry-After Server WWW-Authenticate
Allow
Content-Encoding Content-Language Content-Length
Content-Transfer-Encoding Content-Type
--============_-1404368481==_============
Content-Type: text/plain; name="patch.d"; charset="us-ascii"
Content-Disposition: attachment; filename="patch.d"
*** MIMEheader.pm.orig Sun Aug 6 14:52:37 1995
--- MIMEheader.pm Sun Aug
6 15:07:40 1995
***************
*** 130,135 ****
--- 130,141 ----
croak('need a field name') unless defined $field;
croak('to many
parameters') if @_ > 4;
+ my $std_field = lc $field;
+ unless(
defined $standard_case{$std_field} ) {
+ $field =~
s/\b(\w)/\u$1/g;
+ $standard_case{$std_field} = $field;
+ }
+
my $thisHeader = \@{$self->{'_header'}{lc $field}};
my @old
= ();
***************
*** 218,229 ****
if (defined $list) {
my $val;
my $std_field = $standard_case{$field};
-
unless (defined $std_field) {
- # unknown header,
determine suitable "casing" for it
- $std_field = $field;
-
$std_field =~ s/\b(\w)/\u$1/g;
-
$standard_case{$field} = $std_field; # remember it
- }
for $val (@$list) {
&$sub($std_field, $val);
}
--- 224,229 ----
--============_-1404368481==_============--