Commit Graph

2 Commits

Author SHA1 Message Date
Fabian Fett ea5a64978d Initializing HTTPMethod with String picks explicit value over catch all RAW(value) (#1329)
Motivation:

When initializing an `HTTPMethod` with a `String` we currently switch over all expected values to pick an explicit value, only to overwrite our found explicit value with a catchall `RAW(value: String)`. This doesn’t make a ton of sense. This went unnoticed because we use the conditional conformance on `RawRepresentable` to be `Equatable`. But `switch`es  don’t use the `Equatable` protocol to match enums. The issue is visible there.

Modifications:

Added a testcase with a switch that fails, if the `.RAW(value: String)` value is used for `”GET”`. Removed the final overwrite in HTTPMethod(rawValue: String). Therefore the test passes.

Result:

We can initialize the HTTPMethod with a String and get an explicit value.
2020-01-02 11:39:54 -05:00
Romain Pouclet 4991d0930f Add a way to convert HTTP methods from/to String (#976)
Motivation:

https://github.com/apple/swift-nio/issues/701

Modifications:

* Add `init(rawValue:)`
* Add `rawValue`
* Add tests in HTTPTypesTest.swift

Result:

Users no longer have to write their own conversion methods.
2019-04-30 13:17:54 +01:00