You are not logged in.
Thank you for great product!
I'm trying to use Http API Sever separately of framework and found that there is no access to Client IP/Port and Cookie info.
I've added it for me but is it possible to add these properties to main source?
Suppose it will be helpful for sessions support when using HttpAPI server separately.
What was added:
THttpServerRequest = class
..
protected
...
fClientIP: rawbytestring;
fClientPort: integer;
fCookie: rawbytestring;
public
property ClientIP: rawbytestring read fClientIP write fClientIP;
property ClientPort: integer read fClientPort write fClientPort;
property Cookie: rawbytestring read fCookie write fCookie;
procedure THttpApiServer.Execute;
...
after Context.OutCustomHeaders := '';
Context.fClientIP:=Format('%d.%d.%d.%d', [Req.Address.pRemoteAddress.sin_addr.S_bytes[0],
Req.Address.pRemoteAddress.sin_addr.S_bytes[1], Req.Address.pRemoteAddress.sin_addr.S_bytes[2], Req.Address.pRemoteAddress.sin_addr.S_bytes[3]]);
Context.fClientPort:=Req.Address.pRemoteAddress.sin_port;
SetString(Context.fCookie, Req.Headers.KnownHeaders[reqCookie].pRawValue, Req.Headers.KnownHeaders[reqCookie].RawValueLength);
Offline
As we already stated several times, we handle the cookies/ip process at TSQLRest level.
So you could use code like you wrote to have it seperated at THttpApi instead.
But a few remarks:
- Your IP computation won't work as expected with IPv6, and in fact, there is already a 'RemoteIP: 127.0.0.1' entry in the generated HTTP headers, supporting IPv6.
- BTW you are mixing Ansi and Unicode strings by using format() and RawByteString
- I suspect you should better use getter functions instead of modifying the Execute method.
Offline
Thanks for remarks!
As we already stated several times, we handle the cookies/ip process at TSQLRest level.
So you could use code like you wrote to have it seperated at THttpApi instead.
But how to access Req variable (: PHTTP_REQUEST which contains parsed headers) from other class? It seems to be THttpApiServer.Execute local variable and doesn't published anywhere
Offline