Merge pull request #7 from petdr/master

Add content-length header to frames.
This commit is contained in:
Daniele Teti 2016-02-15 08:50:02 +01:00
commit 31001af0cb
2 changed files with 14 additions and 0 deletions

View File

@ -405,6 +405,10 @@ begin
h := AHeaders.GetAt(i); h := AHeaders.GetAt(i);
AFrame.GetHeaders.Add(h.Key, h.Value); AFrame.GetHeaders.Add(h.Key, h.Value);
end; end;
// If the frame has some content, then set the length of that content.
if (AFrame.ContentLength > 0) then
AFrame.GetHeaders.Add('content-length', IntToStr(AFrame.ContentLength));
end; end;
procedure TStompClient.Nack(const MessageID, TransactionIdentifier: string); procedure TStompClient.Nack(const MessageID, TransactionIdentifier: string);

View File

@ -63,6 +63,7 @@ type
procedure SetBody(const Value: string); procedure SetBody(const Value: string);
function GetHeaders: IStompHeaders; function GetHeaders: IStompHeaders;
function MessageID: string; function MessageID: string;
function ContentLength: Integer;
end; end;
IStompClient = interface IStompClient = interface
@ -136,6 +137,7 @@ type
private private
FCommand: string; FCommand: string;
FBody: string; FBody: string;
FContentLength: Integer;
FHeaders: IStompHeaders; FHeaders: IStompHeaders;
procedure SetHeaders(const Value: IStompHeaders); procedure SetHeaders(const Value: IStompHeaders);
function GetCommand: string; function GetCommand: string;
@ -153,6 +155,7 @@ type
// otherwise, return Value; // otherwise, return Value;
function Output: string; function Output: string;
function MessageID: string; function MessageID: string;
function ContentLength: Integer;
property Headers: IStompHeaders read GetHeaders write SetHeaders; property Headers: IStompHeaders read GetHeaders write SetHeaders;
end; end;
@ -286,6 +289,7 @@ begin
FHeaders := TStompHeaders.Create; FHeaders := TStompHeaders.Create;
self.FCommand := ''; self.FCommand := '';
self.FBody := ''; self.FBody := '';
self.FContentLength := 0;
end; end;
destructor TStompFrame.Destroy; destructor TStompFrame.Destroy;
@ -319,9 +323,15 @@ begin
COMMAND_END; COMMAND_END;
end; end;
function TStompFrame.ContentLength: Integer;
begin
Result := FContentLength;
end;
procedure TStompFrame.SetBody(const Value: string); procedure TStompFrame.SetBody(const Value: string);
begin begin
FBody := Value; FBody := Value;
FContentLength := Length(TEncoding.UTF8.GetBytes(FBody));
end; end;
procedure TStompFrame.SetCommand(const Value: string); procedure TStompFrame.SetCommand(const Value: string);