Recent

Author Topic: [Solved] Cannot display socket header data in IdHTTPProxyServer  (Read 1431 times)

loaded

  • Hero Member
  • *****
  • Posts: 824
[Solved] Cannot display socket header data in IdHTTPProxyServer
« 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.
« Last Edit: January 29, 2020, 09:02:07 pm by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: Cannot display socket header data in IdHTTPProxyServer
« Reply #1 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:

  • use the TIdHTTPProxyServer.OnHTTPBeforeCommand event
  • set the TIdHTTPProxyServer.TransferMode property to tmFullDocument and use the TIdHTTPProxyServer.OnHTTPDocument event

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.
« Last Edit: January 29, 2020, 08:39:57 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

loaded

  • Hero Member
  • *****
  • Posts: 824
Re: Cannot display socket header data in IdHTTPProxyServer
« Reply #2 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.
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

 

TinyPortal © 2005-2018