You are not logged in.
Pages: 1
Is this code correct? (SynCommons unit)
function RawUnicodeToUtf8(Dest: PUTF8Char; DestLen: PtrInt; Source: PWideChar; SourceLen: PtrInt): PtrInt; overload;
var c: Cardinal;
Tail: PWideChar;
i,j: integer;
begin
result := PtrInt(Dest);
if (Source<>nil) and (Dest<>nil) then begin
// first handle 7 bit ASCII WideChars, by pairs (Sha optimization)
SourceLen := SourceLen*2+PtrInt(Source);
Tail := PWideChar(SourceLen)-2;
if Source<=Tail then
repeat
c := PCardinal(Source)^;
if c and $ff80ff80<>0 then
break; // break on first non ASCII pair
inc(Source,2);
c := c shr 8 or c;
pWord(Dest)^ := c;
inc(Dest,2);
until Source>Tail;
// generic loop, handling one UCS4 char per iteration
Inc(DestLen,PtrInt(Dest));
Shouldn't
Inc(DestLen,PtrInt(Dest));
be placed before the cycle? Now DestLen do not point to real Dest end
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
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);
Pages: 1