develooper Front page | perl.vmsperl | Postings from January 2002

Re: LWP/HTTP Content-Length Calculation Error

Thread Previous
Craig A. Berry
January 14, 2002 21:51
Re: LWP/HTTP Content-Length Calculation Error
Message ID:
At 10:54 PM -0500 1/14/02, Kokosa, Chris wrote:
> When I run the script on Win32 it
>runs fine.  When I run the app on VMS the web server replies with a "500
>length of data sent did not match calculated Content-Length header..."
>Is the content-length calculation wrong or is it a difference between OSs?

This could be a variant of the "what is the VMS file size *really*"
question that apparently caused Linus himself to make a derogatory
remark about VMS.  This has been discussed many times on comp.os.vms
and might even be in the OpenVMS FAQ, but I'll try to summarize from
a Perl perspective.

A quick look suggests that the request() method uses the st_size
field of the stat buffer to set up content length.  Perl's stat() is
based closely on what the C library gives us, and the docs to this
routine say, "If the file is a record file, the st_size field
includes carriage-control information. Consequently, the st_size
value will not correspond to the number of characters that can be
read from the file. "

In other words, the size of the file depends on what kind of file it
is.  Do DIRECTORY/FULL on the file in question and look at the record
format field; if it doesn't begin with "Stream"  then you've probably
got a record file in which formatting information occupies space on
disk but does not count in what goes on the wire when you read and
transmit the data in the file.

Try (assuming your file is named foo.dat):

$ set file foo.dat/attributes=rfm:stmlf

and see if the upload works.

We should probably fix up LWP, specifically (I think)
lib/LWP/Protocol/, so that record files get their data counted
properly.  In the meantime, does LWP give you any way to explicitly
specify the content-length yourself?  If so, you could slurp the
whole file into a variable and just do a length() on it if it's a
small file, and if it's not small do a length() on each record and
keep a total.

BTW, you might well have the same problem in C (or DCL for that
matter) as in Perl.

Craig A. Berry         

"Literary critics usually know what they're
talking about. Even if they're wrong."
	-- Perl creator Larry Wall

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About