diff --git a/StompClient.pas b/StompClient.pas index 56b69887..cb725c18 100644 --- a/StompClient.pas +++ b/StompClient.pas @@ -405,6 +405,10 @@ begin h := AHeaders.GetAt(i); AFrame.GetHeaders.Add(h.Key, h.Value); 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; procedure TStompClient.Nack(const MessageID, TransactionIdentifier: string); diff --git a/StompTypes.pas b/StompTypes.pas index bd08fdb0..a16c3088 100644 --- a/StompTypes.pas +++ b/StompTypes.pas @@ -63,6 +63,7 @@ type procedure SetBody(const Value: string); function GetHeaders: IStompHeaders; function MessageID: string; + function ContentLength: Integer; end; IStompClient = interface @@ -136,6 +137,7 @@ type private FCommand: string; FBody: string; + FContentLength: Integer; FHeaders: IStompHeaders; procedure SetHeaders(const Value: IStompHeaders); function GetCommand: string; @@ -153,6 +155,7 @@ type // otherwise, return Value; function Output: string; function MessageID: string; + function ContentLength: Integer; property Headers: IStompHeaders read GetHeaders write SetHeaders; end; @@ -286,6 +289,7 @@ begin FHeaders := TStompHeaders.Create; self.FCommand := ''; self.FBody := ''; + self.FContentLength := 0; end; destructor TStompFrame.Destroy; @@ -319,9 +323,15 @@ begin COMMAND_END; end; +function TStompFrame.ContentLength: Integer; +begin + Result := FContentLength; +end; + procedure TStompFrame.SetBody(const Value: string); begin FBody := Value; + FContentLength := Length(TEncoding.UTF8.GetBytes(FBody)); end; procedure TStompFrame.SetCommand(const Value: string);