#1 2024-11-08 13:23:17

Kabiri
Member
Registered: 2024-06-22
Posts: 38

THttpProxyServer Inquiry

Hello,
I'm working with a THttpProxyServer.
I know I can add directories to it before creating the server. (settings.AddFolder(folder, url);)
1)What I'd like to know is how to dynamically add directories and map them to URLs after the server has been created and started?
2)Additionally, does THttpProxyServer support an IP whitelist? If so, how can I modify this list after the server has started?

Offline

#2 2024-11-09 02:50:08

zen010101
Member
Registered: 2024-06-15
Posts: 69

Re: THttpProxyServer Inquiry

Maybe you call call Stop method first, then Start again.


You can take a look at the source code of the AfterServerStarted() method, and then you can manually control fServer.Route function. The core statement is :

    old := fServer.ReplaceRoute(new); 

Offline

#3 2024-11-09 02:56:07

zen010101
Member
Registered: 2024-06-15
Posts: 69

Re: THttpProxyServer Inquiry

Regarding whitelist, you can check out THttpServer.Banned property which is THttpAcceptBan type that has some features about whitelist.

Offline

#4 2024-11-09 17:16:30

Kabiri
Member
Registered: 2024-06-22
Posts: 38

Re: THttpProxyServer Inquiry

Thank you @zen010101
I just didn't understand about the whitelist.

Offline

#5 2024-11-10 09:20:42

zen010101
Member
Registered: 2024-06-15
Posts: 69

Re: THttpProxyServer Inquiry

Kabiri wrote:

Thank you @zen010101
I just didn't understand about the whitelist.

Sorry, I found that the WhiteIP property of THttpAccsptBan seems to only be able to contain one IP address that should not be banned.

    /// a 32-bit IP4 which should never be banned
    // - is set to cLocalhost32, i.e. 127.0.0.1, by default
    property WhiteIP: cardinal
      read fWhiteIP write fWhiteIP; 

Offline

#6 2024-11-23 12:18:29

Kabiri
Member
Registered: 2024-06-22
Posts: 38

Re: THttpProxyServer Inquiry

I couldn't find a solution to dynamically create a whitelist of IP addresses.

Offline

#7 2024-11-23 20:51:09

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,679
Website

Re: THttpProxyServer Inquiry

You can use the OnBeforeBody event at the HTTP server level.
The RemoteIP is provided, and you can reject the request ASAP.

Offline

#8 2024-11-24 13:38:09

Kabiri
Member
Registered: 2024-06-22
Posts: 38

Re: THttpProxyServer Inquiry

Thanks @ab.
I used it(OnBeforeBody) to create the whitelist and work fine.

Do you have any suggestions for adding and removing routes after starting the server without stopping it? 
Since many methods of `THttpProxyUrl` are defined as `protected`, I cannot use them in my class. It seems I have to add a function for this in the `mormot.net.async` unit.

Offline

#9 2024-11-24 16:24:26

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,679
Website

Re: THttpProxyServer Inquiry

You have THttpServerGeneric.ReplaceRoute() which is not optimal, but should be thread-safe.
Or you can use TUriRouter.Clear then re-register all routes. TUriRouter should be thread-safe in itself.

But if you want to add or remove a set of routes, you may define all possible route URIs, then eventually reject some "removed/disabled" route URIs.

Or just don't use the routes, but good plain OnRequest().

Offline

#10 2024-11-26 07:06:54

Kabiri
Member
Registered: 2024-06-22
Posts: 38

Re: THttpProxyServer Inquiry

I used the `THttpProxyServer` server. 
There are about 100 files on the server, and I want to share them with authorized users. 
I want to create a unique URL for each task. 
When the program runs, those files should be accessible in Google Chrome through the URL provided to the user by the program (on the same system where the program is running). 
For this reason, I used `THttpProxyServer`. 
I don't know if `THttpServerGeneric.ReplaceRoute()` can be used with `THttpProxyServer` or not. 
I want to create an interface that adds a new route to the `THttpProxyServer` server and specifies which file this route corresponds to. Then, in the `OnBeforeBody` section, if the IP does not correspond to the URL, return a 404 error. 

1. I have created the `THttpProxyServer` server. 
2. I have completed the `OnBeforeBody` section to check the URL and IP. 
3. I need to create an interface to add or remove URLs in the `THttpProxyServer`.

Last edited by Kabiri (2024-11-26 07:11:14)

Offline

Board footer

Powered by FluxBB