Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ajax: Support binary data (including FormData)#5197

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

mgol
Copy link
Member

@mgolmgol commentedJan 16, 2023
edited
Loading

Summary

NOTE: Please don't review the first commit; that one is#5196, it was just easier for me to depend on it. (that PR landed)

Two changes have been applied:

  • prefilters are now applied before data is converted to a string;
    this allows prefilters to disable such a conversion
  • a prefilter for binary data is added; it disables data conversion
    for non-string non-plain-objectdata; forFormData bodies, it
    removes manually-setContent-Type header - this is required
    as browsers need to append their own boundary to the header

Refgh-4150

+39 bytes. We should discuss whether we want this fully in core or just the small change of running prefilters early enough for this to be possible. It is quite generic, though, with the small exception of specialFormData treatment - which, I think, is not necessarily desired in all cases? Unless it is - then the PR overhead would be+20 bytes instead of+39.

Checklist

@mgolmgol added Ajax Needs review Discuss in MeetingReserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labelsJan 16, 2023
@mgolmgol added this to the4.0.0 milestoneJan 16, 2023
@mgolmgol self-assigned thisJan 16, 2023
@mgolmgolforce-pushed theajax-prefilters-before-data-gh-4150 branch from3584c0b to909c466CompareJanuary 16, 2023 13:51
Comment on lines +565 to -571
// Apply prefilters
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );

// Convert data if not already a string
if ( s.data && s.processData && typeof s.data !== "string" ) {
s.data = jQuery.param( s.data, s.traditional );
}

// Apply prefilters
inspectPrefiltersOrTransports( prefilters, s, options, jqXHR );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think moving prefilters ahead of string coercion is a breaking change with respect to custom prefilters, cf.https://api.jquery.com/jQuery.ajaxPrefilter/ (emphasis mine):

originalOptions are the options as provided to the$.ajax() method,unmodified and, thus, without defaults fromajaxSettings

Is there a way to instead establish something like prefilter phases?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The line that now happens after the prefilters is only settingdata, not options. Is there any change that I'm missing?

BTW, I would also consider this a breaking change regardless of the above, that's why I'm targeting it at v4.

gibson042 reacted with thumbs up emoji
@timmywiltimmywil removed the Discuss in MeetingReserved for Issues and PRs that anyone would like to discuss in the weekly meeting. labelJan 23, 2023
Copy link
Member

@timmywiltimmywil left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good for 4.0. Might need a note in docs about the prefilter going before stringifyings.data, if that was ever documented.

// `Content-Type` for requests with `FormData` bodies needs to be set
// by the browser as it needs to append the `boundary` it generated.
if ( s.data instanceof window.FormData ) {
s.contentType = false;
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Note to self: check if this could be overridden in options if this is set tofalse for all binary data, not justFormData.

Copy link
MemberAuthor

@mgolmgolFeb 8, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

OK, this cannot be changed via settings as of now. 😕 I'll need another patch, I think.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Two changes have been applied:* prefilters are now applied before data is converted to a string;  this allows prefilters to disable such a conversion* a prefilter for binary data is added; it disables data conversion  for non-string non-plain-object `data`; for `FormData` bodies, it  removes manually-set `Content-Type` header - this is required  as browsers need to append their own boundary to the headerRefjquerygh-4150
@mgolmgolforce-pushed theajax-prefilters-before-data-gh-4150 branch from909c466 to5e8fc4dCompareJanuary 23, 2023 23:51
@mgolmgol merged commita7ed9a7 intojquery:mainFeb 1, 2023
@mgolmgol deleted the ajax-prefilters-before-data-gh-4150 branchFebruary 1, 2023 12:48
mgol added a commit to mgol/jquery that referenced this pull requestFeb 6, 2023
PRjquerygh-5197 started treating all non-string non-plain-object`data` values as binary. However, `jQuery.ajax` also supportsarrays as values of `data`. This change makes regular arraysno longer be considered binary data.Surprisingly, we had no tests for array `data` values; otherwise,we'd detect the issue earlier. This change also addsa few such missing tests.Refjquerygh-5197
@mgolmgol mentioned this pull requestFeb 6, 2023
2 tasks
@mgol
Copy link
MemberAuthor

mgol commentedFeb 6, 2023

I missed handling arraydata values; a fix at#5203.

mgol added a commit to mgol/jquery that referenced this pull requestFeb 8, 2023
The wayjquerygh-5197 implemented binary data handling, `processData`was being explicitly set to `false`. This is expected but it madeit impossible to override it to `true`. The new logic will onlyset `processData` to `false` if it wasn't explicitly passedin original options.Refjquerygh-5197
mgol added a commit that referenced this pull requestMar 20, 2023
The waygh-5197 implemented binary data handling, `processData`was being explicitly set to `false`. This is expected but it madeit impossible to override it to `true`. The new logic will onlyset `processData` to `false` if it wasn't explicitly passedin original options.Closesgh-5205Refgh-5197
mgol added a commit to mgol/jquery that referenced this pull requestMar 20, 2023
PRjquerygh-5197 started treating all non-string non-plain-object`data` values as binary. However, `jQuery.ajax` also supportsarrays as values of `data`. This change makes regular arraysno longer be considered binary data.Surprisingly, we had no tests for array `data` values; otherwise,we'd detect the issue earlier. This change also addsa few such missing tests.Refjquerygh-5197
mgol added a commit that referenced this pull requestMar 20, 2023
PRgh-5197 started treating all non-string non-plain-object`data` values as binary. However, `jQuery.ajax` also supportsarrays as values of `data`. This change makes regular arraysno longer be considered binary data.Surprisingly, we had no tests for array `data` values; otherwise,we'd detect the issue earlier. This change also addsa few such missing tests.Closesgh-5203Refgh-5197
mgol added a commit that referenced this pull requestMar 20, 2023
PRgh-5197 started treating all non-string non-plain-object`data` values as binary. However, `jQuery.ajax` also supportsarrays as values of `data`. This change didn't land on `3.x-stable`;however... Surprisingly, we had no tests for array `data` values.This change backports a few such missing tests added ingh-5203.Refgh-5197Refgh-5203
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@gibson042gibson042gibson042 left review comments

@timmywiltimmywiltimmywil approved these changes

Assignees

@mgolmgol

Milestone
4.0.0
Development

Successfully merging this pull request may close these issues.

3 participants
@mgol@timmywil@gibson042

[8]ページ先頭

©2009-2025 Movatter.jp