#1 2019-03-29 14:24:16

pandaben7890
Member
Registered: 2017-12-11
Posts: 12

Ctxt.Call.InBody in TSQLRestServer.OnAfterURI is not correct????

This is when I start service

....
aProps := TOleDBMSSQL2012ConnectionProperties.Create(servername, databasename, username, password);
ServerDB := TSQLRestServerWS.Create(Model, ':memory:', True);
ServerDB.OnAfterURI := OnServerAfterURI;
HttpServer := TSQLHttpServer.Create(port, [ServerDB]);
.....

Callback function

procedure TSM.OnServerAfterURI(Ctxt: TSQLRestServerURIContext);
begin
  UT.Log(Ctxt.Call.InBody);
end;

UT.Log is just function that log text to file

This is what I got on output.txt

[
  "{"onlyunread":"Y","size":9999999} 9999}"

There is newline after the bracket and garbage at the end which screw JSON format

This is what Angular actually sent

["{"onlyunread":"Y","size":9999999}"]

I just want to log what Angular sent me as input when they request API to mORMot.
PS. sorry for my bad English. I'm not a native speaker U_U

Offline

#2 2019-03-29 18:58:24

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

Re: Ctxt.Call.InBody in TSQLRestServer.OnAfterURI is not correct????

This is as expected: the input content, i.e. Call.InBody has been parsed in-place, with no memory allocation.
It is done as such for performance reasons.

If you want the input body untouched, use OnServerBeforeURI.

BTW the framework already has several ways of logging built-in - up to inside a database - so take a look at it before reinventing the wheel.
It will be much more powerful, and less invasive, than any other solution.
See https://synopse.info/files/html/Synopse … l#TITL_183

Offline

#3 2019-03-30 05:19:05

pandaben7890
Member
Registered: 2017-12-11
Posts: 12

Re: Ctxt.Call.InBody in TSQLRestServer.OnAfterURI is not correct????

Information I want is
- InputBody
- InputHeader (i sent something useful from Angular) (UserAgent and RemoteIP also)
- OutputBody (so OnServerBeforeURI won't have this data like OnAfterBeforeURI?)
- MicroSecondsElapsed (OnAfterBeforeURI has Ctxt.MicroSecondsElapsed)

Actually I try AddInterceptor(), every data I want is all fine except just

Ctxt.MicroSecondsElapsed always 0

Offline

Board footer

Powered by FluxBB