-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When MultipartBody is serialized the values are generated with CRLF #247
Comments
Thanks for raising this @MartinM85 Any chance you can confirm that the seriliazed payload is as expected when you run the following? var stringValue = KiotaSerializer.SerializeAsString("multipart/form-data", multipartBody); |
Hi @andrueastman, Text Visualizer in VS shows me this
string value: In |
It looks like since the value is a string value, the writer isn't using the serializer based on the content type the same way it would for a parsable but using the multipart writer instead hence the new line character. We would need to update the if clause to be similar to the parasable clause above it to pull the right |
Hi @andrueastman I will try to deliver a fix |
@andrueastman Fix delivered, but I'm worried about unit tests. Unit tests for MultipartBody are part of Abstraction library, but in this case, we need to set up concrete serialization writer. Not sure if mocking of json serializer is a good idea. It would be nice to have some integration tests to ensure that everything will work. |
What I'd suggest for now is adding a test and referencing the project in the multipart library. Similar to this. This should all get easier to do later on once we move the projects to one repo to make the end to end testing easier for such via #238 |
@andrueastman Seems like my change didn't work, but it's quite challenge to test it properly. I've tried to add unit test to https://github.com/microsoft/kiota-serialization-multipart-dotnet, but I need to reference local Microsoft.Kiota.Abstractions and Microsoft.Kiota.Serialization.Json. It's time consuming and what's important, I don't know what should be the expected result. Based on this: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition#examples the correct serialized content should be:
Maybe the fix should be removing AddNewLine: https://github.com/microsoft/kiota-abstractions-dotnet/blob/0787139294b160818a89b22d24eb079084fc7ffd/src/MultipartBody.cs#L179, but removing this line can break another funcionality. |
@MartinM85 FYI Andrew is out, we're not sure when he'll be back at this point. |
@baywet In the controller, the properties values are null |
let me be more specific with my question: when you send the payload from the client today, how it is formatted? and how does it differ from what would be required? |
Behavior for version 1.9.3:
Serialized payload when calling:
Server:
Behavior for version >=1.9.4:
StackTrace:
Server:
|
Re-opening this one for now.... The error occurs as the property It also looks like the writer for Using the code below will yield the expected result albeit with the wrong content type(i.e. "text/plain"). var multipartBody = new MultipartBody();
multipartBody.AddOrReplacePart("username", "text/plain", "test");
multipartBody.AddOrReplacePart("password", "text/plain", "abc");
multipartBody.RequestAdapter = graphClient.RequestAdapter;
var stringValue = await KiotaSerializer.SerializeAsStringAsync("multipart/form-data", multipartBody); Open question here is shouldn't the body for url-form-encoded be with key value pairs as below? --605a817187c144bbae08f23dda69523a
Content-Type: application/x-www-form-urlencoded
Content-Disposition: form-data; name="username"
username=test
--605a817187c144bbae08f23dda69523a
Content-Type: application/x-www-form-urlencoded
Content-Disposition: form-data; name="password"
password=abc
--605a817187c144bbae08f23dda69523a-- |
Trying the requests from Postman. API is running on ASPNET Core 8
|
looking at both RFC1867 and RFC7578 it is clear there shouldn't be a line return between the part and the next boundary (see different between previous message 2 and 3 examples). This is something we should fix. Then I think there's a misunderstanding there. I believe that since the multipart format is already handling the "segmentation of multiple properties" is doesn't need to be repeated in the different parts. I.E Does that make sense? |
Thanks @baywet, I believe this is already fixed in the latest abstractions with @MartinM85 PR. I was just highlighting that using the code below var multipartBody = new MultipartBody();
multipartBody.AddOrReplacePart("username", "text/plain", "test");
multipartBody.AddOrReplacePart("password", "text/plain", "abc");
multipartBody.RequestAdapter = graphClient.RequestAdapter;
var stringValue = await KiotaSerializer.SerializeAsStringAsync("multipart/form-data", multipartBody); will result in the correct and expected result as below (no spaces but content type as text plain)
However, changing the content type of the parts to
This is because the form writer does not accept writing values when the key is not passed/present/empty at https://github.com/microsoft/kiota-serialization-form-dotnet/blob/50d7a29ac768c2f3c0047d8909f12c2df623a30f/src/FormSerializationWriter.cs#L203. I believe the question really is that should we update the form writer to accept empty keys? Or does setting the content type as In my head, the only valid case for using So, a scenario like this should probably not have the part content type as |
Before we make that last change in the form serialization, we should double check in the specs (I believe that form encoded is a split between RFC and WHATWG) if this is valid. Would you look into that @andrueastman ? |
No worries. Will take a look into this to confirm. Way forward will either be
|
Sure, thanks for keeping the issues clean. Please go ahead. |
I've a controller
Login
class has propertiesUsername
andPassword
Part of swagger.json from which a client is generated
Calling the
login
method from the clientWhen debugging the
login
method, I see that the value inUsername
is"test\r\n"
and inPassword
is"abc\r\n"
. At the first sight it seems to me that CRLF are added during serialization.Same for content type
text/plain
The text was updated successfully, but these errors were encountered: