Recent

Author Topic: Improvement for TFPHTTPConnectionResponse  (Read 448 times)

domasz

  • Hero Member
  • *****
  • Posts: 553
Improvement for TFPHTTPConnectionResponse
« on: December 01, 2023, 12:34:11 pm »
In TFPHTTPConnectionResponse there is a property Content: RawByteString. We can set here what should be output by our web server. Works fine for text content but not so much for binary (even though RawByteString would suggest it's safe for binary data).
Alternatively we can use ContentStream and put our binary data here but I think it would be nice for Content to support binary data.

Why doesn't it? Because:
file HttpDefs.pas:
Code: Pascal  [Select][+][-]
  1. function TResponse.GetContent: RawByteString;
  2. begin
  3.   Result:=Contents.Text;
  4. end;  
  5.  
  6. procedure TResponse.SetContent(const AValue: RawByteString);
  7. ...
  8. FContents.Text:=AValue;
  9.  

Property .Text converts line breaks to #13#10 and corrupts binary data.
My suggestion:

Code: Pascal  [Select][+][-]
  1.   FContents.Delimiter := #13;
  2.   FContents.StrictDelimiter := True;
  3.   FContents.DelimitedText := AValue;  

But I don't know if it won't break something else somewhere.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5764
  • Compiler Developer
Re: Improvement for TFPHTTPConnectionResponse
« Reply #1 on: December 01, 2023, 09:47:43 pm »
In TFPHTTPConnectionResponse there is a property Content: RawByteString. We can set here what should be output by our web server. Works fine for text content but not so much for binary (even though RawByteString would suggest it's safe for binary data).

No, that is a wrong assumption. A RawByteString is a string which does not have a fixed static encoding, but instead relies on the dynamic encoding of whatever string data is assigned to it. If you want to retrieve binary data then use the properties intended for it like ContentStream that you already mentioned.

 

TinyPortal © 2005-2018