I'm having the craziest issue with Firefox. I'm not sure if this issue is coming from Firefox its self, or from my custom web server (built in Delphi) or what it might be. This problem only happens in Firefox (and Opera) where it is both moving everything from the head down to the body, and also adding random characters at the beginning of the body. Strangely, it even does it with a completely 100% empty web page.
I'm testing with a page as simple as this:
<html>
<head>
<title>Test</title>
</head>
<body>
</body>
</html>
As for the Web Server, I'm building a custom HTTP App in Delphi using IdHTTPWebBrokerBridge
(Indy) and simply replacing the ContentStream
(or Content
) of the Request
like so...
procedure TDashModule.DashConsoleHomeAction(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
Response.ContentType:= 'text/html';
Response.ContentStream:= TFileStream.Create('C:\SomeDir\SomeFile.html', fmOpenRead or fmShareDenyNone);
end;
...where SomeFile.html
is the empty page as posted above, and the procedure being an event handler for the default request handler.
In Chrome, IE, Safari, etc. everything shows exactly as the original code. However, Firefox (and Opera) are producing this:
<html>
<head>
</head>
<body>

<title>Test</title>
</body>
</html>
As you can see, the title
tag has been moved down to the body
, and some random characters 
are appearing at the very beginning of the body. When viewing the raw page as its original file in Firefox, it shows correctly. But when using my web server in Delphi, Firefox is destroying this page (and all pages, for that matter).
What could be doing this and how to fix it?
Steps to reproduce
A) Create a new HTML Page (for me in Visual Studio 2010) with just this content:
<html>
<head>
<title>Test</title>
</head>
<body>
</body>
</html>
B) In Delphi XE2, start a new project: File > New > Other... > Web Broker > Web Server Application
C) Choose Stand-alone VCL Application
> Next > Finish
D) Create a default handler (Right-click WebModule1
and choose Action Editor...
)
E) For DefaultHandler
item, go to the Event Properties and go to the Event Handler for OnAction
F) Replace any code that's already there with this (replace filename with HTML filename):
Response.ContentStream:= TFileStream.Create('C:\SomeDir\SomeFile.html', fmOpenRead or fmShareDenyNone);
E) Run application and click "Show In Browser" - copy/paste the URL to Firefox if necessary.
UPDATE
Thanks to the help, I've come to realize the issue is with the BOM tag of the file, which did not belong there. It was due to how the TFileStream
works, it loads every little piece of the file, which included this code. I've changed my method to using TStringList.LoadFromFile()
instead, because this automatically detects it and I can also read TStringList.Text
to assign to Response.Content
.