Thread View: borland.public.cppbuilder.internet.socket
4 messages
4 total messages
Started by WimB
Thu, 10 Jul 2008 10:20
TIdHTTPResponseInfo WriteContent (or not)
Author: WimB
Date: Thu, 10 Jul 2008 10:20
Date: Thu, 10 Jul 2008 10:20
37 lines
2073 bytes
2073 bytes
Hi, I've created a webserver that servers pages and binaries etc. All works well, but I'm confused about the usage of WriteContent. Do I need to call this, or is it automatically called? It seems that without, the responses are also correct. Without diving into Indy10 myself, maybe anyone can shed some light on it? Thanks in advance, WimB. example, in serverCommandGet: TMemoryStream* MemoryStream = new TMemoryStream(); MemoryStream->LoadFromFile(....->LocalDoc); HttpRequest->ResponseInfo->FreeContentStream = true; HttpRequest->ResponseInfo->ResponseNo = 200; HttpRequest->ResponseInfo->ContentType = ContentType; HttpRequest->ResponseInfo->ContentLength = (int)MemoryStream- >Size; HttpRequest->ResponseInfo->ContentStream = MemoryStream; HttpRequest->ResponseInfo->WriteContent; works fine, and: TStringList* StringList = new TStringList(); StringList->LoadFromFile(HttpRequest->LocalDoc); HttpRequest->Content = StringList->Text; delete StringList; AnsiString ContentText = ReplaceTags(HttpRequest); HttpRequest->ResponseInfo->ResponseNo = 200; HttpRequest->ResponseInfo->ContentType = ContentType; HttpRequest->ResponseInfo->ContentText = ContentText; HttpRequest->ResponseInfo->ContentLength = ContentText.Length(); also works fine.
Re: TIdHTTPResponseInfo WriteContent (or not)
Author: Remy Lebeau (TeamB)
Date: Thu, 10 Jul 2008 16:37
Date: Thu, 10 Jul 2008 16:37
13 lines
1580 bytes
1580 bytes
"WimB" <wim....@.....nl> wrote in message news:4875e25d$1@newsgroups.borland.com... > Hi, I've created a webserver that servers pages and binaries etc. > All works well, but I'm confused about the usage of WriteContent. > Do I need to call this, or is it automatically called? WriteContent() is called automatically after the OnCommandGet event handler exits, if the handler did send the response headers yet. Gambit
Re: TIdHTTPResponseInfo WriteContent (or not)
Author: Wim Bekker
Date: Thu, 10 Jul 2008 21:57
Date: Thu, 10 Jul 2008 21:57
35 lines
2093 bytes
2093 bytes
Remy Lebeau (TeamB) schreef:
> WriteContent() is called automatically after the OnCommandGet event handler
> exits, if the handler did send the response headers yet.
Thanks for your answer and it raises some other questions:
How do I know if the response headers are sent yet? I assume that if I
always call WriteContent, I'm sure that it is send.
At one point I check for the head:
if (AnsiSameText(RequestInfo->Command, "HEAD"))
HandleHead(LocalDoc,ResponseInfo);
else
HandleNormalDoc(LocalDoc,AThread,RequestInfo, ResponseInfo);
In HandleHead, I do:
ResponseInfo->ContentType = GetMIMEType(LocalDoc);
ResponseInfo->WriteHeader();
After this, OnCommandGet exists (without serving the file). Is this
correct? Does it do WriteContent?
If LocalDoc doesn't exists, I do:
ResponseInfo->ResponseNo = 404; // - Not Found
I noticed that if I leave the WriteContent out, the result is a blank
page. If I do WriteContent, I receive a small 404 Not found message. In
this case I do have to manually call WriteContent shouldn't I?
Wim
Re: TIdHTTPResponseInfo WriteContent (or not)
Author: Remy Lebeau (TeamB)
Date: Thu, 10 Jul 2008 22:44
Date: Thu, 10 Jul 2008 22:44
41 lines
2429 bytes
2429 bytes
"Wim Bekker" <wim....@.....nl> wrote in message news:4876859d@newsgroups.borland.com... > How do I know if the response headers are sent yet? The TIdHTTPResponseInfo::HeaderHasBeenWritten property, which is set by WriteHeader(). Generally, you shouldn't worry about calling WriteContent() manually. Just set the response properties and let the server send the response automatically. > In HandleHead, I do: > ResponseInfo->ContentType = GetMIMEType(LocalDoc); > ResponseInfo->WriteHeader(); > > After this, OnCommandGet exists (without serving the file). > Is this correct? Does it do WriteContent? After OnCommandGet exits, WriteHeader() is called if HeaderHasBeenWritten is false, and WriteContent() is called if there is any value assigned to the ContentText or ContentStream property. > I noticed that if I leave the WriteContent out, the result is a blank > page. Because no data is being sent to the client at all, other than the headers. > If I do WriteContent, I receive a small 404 Not found message. If ContentText and ContentStream() are both empty, then WriteContent() sends a small HTML page containing just the ResponseNo and ResponseText values. > In this case I do have to manually call WriteContent shouldn't I? If you assign the ContentText or ContentStream, then WriteContent() is called automatically. Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads