apple / apple/swift-http-types
Feature: conversion of values for application/x-www-form-urlencoded
- Dominant language
- Swift
- Stars
- 1k
- Forks
- 80
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 12
Description
In many cases it's necessary to send data with `application/x-www-form-urlencoded` content type, and it turns out encoding to this content type is a bit of a mess. Firstly, when it was originally defined in [HTML 4.01 in 1999](https://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.13.4.1), it wasn't registered as an IANA media type. It has retroactively been added to the registry, but resulted in additional definitions [such as this one in OAuth 2.0](https://datatracker.ietf.org/doc/html/rfc6749#appendix-B) which is used for the token endpoint auth method known as ["client_secret_basic"](https://datatracker.ietf.org/doc/html/rfc6749#section-2.3.1). It was also redefined in the WHATWG specs: https://url.spec.whatwg.org/#concept-urlencoded-serializer
It's also maybe used for [`Authorization: Basic <...>`](https://www.rfc-editor.org/rfc/rfc7617#section-2) headers — though the OAuth 2.0 spec _may_ be deviating from RFC7617 here as RFC6749 (OAuth 2.0) is older.
I thought initially that it should be `String.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)`, however that didn't seem to be correct as it doesn't encode `+` to `%2B`. I think that may be for the entirety of a query string, not the individual parameter names and values.
In projects like AlamoFire, they have a thousand-ish line encoder for URLEncodedForm: https://github.com/Alamofire/Alamofire/blob/master/Source/Features/URLEncodedFormEncoder.swift
I'm not sure if it would make sense to go _that_ far, but maybe we just need a CharacterSet that is correct for this encoding?
This is also the default content type for POST request bodies.
Contributor guide
Research direction
Start by comparing the HTML 4.01, WHATWG URL, OAuth 2.0, and RFC 7617 definitions linked in the issue, using Alamofire's URLEncodedFormEncoder as a reference. Done should be a settled scope for the library's application/x-www-form-urlencoded conversion and agreed behavior for parameter names and values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100