-
Notifications
You must be signed in to change notification settings - Fork 1.2k
KTOR-6711 Add configurable space encoding (spaceToPlus) to form parameters #5238
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
base: main
Are you sure you want to change the base?
Conversation
…kward compatibility.
WalkthroughA new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (3)
🧰 Additional context used🧠 Learnings (8)📚 Learning: 2025-05-14T18:05:02.321ZApplied to files:
📚 Learning: 2025-11-25T09:38:19.393ZApplied to files:
📚 Learning: 2025-06-09T07:08:35.085ZApplied to files:
📚 Learning: 2025-11-25T09:38:19.393ZApplied to files:
📚 Learning: 2025-11-25T09:38:19.393ZApplied to files:
📚 Learning: 2025-05-16T13:11:28.416ZApplied to files:
📚 Learning: 2025-09-30T07:52:14.769ZApplied to files:
📚 Learning: 2025-05-30T06:45:52.309ZApplied to files:
🔇 Additional comments (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt (1)
45-47: Optional: add@param outto KDocs for completenessSince you’re touching these KDocs, consider documenting the existing
outparameter alongsidespaceToPlusfor consistency with the “document all public APIs” guideline.Also applies to: 75-77
ktor-http/common/test/io/ktor/tests/http/CodecTest.kt (1)
156-185: Optional: consider aligning new test names with the project’s recommended patternThe new tests keep the existing
testXxxnaming style from this file. If/when you touch this test suite again, it might be worth aligning with theDescribeWhatIsBeingTestedpattern from the guidelines (e.g.,FormUrlEncode_respects_spaceToPlus_flag). Not urgent given the current file’s conventions.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
ktor-client/ktor-client-core/common/src/io/ktor/client/request/forms/FormDataContent.kt(1 hunks)ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt(2 hunks)ktor-http/common/test/io/ktor/tests/http/CodecTest.kt(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.kt
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.kt: Follow Kotlin official style guide (https://kotlinlang.org/docs/coding-conventions.html)
Use star imports forio.ktor.*packages
Document all public APIs including parameters, return types, and exceptions
Mark internal APIs with@InternalAPIannotation
Run./gradlew lintKotlinand fix all linting issues before giving control back to the user
Use./gradlew formatKotlinto automatically fix formatting issues
Run./gradlew updateLegacyAbiafter making ABI changes to update ABI signature files
Binary compatibility is enforced - all public API changes must be tracked in the/api/directories
Validate ABI with./gradlew checkLegacyAbiand update with./gradlew updateLegacyAbi
API changes must be intentional and well-documented
Error handling follows Kotlin conventions with specific Ktor exceptions
Files:
ktor-http/common/test/io/ktor/tests/http/CodecTest.ktktor-client/ktor-client-core/common/src/io/ktor/client/request/forms/FormDataContent.ktktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt
**/test/**/*.kt
📄 CodeRabbit inference engine (CLAUDE.md)
Follow test naming pattern:
DescribeWhatIsBeingTested
Files:
ktor-http/common/test/io/ktor/tests/http/CodecTest.kt
🧠 Learnings (2)
📓 Common learnings
Learnt from: bjhham
Repo: ktorio/ktor PR: 4855
File: ktor-server/ktor-server-plugins/ktor-server-di/api/ktor-server-di.klib.api:334-336
Timestamp: 2025-05-14T18:05:02.321Z
Learning: Breaking changes in constructor parameter order are acceptable for the ktor-server-di module when the code hasn't been released yet, as confirmed by the development team.
📚 Learning: 2025-05-30T06:45:52.309Z
Learnt from: rururux
Repo: ktorio/ktor PR: 4896
File: ktor-client/ktor-client-core/jvm/test/FileStorageTest.kt:1-12
Timestamp: 2025-05-30T06:45:52.309Z
Learning: In Ktor test files, particularly in the ktor-client/ktor-client-core/jvm/test/ directory, test files follow the convention of not including explicit package declarations. This is consistent across test files like CachingCacheStorageTest.kt and should be maintained for consistency.
Applied to files:
ktor-http/common/test/io/ktor/tests/http/CodecTest.kt
🔇 Additional comments (5)
ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt (2)
31-40: Space encoding flag is wired correctly through all form encodersThe new
spaceToPlusflag is consistently propagated through list- andParameters-basedformUrlEncode*functions and intoencodeURLParameter(spaceToPlus = spaceToPlus). Defaulting totruepreserves existing+behavior while allowing%20when needed. From a behavior perspective this looks solid and backwards-compatible for callers who recompile.Also applies to: 48-58, 67-70, 78-80, 82-84, 86-90
38-40: Ensure ABI changes are properly tracked via./gradlew updateLegacyAbiAll four
formUrlEncode/formUrlEncodeTosignatures now takespaceToPlus: Boolean = true. Run./gradlew updateLegacyAbito document this intentional API change in the API signature files. Note that breaking changes in unreleased code are acceptable per Ktor development practices—the key requirement is that API changes must be tracked in the/api/directories.ktor-client/ktor-client-core/common/src/io/ktor/client/request/forms/FormDataContent.kt (2)
25-33: FormDataContent wiring tospaceToPluslooks correctThe new
spaceToPlusparameter feeds directly intoformData.formUrlEncode(spaceToPlus)and the KDoc documents it clearly; the default preserves existing behavior while allowing%20when required.
28-33: Constructor change needs verification against ABI trackingVerify whether this constructor change has been tracked in the
/api/ktor-client-core.apidescriptor files. If the change is unreleased and properly documented in the API files, breaking changes may be acceptable per Ktor's development guidelines. If the change is not yet tracked in API descriptors, run./gradlew updateLegacyAbito update them. Only add a secondary constructor if empirical ABI checks via./gradlew checkLegacyAbifail.ktor-http/common/test/io/ktor/tests/http/CodecTest.kt (1)
156-185: Good coverage forspaceToPlusbehavior on both map and list encodersThe two new tests correctly exercise:
- Default plus behavior and explicit
spaceToPlus = true/falsefor map-basedentries.formUrlEncodeTo.- Default plus behavior and explicit
%20behavior for list-basedformUrlEncode.This should prevent regressions around the new flag.
|
@coderabbitai generate docstrings |
✅ Actions performedInitiated docstring generation; will generate only if new commits exist. |
|
Note Docstrings generation - SUCCESS |
Docstrings generation was requested by @mltheuser. * #5238 (comment) The following files were modified: * `ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt`
|
I am confused, I would have expected that the |
|
The failed tests might've been a temporary issue with the CI. Hopefully they'll pass this time. You'll need to run |
877dcb8 to
95d04c9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt (1)
70-80: Consider documentation consistency.This function retains the "Report a problem" link (line 73), while the other modified public functions in this file don't have it. For consistency, consider either adding the link to all public functions or removing it from this one.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.kt
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.kt: Follow Kotlin official style guide (https://kotlinlang.org/docs/coding-conventions.html)
Use star imports forio.ktor.*packages
Document all public APIs including parameters, return types, and exceptions
Mark internal APIs with@InternalAPIannotation
Run./gradlew lintKotlinand fix all linting issues before giving control back to the user
Use./gradlew formatKotlinto automatically fix formatting issues
Run./gradlew updateLegacyAbiafter making ABI changes to update ABI signature files
Binary compatibility is enforced - all public API changes must be tracked in the/api/directories
Validate ABI with./gradlew checkLegacyAbiand update with./gradlew updateLegacyAbi
API changes must be intentional and well-documented
Error handling follows Kotlin conventions with specific Ktor exceptions
Files:
ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt
🔇 Additional comments (4)
ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt (4)
40-58: Implementation looks solid.The
spaceToPlusparameter is correctly propagated to both key and value encoding using named parameter syntax, and null values are handled appropriately.
60-68: LGTM!The parameter chaining is correct, and the documentation clearly describes the behavior.
82-84: LGTM!The internal function correctly propagates the parameter through the call chain.
86-90: LGTM!The flattening logic correctly handles empty value lists and properly delegates with the
spaceToPlusparameter.
e8cdf2b to
a179fa8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
ktor-http/api/ktor-http.klib.api (1)
1738-1760: API changes correctly tracked with comprehensive documentation.The ABI dump properly reflects the addition of the
spaceToPlusBoolean parameter to all four form URL encoding functions. All corresponding source implementations inktor-http/common/src/io/ktor/http/HttpUrlEncoded.ktinclude KDoc documentation covering parameter purpose, default value, and encoding behavior.The documentation could be optionally enhanced by clarifying use cases for setting
spaceToPlus = false, such as RFC 3986 compliance or signature verification scenarios, to help developers choose the appropriate setting.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
ktor-http/api/ktor-http.api(1 hunks)ktor-http/api/ktor-http.klib.api(2 hunks)
🧰 Additional context used
🧠 Learnings (6)
📚 Learning: 2025-11-25T09:38:19.393Z
Learnt from: CR
Repo: ktorio/ktor PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:38:19.393Z
Learning: Applies to **/*.kt : API changes must be intentional and well-documented
Applied to files:
ktor-http/api/ktor-http.apiktor-http/api/ktor-http.klib.api
📚 Learning: 2025-11-25T09:38:19.393Z
Learnt from: CR
Repo: ktorio/ktor PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:38:19.393Z
Learning: Applies to **/*.kt : Document all public APIs including parameters, return types, and exceptions
Applied to files:
ktor-http/api/ktor-http.apiktor-http/api/ktor-http.klib.api
📚 Learning: 2025-09-30T07:52:14.769Z
Learnt from: yschimke
Repo: ktorio/ktor PR: 4013
File: ktor-client/ktor-client-android/jvm/src/io/ktor/client/engine/android/Android14URLConnectionFactory.kt:24-26
Timestamp: 2025-09-30T07:52:14.769Z
Learning: In the Ktor Android HTTP client engine (ktor-client-android), prefer using `URI.create(urlString).toURL()` over the `URL(urlString)` constructor when opening connections with Android's HttpEngine, as it avoids deprecated APIs and the different exception behavior (IllegalArgumentException vs MalformedURLException) is acceptable.
Applied to files:
ktor-http/api/ktor-http.apiktor-http/api/ktor-http.klib.api
📚 Learning: 2025-05-14T18:05:02.321Z
Learnt from: bjhham
Repo: ktorio/ktor PR: 4855
File: ktor-server/ktor-server-plugins/ktor-server-di/api/ktor-server-di.klib.api:334-336
Timestamp: 2025-05-14T18:05:02.321Z
Learning: Breaking changes in constructor parameter order are acceptable for the ktor-server-di module when the code hasn't been released yet, as confirmed by the development team.
Applied to files:
ktor-http/api/ktor-http.klib.api
📚 Learning: 2025-11-25T09:38:19.393Z
Learnt from: CR
Repo: ktorio/ktor PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:38:19.393Z
Learning: Applies to **/*.kt : Binary compatibility is enforced - all public API changes must be tracked in the `/api/` directories
Applied to files:
ktor-http/api/ktor-http.klib.api
📚 Learning: 2025-05-30T06:45:52.309Z
Learnt from: rururux
Repo: ktorio/ktor PR: 4896
File: ktor-client/ktor-client-core/jvm/test/FileStorageTest.kt:1-12
Timestamp: 2025-05-30T06:45:52.309Z
Learning: The headersOf() function from io.ktor.http package is available through wildcard imports like `import io.ktor.http.*`, so no explicit import statement is needed when using wildcard imports from that package.
Applied to files:
ktor-http/api/ktor-http.klib.api
🔇 Additional comments (1)
ktor-http/api/ktor-http.api (1)
771-778: API changes look correct and consistent.The addition of the Boolean parameter to form URL encoding methods is properly reflected in the API descriptor with:
- Both
formUrlEncodeandformUrlEncodeTomethod families updated- Both
ParametersandListoverloads covered- Synthetic
$defaultmethods correctly generated for JVM default parameter supportThis maintains binary compatibility through default parameters.
Please verify the following to ensure completeness:
#!/bin/bash # Verify that the default value is spaceToPlus = true for backward compatibility echo "=== Checking default parameter value in implementation ===" rg -n "fun formUrlEncode.*spaceToPlus.*=" --type=kt -A2 echo -e "\n=== Checking KDoc for the new parameter ===" rg -n "@param spaceToPlus" --type=kt -B2 -A2Based on learnings, API changes must be well-documented with parameter descriptions.
a179fa8 to
1b12f47
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
ktor-client/ktor-client-core/api/ktor-client-core.api(1 hunks)ktor-client/ktor-client-core/api/ktor-client-core.klib.api(1 hunks)ktor-http/api/ktor-http.api(1 hunks)ktor-http/api/ktor-http.klib.api(2 hunks)ktor-server/ktor-server-core/api/ktor-server-core.api(1 hunks)
🧰 Additional context used
🧠 Learnings (7)
📚 Learning: 2025-11-25T09:38:19.393Z
Learnt from: CR
Repo: ktorio/ktor PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:38:19.393Z
Learning: Applies to **/*.kt : API changes must be intentional and well-documented
Applied to files:
ktor-server/ktor-server-core/api/ktor-server-core.apiktor-http/api/ktor-http.apiktor-http/api/ktor-http.klib.api
📚 Learning: 2025-09-30T07:52:14.769Z
Learnt from: yschimke
Repo: ktorio/ktor PR: 4013
File: ktor-client/ktor-client-android/jvm/src/io/ktor/client/engine/android/Android14URLConnectionFactory.kt:24-26
Timestamp: 2025-09-30T07:52:14.769Z
Learning: In the Ktor Android HTTP client engine (ktor-client-android), prefer using `URI.create(urlString).toURL()` over the `URL(urlString)` constructor when opening connections with Android's HttpEngine, as it avoids deprecated APIs and the different exception behavior (IllegalArgumentException vs MalformedURLException) is acceptable.
Applied to files:
ktor-http/api/ktor-http.apiktor-http/api/ktor-http.klib.api
📚 Learning: 2025-05-14T18:05:02.321Z
Learnt from: bjhham
Repo: ktorio/ktor PR: 4855
File: ktor-server/ktor-server-plugins/ktor-server-di/api/ktor-server-di.klib.api:334-336
Timestamp: 2025-05-14T18:05:02.321Z
Learning: Breaking changes in constructor parameter order are acceptable for the ktor-server-di module when the code hasn't been released yet, as confirmed by the development team.
Applied to files:
ktor-client/ktor-client-core/api/ktor-client-core.apiktor-http/api/ktor-http.klib.api
📚 Learning: 2025-11-25T09:38:19.393Z
Learnt from: CR
Repo: ktorio/ktor PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:38:19.393Z
Learning: Applies to **/*.kt : Document all public APIs including parameters, return types, and exceptions
Applied to files:
ktor-http/api/ktor-http.klib.api
📚 Learning: 2025-11-25T09:38:19.393Z
Learnt from: CR
Repo: ktorio/ktor PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:38:19.393Z
Learning: Applies to **/*.kt : Binary compatibility is enforced - all public API changes must be tracked in the `/api/` directories
Applied to files:
ktor-http/api/ktor-http.klib.api
📚 Learning: 2025-06-09T07:08:35.085Z
Learnt from: bjhham
Repo: ktorio/ktor PR: 4916
File: ktor-server/ktor-server-core/api/ktor-server-core.api:151-151
Timestamp: 2025-06-09T07:08:35.085Z
Learning: Breaking changes are acceptable in Ktor codebase when the code hasn't been released yet, as confirmed by bjhham from the development team.
Applied to files:
ktor-http/api/ktor-http.klib.api
📚 Learning: 2025-05-30T06:45:52.309Z
Learnt from: rururux
Repo: ktorio/ktor PR: 4896
File: ktor-client/ktor-client-core/jvm/test/FileStorageTest.kt:1-12
Timestamp: 2025-05-30T06:45:52.309Z
Learning: The headersOf() function from io.ktor.http package is available through wildcard imports like `import io.ktor.http.*`, so no explicit import statement is needed when using wildcard imports from that package.
Applied to files:
ktor-http/api/ktor-http.klib.api
🔇 Additional comments (4)
ktor-http/api/ktor-http.klib.api (2)
1738-1739: spaceToPlus flag on Parameters-based formUrlEncode looks consistent; just confirm ABI expectationsThe added Boolean parameter (with a default) on the
Parameters.formUrlEncode/formUrlEncodeToextensions matches the PR intent and preserves previous behavior when omitted. It does, however, change the function descriptors compared to the earlier single-parameter versions, which is an ABI-breaking change for callers compiled against the old signatures (especially in native/JS targets). Please confirm this break is acceptable for the branch you’re targeting, or consider adding overloads that keep the old signatures delegating to the new ones.
1759-1760: List<Pair<...>> overloads mirror Parameters APIs; same ABI caveat appliesThe list-based
formUrlEncode/formUrlEncodeToextensions are updated symmetrically with the same Boolean default parameter, which is good for API consistency and behavior. As with theParametersoverloads, this changes the exported signatures; please double-check that this intended ABI break is acceptable, or add delegating overloads that retain the legacy one-parameter forms if you need binary compatibility.ktor-client/ktor-client-core/api/ktor-client-core.klib.api (1)
909-920: Binary incompatibility introduced; clarify if acceptable for this development cycleThe constructor signature change from
(Parameters)to(Parameters, Boolean = true)breaks binary compatibility. Even though the Boolean parameter has a default value, the old single-argument constructor is no longer available at the ABI level—existing binaries compiled against previous versions will fail to link.Per the learnings from this project, breaking changes are acceptable for unreleased versions (similar to prior decisions on ktor-server-di). If this version is still in development, this change may be intentional and acceptable. However, verify this with the team or use the dual-constructor pattern suggested in the original review if binary compatibility with prior releases must be maintained:
public class FormDataContent( public val formData: Parameters, spaceToPlus: Boolean, ) : OutgoingContent.ByteArrayContent() { // ... constructor(formData: Parameters) : this(formData, spaceToPlus = true) }Note: The default parameter on the primary constructor maintains source-level compatibility for new code, which is good practice regardless.
ktor-http/api/ktor-http.api (1)
771-781: API surface changes are consistent and preserve backward compatibility.The addition of the boolean
spaceToPlusparameter toformUrlEncodeandformUrlEncodeTo(for bothParametersandList<Pair>overloads) is handled correctly:
- Synthetic default methods (
formUrlEncode$default,formUrlEncodeTo$default) enable Kotlin's default parameter semantics at the JVM boundary, ensuring existing callers continue to work without modification.- All four encoding function variants are updated consistently.
Based on learnings, API changes must be intentional and well-documented. Please ensure:
- The implementation correctly defaults
spaceToPlus = true(as stated in PR objectives).- Public documentation (KDoc) clearly explains the behavior difference between
spaceToPlus = true(spaces encoded as+) andspaceToPlus = false(spaces encoded as%20).- Migration guidance is provided if the default may change in future versions.
Run the following script to verify the implementation includes proper documentation and default values:
#!/bin/bash # Verify implementation of formUrlEncode functions includes proper defaults and documentation # Check for the spaceToPlus parameter with default value in implementation rg -A5 -B2 'fun formUrlEncode.*spaceToPlus.*=.*true' ktor-http/common/src/io/ktor/http/ # Check for KDoc documentation on spaceToPlus parameter rg -B10 'fun formUrlEncode' ktor-http/common/src/io/ktor/http/HttpUrlEncoded.kt | grep -E '(@param|spaceToPlus|%20|\+)'
| public fun <init> (Lio/ktor/http/Parameters;Z)V | ||
| public synthetic fun <init> (Lio/ktor/http/Parameters;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FormDataContent constructor signature is binary-incompatible; document as major version breaking change
Changing the primary constructor to (Parameters, Boolean) removes the previous (Parameters) entry point from the ABI. Existing binaries compiled against the old signature will fail to link. If preserving binary compatibility within the current major version is desired, add a secondary constructor delegating to the new one. However, if this change targets the next major version (4.0), the breaking change is acceptable per semantic versioning—but should be clearly documented in release notes as ABI-incompatible.
🤖 Prompt for AI Agents
In ktor-client/ktor-client-core/api/ktor-client-core.api around lines 1467-1468,
the FormDataContent primary constructor was changed to (Parameters, Boolean)
which removes the previous (Parameters) ABI entry and breaks binary
compatibility; to fix, restore ABI compatibility by adding a secondary
constructor with the original single-Parameters signature that delegates to the
new two-argument constructor (providing the appropriate default Boolean value to
preserve prior behavior) and update the API surface accordingly, or if this is
an intended major-version break, document the ABI-incompatible constructor
change clearly in the 4.0 release notes instead of adding the compatibility
constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I add back a version with one argument for binary compatibility or is breaking it acceptable? Let's leave that up to the reviewers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mltheuser, that's a sensible approach! Based on the project's history, breaking changes in Ktor are generally acceptable in these scenarios:
- When the code hasn't been released yet – if this feature is part of an unreleased version, binary incompatibility is typically fine
- In major version releases – if this is targeting a major version bump (e.g., 4.0), breaking the ABI is acceptable per semantic versioning
Since the decision depends on the release timeline and versioning strategy, letting the reviewers make the call is the right move. They'll know whether this change:
- Is still unreleased (in which case the break is fine)
- Should preserve binary compatibility by adding a secondary constructor with the old signature
- Is acceptable as a documented breaking change for the next major version
The synthetic default constructor that's already generated (<init>(Lio/ktor/http/Parameters;ZILkotlin/jvm/internal/DefaultConstructorMarker;)) helps with source compatibility, but doesn't restore binary compatibility for the original single-parameter constructor.
🧠 Learnings used
Learnt from: bjhham
Repo: ktorio/ktor PR: 4855
File: ktor-server/ktor-server-plugins/ktor-server-di/api/ktor-server-di.klib.api:334-336
Timestamp: 2025-05-14T18:05:02.321Z
Learning: Breaking changes in constructor parameter order are acceptable for the ktor-server-di module when the code hasn't been released yet, as confirmed by the development team.
Learnt from: osipxd
Repo: ktorio/ktor PR: 4860
File: ktor-server/ktor-server-plugins/ktor-server-di/api/ktor-server-di.api:24-26
Timestamp: 2025-05-16T13:11:28.416Z
Learning: Binary incompatible changes (such as constructor signature changes) are acceptable in the ktor-server-di module when the version is not yet released, as confirmed by the development team.
Learnt from: bjhham
Repo: ktorio/ktor PR: 4916
File: ktor-server/ktor-server-core/api/ktor-server-core.api:151-151
Timestamp: 2025-06-09T07:08:35.085Z
Learning: Breaking changes are acceptable in Ktor codebase when the code hasn't been released yet, as confirmed by bjhham from the development team.
Learnt from: CR
Repo: ktorio/ktor PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T09:38:19.393Z
Learning: Applies to **/*.kt : API changes must be intentional and well-documented
Learnt from: CR
Repo: ktorio/ktor PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-06-23T12:49:56.883Z
Learning: Breaking changes to public APIs are only allowed in major version releases.
1b12f47 to
88c0d56
Compare
|
Thanks @bjhham for bringing this back to my attention and guiding me in the right direction! I suspect this is ready for review now. There are 2 remaining test failures, but TeamCity marks them as flaky, so they seem unrelated to these changes. Regarding binary compatibility, I will leave the final call to the reviewers. If you prefer strict compatibility, I am happy to add back single argument versions to support it. |
|
Oh and could someone close the PR by coderabbit: #5239 (I can't do it since it is not in my name) |
Subsystem
ktor-http,ktor-clientMotivation
Currently,
FormDataContentandformUrlEncodeforcibly encode spaces as+. This prevents integration with external APIs that strictly follow RFC 3986 (expecting%20) or use exact string matching for signature verification. We need a way to configure this behavior without forcing users to rewrite the encoding logic from scratch.Solution
I introduced a
spaceToPlusboolean parameter toFormDataContentand the variousformUrlEncodeextension functions.spaceToPlus = true. I chose to keep the current behavior as the default to ensure full backward compatibility for existing applications.spaceToPlus = falseto generate%20instead of+, matching the WHATWG spec recommendation.Note to reviewers: I stuck with
truefor safety, but I am open to changing the default tofalseif you prefer stricter adherence to the spec over backward compatibility.