in reply to Re^2: Perl output is not inducing file download as expected
in thread Perl output is not inducing file download as expected

The truth is, I became frustrated by the amount of confusion on this issue. I found not a single decent commentary online for how to print the headers manually, and the packages that printed them appeared to be printing more than I had specified when I checked the browser console--and I had doubts as to what else they might be doing under the surface. This is what led me to attempt to print them manually, so I would have full control over what got put into the header.

But the internet seemed to provide multiple instructions on what the headers required: specifically, how each line of the header should be terminated. I tried one thing after another--I'm sure I must have tried at least 40 or more various configurations before I found anything that worked--and, of course, much of that time it was unrelated to the headers anyhow, but I didn't know that yet (the hot print handle was messing things up, or the fork: {} that I was attempting to use may not have helped).

For example: some sites said that each line should end in "\r\n"--whereas I had been using just "\n". Was this something that the CGI package was "fixing" for me automatically? Did I need to add this manually? Another point of question was whether or not each line of the header should end in a comma, and whether or not this included the last line of the header, too. Perhaps the comma was just required by the CGI package, and not by the client. I searched in vain online for http header syntax. I found sites that claimed to say something about it, alright, but they focused on the headers themselves, not whether or not they should be case-sensitive, or how their lines should end, or anything else that I needed to know.

In the end, I found an answer online with two lines, printed as I posted in my solution except that the second one had the double newline, that worked! I then added only the third line--the Content-length. Seeing that it worked satisfied me. Its simplicity pleased me. I am certain it could still be improved, and originally I did have all of it in a multi-line quote to be printed at once--but that was back when things were not working. Once I got it all working, I tended to let it be as it was! So that's how there got to be multiple print lines. I do not, however, presume that it must be this way, nor that it would not be superior to combine them. But it works; as-is. And with that I am, for now, content.

Blessings,

~Polyglot~

Replies are listed 'Best First'.
Re^4: Perl output is not inducing file download as expected
by haukex (Archbishop) on Sep 24, 2023 at 21:16 UTC
    I searched in vain online for http header syntax.

    See the Wikipedia page for HTTP, you'll find a list of RFCs that give the exact specifications.