Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Custom header from Indy HTTP Server componenet

1,381 views
Skip to first unread message

Andy

unread,
Mar 21, 2002, 3:37:43 PM3/21/02
to

Hello,

I would like to create a custom header to send back to a client
request. I have a web server created using the Indy HTTP Server
component (TIdHTTPServer). If you create an OnCommandGet event then there is a ResponseInfo command with parameters you can set
that will then get sent to the client. There is a CustomHeaders
option but it's a TIdHeaderList type and how would I set text for
it? When I try it obviously gives me a can not convert char to
TIdHeaderList. Can anyone help?

Thanks in advance.

Andy

Remy Lebeau [TeamB]

unread,
Mar 21, 2002, 3:56:00 PM3/21/02
to
AResponseInfo->CustomHeaders->Values["MyHeader"] = "MyValue";


Gambit

"Andy" <ju...@guessagain.net> wrote in message news:3c9a4497$2_1@dnews...

Junk

unread,
Mar 21, 2002, 8:19:28 PM3/21/02
to
Gambit,

That worked perfect, thank you!
Now this question is more for HTML probably but since you knew the last
question I thought maybe
you would know this to. I am setting the custom header to return "HTTP/1.0
200 OK". I was told
if I send this and do not send a ContentLength, then the client would not
know when the page was
done loading and would keep the connection open to the web server. This
would allow me to keep
pushing down data from the server as I need to. So I tried this but the
client keeps loading the web
page and stopping like normal. Do you know what I might be doing wrong (or
anyone)? Thanks again.

Andy

"Remy Lebeau [TeamB]" <gamb...@yahoo.com> wrote in message
news:3c9a4943$1_2@dnews...

Remy Lebeau [TeamB]

unread,
Mar 21, 2002, 8:47:20 PM3/21/02
to
What EXACTLY are you trying to accomplish with all of this?

If all you want to do is keep the connection open, you can simply make sure
the AResponseInfo->CloseConnection property is false. It's already false by
default (based on the HTTPServer's KeepAlive property).


Gambit

"Junk" <ju...@guessagain.net> wrote in message news:3c9a8687_1@dnews...

Junk

unread,
Mar 22, 2002, 3:02:18 AM3/22/02
to
I am trying to create a page like the one on the Borland chat page
(http://community.borland.com). If you go to the chat link you will notice
how the page is constantly loading and never stops. This keeps the port
open to the client so the server can keep shoving data down to it as it gets
it. I want to create a page similar to that.


"Remy Lebeau [TeamB]" <gamb...@yahoo.com> wrote in message

news:3c9a8c6f$1_1@dnews...

Remy Lebeau [TeamB]

unread,
Mar 22, 2002, 12:25:49 PM3/22/02
to
The chat is controlled by the server-side script. Generally, such pages are
generated when the server launches a CGI/PERL script and waits for it to
finish executing, all the while that script writes output to the stdout of
the server itself, which happens to go directly to the browser. So as long
as the script is running, the connection stays open by the program running
the script.

(untested) In your case, as soon as OnCommandGet exits, the connection will
probably close. So what you can try doing is enter a loop that repeatedly
sets the AResponseInfo->ContentText property (not ContentStream, as it gets
automatically freed every time) and then call it's WriteContent() method
until your'e done. Drop a TIdAntiFreeze component onto the form (or call
Application->ProcessMessages()) so your program remains responsive.


Gambit

"Junk" <ju...@guessagain.net> wrote in message news:3c9ae4ee$1_1@dnews...

Andy

unread,
Mar 22, 2002, 1:46:10 PM3/22/02
to

Gambit,

Thank you again, that does keep the page open but it's not
quite the same as what the chat page does. Let me paste a
conversation between myself and Simon Kissel (the one who
created the chatjet program that's used on Borland's chat
page)...


andy: I love the way your chatjet program works and from what I understand it was created using Delphi? Is that right?
SimonK: Yes
SimonK: And the linux version is done with kylix
andy: Ok. Yeah, I understand that´s what Borland is using.
andy: Now, I use C++ Builder and here is what I´m trying to do....
andy: Create a web page that will update multiple clients (web browsers) connected with live changing data...
andy: Now your chat program looks like it keeps an open port to the client and the client looks like it´s constantly loading the page thus constantly grabbing new data the server puts out, is this how it works?
SimonK: yes
SimonK: the connection is never closed...
SimonK: there are a few tweaks so that it also works with proxys,
SimonK: but yes, that´s the basic idea.
SimonK: open a http connection and never close it...
SimonK: and make the streaming frame update all other frames.
andy: Now obviously you can´t give me your source code ;) but is there anyway you can give me an example of how this works. Would I have to use C++ to do this or do you have HTML or Javascript or something that would give me a clue as to how this works?
SimonK: Well
andy: My main thing is how do you keep the streaming frame connected and constantly pulling data?
SimonK: it´s not pulling
SimonK: the server is pushing
andy: Server is pushing?
SimonK: it´s very easy
SimonK: open a server socket,
SimonK: write out HTTP/1.0 200 OK
SimonK: and all additional headers you want,
SimonK: but DON´T set a Content-Length Header
SimonK: this way the browser doesn´t know when loading of file has finished
SimonK: so instead it will load until server closes connection.
SimonK: then just write out all the data you want.
SimonK: if you need longer pauses, you´ll have to send some filler stuff,
SimonK: so the connection doesn´t time out.


Now how would I implement the way Simon does it? Thanks again.

Andy

Remy Lebeau [TeamB]

unread,
Mar 22, 2002, 2:34:01 PM3/22/02
to
From the looks of the TIdHTTPResponseInfo source code, it's handling of the
HTML header is not going to support what you're looking for, as it forces
the connection closed after the content has been sent. You'll have to write
the header directly to the socket connection yourself:

void __fastcall TIdHTTPServer1CommandGet(TIdPeerThread *AThread,
TIdHTTPRequestInfo *ARequestInfo, TIdHTTPResponseInfo *AResponseInfo)
{
// ... process the request as needed first

AThread->Connection->WriteLn("HTTP/1.0 200 OK");

// Write your own headers directly

AThread->Connection->WriteLn("Content-Type: TheContentType");
// etc...

AResponseInfo->HeaderHasBeenWritten = true;

while(doSomething)
{
AResponseInfo->ContentText = "new text";
AResponseInfo->WriteContent();
}
}


Gambit

"Andy" <ju...@guessagain.net> wrote in message news:3c9b7bf2$1_2@dnews...

0 new messages