Lazarus

Programming => Networking and Web Programming => Topic started by: loaded on January 29, 2020, 03:00:04 pm

Title: [Solved] Cannot display socket header data in IdHTTPProxyServer
Post by: loaded on January 29, 2020, 03:00:04 pm
Hello to everyone
I am using IdHTTPProxyServer included in Indy 10.6.2.5494 package.
The application runs smoothly, but to see the header data from the users to the IdHTTPProxyServer1Connect method

when I add the code

Code: Pascal  [Select][+][-]
  1. procedure TForm1.IdHTTPProxyServer1Connect(AContext: TIdContext);
  2. begin
  3.    memo1.lines.add(AContext.Connection.Socket.ReadLn); //<-
  4. end;  
  5.  

The project is inoperable. What could be the reason for this?
I would be glad if you can get the idea and help. Respects.
Title: Re: Cannot display socket header data in IdHTTPProxyServer
Post by: Remy Lebeau on January 29, 2020, 08:35:06 pm
Why are you reading the client's request data in the TIdHTTPProxyServer.OnConnect event?  You should not be doing that at all.  You are reading the request line that specifies the HTTP method and URL being requested by the client, which means that line is no longer available for TIdHTTPProxyServer to read, so it won't know how to process the request correctly.

If you want access to the client's request headers, you need to either:


Either way, the client's request headers will be in the provided TIdHTTPProxyServerContext object's Headers property when its TransferSource property is tsClient.

Also, TIdHTTPProxyServer is a multi-threaded component.  Its events are fired in the context of worker threads, not in the main UI thread.  As such, you cannot safely access UI controls directly like you are.  You MUST synchronize with the main UI thread, such as with the RTL's TThread.Synhronize() or TThread.Queue() methods, or Indy's TIdSync or TIdNotify classes.
Title: Re: Cannot display socket header data in IdHTTPProxyServer
Post by: loaded on January 29, 2020, 09:01:50 pm
Thank you so much for your answer to Remy Lebeau.
I want to do;
Except for a single web resource I specified, it was to end incoming connection requests.
So I thought the Onconnect method was appropriate.
I was wrong, the method you said worked. Also thank you for writing Indy and for all your efforts. Respects.
TinyPortal © 2005-2018