WebURL 0.2.0 released!

I'm happy to announce that WebURL 0.2.0 is out now!

Check it out: [Repository]

What's Changed

In addition to the changes listed below, the guide has been entirely rewritten, and now does a better job of explaining the WebURL API and object model, and the benefits it can bring to your application/library. The goal is to help you become as comfortable using WebURL as you are using Foundation's URL. It took a lot of work, and I'd really recommend giving it a read. Even if you're not using WebURL yet, the chances are that you'll learn a thing or two about how Foundation's URL actually works.

URL standard

API

  • Support for creating file URLs from file paths, and file paths from file URLs.
  • Added WebURLSystemExtras module which integrates with both swift-system and Apple's System.framework.
  • LazilyPercentDecoded<Collection> is now bidirectional when its source collection is.
  • WebURL.cannotBeABase has been renamed to WebURL.hasOpaquePath, following an update in the standard. (Editorial: fold cannot-be-base-URL into path by annevk · Pull Request #655 · whatwg/url · GitHub) (reported by us)
  • Percent-encoding and -decoding APIs have been reworked to take advantage of static member syntax (SE-0299). A source-compatible fallback is in place for pre-5.5 compilers. This is the reason for duplicate functions appearing in the docs, one with a EncodeSet._Member argument. We're looking at moving to Swift-DocC which will hopefully fix this. The previous API has been back-ported with deprecation notices wherever possible, so the compiler should guide when it comes to updating your applications.
  • It is now possible to percent-decode a string as an array of bytes using the .percentDecodedBytesArray() function. This is useful for dealing with binary data and non-UTF8 strings.
  • The .pathComponents view now assumes inserted data is not percent-encoded, which preserves values exactly if they happen to contain strings which coincidentally look like percent-encoding.
  • A .pathComponents[raw: Index] subscript has been added, which returns a path component exactly as it appears in the URL string, including its percent-encoding.
  • A .pathComponent.replaceSubrange(_:withPercentEncodedComponents:) function has been added for inserting pre-encoded path components.
  • Added Sendable conformance to WebURL, WebURL.Host, IP addresses, origins, and the various wrapper views.
  • The .serialized property has been combined with .serializedExcludingFragment in to a single function: .serialized(excludingFragment: Bool = false).

Implementation

  • Better performance, especially for component setters
  • Component setters are now benchmarked
  • Support for fuzzing the parser
  • Added UnsafeBoundsCheckedBufferPointer which allows us to keep bounds-checking without sacrificing performance
  • Simplified internal storage types, reducing code size
  • Better percent-encoding performance

Full Changelog: Comparing 0.1.0...0.2.0 · karwa/swift-url · GitHub

What's coming next

The major goal for 0.3.0 is compatibility with Foundation's URL. At the very least, that is going to include support for creating a URL from a WebURL and vice versa, but we may need additional APIs for a truly great developer experience.

11 Likes

Additionally, I've updated the port of async-http-client to 1.7.0, which was released just a few days ago. It uses WebURL for all of its internal URL processing, and allows you to make http(s) requests, including support for HTTP/2, and all of the other things you'd expect from async-http-client.

3 Likes