Re: [fpc-pascal] TJSONRPCModule: access the request from an handler.

2022-09-09 Thread Michael Van Canneyt via fpc-pascal




On Fri, 9 Sep 2022, Luca Olivetti via fpc-pascal wrote:


El 9/9/22 a les 15:50, Michael Van Canneyt ha escrit:


The solution is much more simple.

Override HandleRequest() in the module.
Save the request in a variable and call inherited.


Much simpler indeed! Thank you.
In my case I just save the remote address, but in your example below I 
suppose you redefined FRequest (and FResponse) to hide the private one in the 
ancestor, but what I don't understand is the C:=C+C and the need to set 
FRequest and FResponse to nil.


You can remove the C variable stuff, it was for debugging purposes. I simply
didn't remove it during the copy & paste.

I set the variables to Nil after calling inherited (where the request is
actualluy handled) so they are not inadvertently used in the
OnDestroy of the datamodule.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TJSONRPCModule: access the request from an handler.

2022-09-09 Thread Luca Olivetti via fpc-pascal

El 9/9/22 a les 15:50, Michael Van Canneyt ha escrit:


The solution is much more simple.

Override HandleRequest() in the module.
Save the request in a variable and call inherited.


Much simpler indeed! Thank you.
In my case I just save the remote address, but in your example below I 
suppose you redefined FRequest (and FResponse) to hide the private one 
in the ancestor, but what I don't understand is the C:=C+C and the need 
to set FRequest and FResponse to nil.




I have code that needs to work with 3.2.2 and I do this:

---
procedure TUserRPCModule.HandleRequest(ARequest: TRequest; AResponse: 
TResponse);


Var
   C : String;

begin
   FRequest:=aRequest;
   FResponse:=aResponse;
   try
     C:=FRequest.Content;
     C:=C+C;
     inherited HandleRequest(ARequest, AResponse);
   finally
     FRequest:=Nil;
     FResponse:=Nil;
   end;
end;


Bye
--
Luca

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] TJSONRPCModule: access the request from an handler.

2022-09-09 Thread Michael Van Canneyt via fpc-pascal




On Fri, 9 Sep 2022, Luca Olivetti via fpc-pascal wrote:


Hello,

I added a "Web JSON-RPC Module" to my project, I dropped on it a 
TJSONPCHandler.


I find no way to access the request (I want to check the RemoteAddress):

1) the module has a "Request" field but it is always nil (either in 
DataModuleCreate, which isn't called with every request so it's unusable 
anyway, in BeforeExecute and in Execute, I didn't check AfterExecute but it 
would be too late).


This is fixed in trunk: Request is always available.



2) the JSONRPCHandler has no way to access the request (or I couldn't find 
it).


I guess that, instead of calling the RegisterHTTPModule of the module, I 
should register the route in my webserver class (with 
httprouter.RegisterRoute), but what should I do in the handler to delegate 
the handling to the JSONRPCModule?


The solution is much more simple.

Override HandleRequest() in the module.
Save the request in a variable and call inherited.

I have code that needs to work with 3.2.2 and I do this:

---
procedure TUserRPCModule.HandleRequest(ARequest: TRequest; AResponse: 
TResponse);

Var
  C : String;

begin
  FRequest:=aRequest;
  FResponse:=aResponse;
  try
C:=FRequest.Content;
C:=C+C;
inherited HandleRequest(ARequest, AResponse);
  finally
FRequest:=Nil;
FResponse:=Nil;
  end;
end;
---


Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] TJSONRPCModule: access the request from an handler.

2022-09-09 Thread Luca Olivetti via fpc-pascal

Hello,

I added a "Web JSON-RPC Module" to my project, I dropped on it a 
TJSONPCHandler.


I find no way to access the request (I want to check the RemoteAddress):

1) the module has a "Request" field but it is always nil (either in 
DataModuleCreate, which isn't called with every request so it's unusable 
anyway, in BeforeExecute and in Execute, I didn't check AfterExecute but 
it would be too late).


2) the JSONRPCHandler has no way to access the request (or I couldn't 
find it).


I guess that, instead of calling the RegisterHTTPModule of the module, I 
should register the route in my webserver class (with 
httprouter.RegisterRoute), but what should I do in the handler to 
delegate the handling to the JSONRPCModule?


Bye
--
Luca
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal