#1 2024-08-27 18:19:19

igors233
Member
Registered: 2012-09-10
Posts: 241

MultiPartFormDataEncode with THttpRequest.Request

MultiPartFormDataEncode in mormot1 and mormot2 adds "Content-Type: " prefix to ContentType.
If encoded data and ContentType is sent using THttpRequest.Request descendant, prefix is doubled with:
  if InDataType<>'' then
    InternalAddHeader(SockString('Content-Type: ')+InDataType);

So when sent to recipient ContentType will look like:
Content-Type: Content-Type: multipart/form-data; boundary=

Perhaps THttpRequest.Request should be updated to include "Content-Type:" only if InDataType doesn't have it.

Offline

#2 2024-08-28 12:04:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,506
Website

Re: MultiPartFormDataEncode with THttpRequest.Request

This is documented as such:

// - MultiPartContentType: variable returning
// $ Content-Type: multipart/form-data; boundary=xxx
// where xxx is the first generated boundary

So it returns an header.
Just delete the first chars if you want to use it not as header but as content-type.

Offline

#3 2024-08-29 06:32:18

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: MultiPartFormDataEncode with THttpRequest.Request

mORMot2 cannot decode content encoded in mORMot1 with MultiPartFormDataAddField/MultiPartFormDataAddFile, it works other way around.

Here is code to reproduce it.

https://paste.ee/p/t3pBv

Last edited by igors233 (2024-08-29 06:37:01)

Offline

#4 2024-08-29 07:06:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,506
Website

Re: MultiPartFormDataEncode with THttpRequest.Request

Please define "cannot decode".
And make some minimal debugging.

Offline

#5 2024-08-31 11:07:22

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: MultiPartFormDataEncode with THttpRequest.Request

MultiPartFormDataDecode returns false.

mORMot1 encoded multipart content has boundary twice, at the begining of section, at the and, and there's also end boundary.
So mORMot2 fails to set Result
due to this part because j is not 0:
j := PosEx(boundary, Body, i);
if j = 0 then
begin
   ...
   result := true;
end

while mORMot1 has same check but doesn't set Result at that place.

I'm not sure if mORMot1 including boundary twice is per standard, couldn't find anything saying it cannot be written twice so likely best thing is to change MultiPartFormDataDecode in mORMot2.

Offline

Board footer

Powered by FluxBB