Search code examples
htmldelphiformattingindyhttpserver

TIdHTTPServer altering HTML


I'm using the TIdHTTPServer to host a large set of existing HTML files. However, I have a problem where it's returning altered HTML. Mainly, double quotes () are being replaced with jibberish like “. Viewing the HTML file directly from my filesystem in Edge shows just fine, but the same page / file when served through this Indy HTTP server gets altered.

I'm returning the file via a TFileStream like so:

    FS:= TFileStream.Create(FN, fmOpenRead);
    AResponseInfo.ContentStream:= FS;

    FE:= LowerCase(ExtractFileExt(FN));
    if FMime.IndexOfName(FE) >= 0 then
      CT:= FMime.Values[FE]
    else
      CT:= 'application/octet-stream';

    AResponseInfo.ContentType:= CT; //text/html in this case

The raw HTML file has this:

<p>“<strong>Y</strong>” = Consigned</p>

...which looks like this:

Correct formatting

But when served through Indy, the HTML has this:

<p>“<strong>Y</strong>†= Consigned</p>

...which looks like this:

Incorrect formatting

What is going wrong, and how do I fix it?


Solution

  • I just figured it out - I need to set the character set:

    AResponseInfo.CharSet := 'utf-8';