Davide Baldini | 28 Feb 2012 05:52
Picon
Gravatar

CGI - carriage-return for new lines?

I'm writing Bash script to process a stdin caming from lighttpd's CGI. I
noticed that the caming lines carry a trailing carriage-return for
breaking lines, instead of the expected line-feed, and obviously bash
fails to recognize new lines.

The MIME type is "multipart/form-data";
lighttpd -v
lighttpd/1.4.28 (ssl) - a light and fast webserver
Build-Date: Dec 20 2011 22:59:43

Ryan Schmidt | 28 Feb 2012 06:08
Favicon

Re: CGI - carriage-return for new lines?


On Feb 27, 2012, at 22:52, Davide Baldini wrote:

> I'm writing Bash script to process a stdin caming from lighttpd's CGI. I
> noticed that the caming lines carry a trailing carriage-return for
> breaking lines, instead of the expected line-feed, and obviously bash
> fails to recognize new lines.
> 
> The MIME type is "multipart/form-data";
> lighttpd -v
> lighttpd/1.4.28 (ssl) - a light and fast webserver
> Build-Date: Dec 20 2011 22:59:43

The HTTP specification says that lines must be terminated by CRLF.

Davide Baldini | 28 Feb 2012 07:13
Picon
Gravatar

Re: CGI - carriage-return for new lines?

On 02/28/12 06:08, Ryan Schmidt wrote:
> The HTTP specification says that lines must be terminated by CRLF.

Hello Ryan,
as of course you know, HTTP specification has nothing to do with CGI-1.1
specification. I personally read the CGI spec on w3.org and about
<newline> it is open to let the system decide; in particular, it states
that webservers must pay attention to convert HTML headers from the
system's encode of <newline> to CR+LF.

Inside UNIX-based OSs we should use the UNIX encode, not the Windows one.

--
please send me Carbon Copies since I'm not subscribed to the list.

Stefan Bühler | 28 Feb 2012 10:40
Favicon

Re: CGI - carriage-return for new lines?

Hi,

On 02/28/2012 05:52 AM, Davide Baldini wrote:
> I'm writing Bash script to process a stdin caming from lighttpd's CGI. I
> noticed that the caming lines carry a trailing carriage-return for
> breaking lines, instead of the expected line-feed, and obviously bash
> fails to recognize new lines.
>
> The MIME type is "multipart/form-data";

If you are talking about writing a CGI script in bash and want to read 
the request body, there is not much lighttpd can do for you - it doesn't 
touch the body (the headers are passed in environment variables)

Davide Baldini | 28 Feb 2012 13:36
Picon
Gravatar

Re: CGI - carriage-return for new lines?

On 02/28/12 10:40, Stefan Bühler wrote:
> If you are talking about writing a CGI script in bash and want to read
> the request body, there is not much lighttpd can do for you - it doesn't
> touch the body (the headers are passed in environment variables)

Thank you Stefan, I don't know HTTP details and I wasn't aware that the
request-body sent to CGI scripts by standard input is directly generated
by the client's user agent.

However, looking back to the CGI specification (*), the request-body is
defined simply as an OCTET stream of data, octet being an undefined
keyword (perhaps it refers to HTTP spec?), without recognizing the
existence of text lines and their possible breaking character sequences.

I wonder if servers are required to pass these OCTETs unaltered or if
they are free to adapt the text encode to the one used by the platform,
of course only in the ambit of text type MIMEs.

(*) request-body section: http://tools.ietf.org/html/rfc3875#page-20


Gmane