🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #4957

Non AnsiString Incoming Buffering in Indy Servers

#4957
From: Colin B Maharaj
Date: Mon, 22 Nov 2004 10:52
65 lines
3449 bytes
Hi All, I am trying to write a Proxy Server (Yes I know there is one 
already - but this is purely academic).

What I have been noticing is that certain Web Servers that know I am 
running from a Proxy and is sending a message to tell me that it will 
keep the TCP connection up. This message is ....

Proxy-Connection: Keep-Alive

Now this is all well and good except the code I am using and that I see 
in the ProxyServer Code in Indy is like this.....

FIRST : MY CODE................................................

  // Make Proxy Connection to Server -------------------
   TIdTCPClient *WebSite = new TIdTCPClient(NULL);
   WebSite->Port = 80;
   WebSite->Host = Host; gotten earlier.....
   WebSite->Connect();

  // Send headers to server ---------------------------
   WebSite->WriteStrings(BrowserHdr); // gotten earlier

   // Transfer all data to Browser --------------------
   TMemoryStream * Stream = new TMemoryStream;
   WebSite->ReadStream(Stream, -1, true); // read from site to stream
   AThread->Connection->WriteStream(Stream); // Problem with this id 
keep alive
   delete Stream;
   AThread->Connection->Disconnect();
   delete BrowserHdr; // created earlier
   WebSite->Disconnect();
   delete WebSite;


SECOND: INDY........................................................
	
procedure TIdHTTPProxyServer.TransferData(ASrc: TIdTCPConnection; ADest: 
TIdTCPConnection;
  const ADocument: string; const ASize: Integer);
//TODO: This captures then sends. This is great and we need this as an 
option for proxies that
// modify data. However we also need another option that writes as it 
captures.
// Two modes? Intercept and not?
var
   LStream: TStream;
begin
   //TODO: Have an event to let the user perform stream creation
   LStream := TMemoryStream.Create; try
       ASrc.ReadStream(LStream, ASize, ASize = -1);
     LStream.Position := 0;
     DoHTTPDocument(ADocument, LStream);
     ADest.WriteStream(LStream);
   finally FreeAndNil(LStream); end;
end;

//////////////////////////////////////////////////////////////////////

Here is the question, How can I get incoming data from a TCP Connection 
that does not go to an AnsiString but to a buffer of sorts, that may 
contain null characters in between (e.g. jpeg image). Also this routing 
must be able to 'timeout' as it were since some connection may not drop 
cause of the keep alive scenario, and the code you see above only 
continues after a disconnect from the web server.
Technical Details
Message-ID: <41a1c4cf$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,9e62d9fb8e1bfe4a,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Mon, 22 Nov 2004 06:52:01 -0400
From: Colin B Maharaj <noreply@myhost.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7a) Gecko/20040219
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Non AnsiString Incoming Buffering in Indy Servers
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 200.108.15.43
Message-ID: <41a1c4cf$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1101120719 200.108.15.43 (22 Nov 2004 02:51:59 -0700)
Lines: 66
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail