Reputation: 1679
I am trying to run a legacy Perl web application based on TetraBB under Apache2 on Debian.
This application uses print
to output HTTP headers, e.g. print "Content-type: text/html\n";
.
However, it seems that after the first print
, no further headers are accepted. In this example:
print "A\n"; print "B\n"; print "\n";
, header A
is recognized by the browser as a response header, while B
ends up at the top of the response HTML.
Writing print "A\nB\n\n";
works.
Also, if the first print
does not contain \n\n
, a 500 Internal Server Error
is generated.
What is causing this behavior and what can I do to make this work?
Upvotes: 0
Views: 453
Reputation: 386646
There is no difference between
print "Content-Type: text/html\n";
print "Set-Cookie: ...\n";
print "\n";
and
print "Content-Type: text/html\nSet-Cookie: ...\n\n";
unless you changed something that specifically makes them different (e.g. $\
). In fact, if you haven't enabled auto-flushing for STDOUT, the output will accumulate in a buffer to be sent in 4 or 8 KiB chunks to the pipe. This means there's absolutely no detectable difference to the other end of the pipe either.
Upvotes: 4
Reputation: 132920
You're actually outputting CGI headers, which the server then translates into response headers with the correct line endings. The CGI headers stop after the first double newline. Don't print two consecutive newlines until you are ready to terminate the headers, and do print them when you need to end the headers:
print <<HEADERS;
Content-type: text/plain
X-Some-Other: header
This is the body
HEADERS
Some servers have limits on the number of headers and on the length of header lines. Your error log may be able to say more about that.
To be any more useful than that, we need to see some actual code. A short program that demonstrates the problem would probably help you figure this out.
Upvotes: 1