Skip to content

[foundation] Fix POST/PUT issues with NSUrlSessionHandler. Fixes #52682 (#1772) (#1778) - #1790

Merged
spouliot merged 1 commit into
dotnet:cycle9from
spouliot:bug52682-c9
Mar 7, 2017
Merged

[foundation] Fix POST/PUT issues with NSUrlSessionHandler. Fixes #52682 (#1772) (#1778)#1790
spouliot merged 1 commit into
dotnet:cycle9from
spouliot:bug52682-c9

Conversation

@spouliot

Copy link
Copy Markdown
Contributor

The latest NSUrlSessionHandler implementation switched from loading the
request into memory (NSData) to loading it from a stream (NSInputStream).
The later is more efficient, at least for large POST'ed requests which
could, in theory, not even fit in memory.

Now using a stream means a different API is used. NSMutableUrlRequest
Body and BodyStream properties are exclusive but also a bit different as
the later won't set Content-Length [1] and switch to chunked encoding [2]

Even if the current code is compliant with HTTP/1.1 this breaks some
common POST/PUT usage that worked "as expected" in the previous (C8)
release.

To fix this we ask for the stream's length. We assume that if the length
is known then it's (likely) already (or fitting) in memory and use the
(old, in memory) Body property, which will set Content-Length.

If the length is unknown then we use the BodyStream approach so large
POST will continue to work (well over past/C8 limits).

Finally there might be case where developers will prefer to avoid the
extra memory (of Body) so a new property MaxInputInMemory is added
to set a maximum. It defaults to Int64.MaxValue so Body will be
used whenever possible. It can be set to 0 to get back the original C9
(always use a stream) behavior.

references:
[1] https://bugzilla.xamarin.com/show_bug.cgi?id=52682
[2] https://bugzilla.xamarin.com/show_bug.cgi?id=52711
[3] https://devforums.apple.com/message/919330#919330

…82 (dotnet#1772) (dotnet#1778)

The latest NSUrlSessionHandler implementation switched from loading the
request into memory (NSData) to loading it from a stream (NSInputStream).
The later is more efficient, at least for large POST'ed requests which
could, in theory, not even fit in memory.

Now using a stream means a different API is used. NSMutableUrlRequest
Body and BodyStream properties are exclusive but also a bit different as
the later won't set Content-Length [1] and switch to chunked encoding [2]

Even if the current code is compliant with HTTP/1.1 this breaks some
common POST/PUT usage that worked "as expected" in the previous (C8)
release.

To fix this we ask for the stream's length. We assume that if the length
is known then it's (likely) already (or fitting) in memory and use the
(old, in memory) Body property, which will set Content-Length.

If the length is unknown then we use the BodyStream approach so large
POST will continue to work (well over past/C8 limits).

Finally there might be case where developers will prefer to avoid the
extra memory (of `Body`) so a new property `MaxInputInMemory` is added
to set a maximum. It defaults to `Int64.MaxValue` so `Body` will be
used whenever possible. It can be set to `0` to get back the original C9
(always use a stream) behavior.

references:
[1] https://bugzilla.xamarin.com/show_bug.cgi?id=52682
[2] https://bugzilla.xamarin.com/show_bug.cgi?id=52711
[3] https://devforums.apple.com/message/919330#919330
@spouliot spouliot added requires-approval-before-merge The pull request requires special approval before it can be merged requires-qa-before-merge The pull request requires QA to approve it before it can be merged labels Feb 28, 2017
@spouliot spouliot added this to the cycle9 milestone Feb 28, 2017
@monojenkins

Copy link
Copy Markdown
Contributor

Build failure

@spouliot

Copy link
Copy Markdown
Contributor Author

known random issue

@spouliot

spouliot commented Mar 7, 2017

Copy link
Copy Markdown
Contributor Author

@spouliot
spouliot merged commit f1d1e31 into dotnet:cycle9 Mar 7, 2017
@spouliot
spouliot deleted the bug52682-c9 branch March 7, 2017 15:18
spouliot added a commit to spouliot/xamarin-macios that referenced this pull request Mar 27, 2017
…82 (dotnet#1772) (dotnet#1778) (dotnet#1790)

The latest NSUrlSessionHandler implementation switched from loading the
request into memory (NSData) to loading it from a stream (NSInputStream).
The later is more efficient, at least for large POST'ed requests which
could, in theory, not even fit in memory.

Now using a stream means a different API is used. NSMutableUrlRequest
Body and BodyStream properties are exclusive but also a bit different as
the later won't set Content-Length [1] and switch to chunked encoding [2]

Even if the current code is compliant with HTTP/1.1 this breaks some
common POST/PUT usage that worked "as expected" in the previous (C8)
release.

To fix this we ask for the stream's length. We assume that if the length
is known then it's (likely) already (or fitting) in memory and use the
(old, in memory) Body property, which will set Content-Length.

If the length is unknown then we use the BodyStream approach so large
POST will continue to work (well over past/C8 limits).

Finally there might be case where developers will prefer to avoid the
extra memory (of `Body`) so a new property `MaxInputInMemory` is added
to set a maximum. It defaults to `Int64.MaxValue` so `Body` will be
used whenever possible. It can be set to `0` to get back the original C9
(always use a stream) behavior.

references:
[1] https://bugzilla.xamarin.com/show_bug.cgi?id=52682
[2] https://bugzilla.xamarin.com/show_bug.cgi?id=52711
[3] https://devforums.apple.com/message/919330#919330
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires-approval-before-merge The pull request requires special approval before it can be merged requires-qa-before-merge The pull request requires QA to approve it before it can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants