Skip to content

Commit ed7100a

Browse files
committed
Add MediaType.rawValue
1 parent 19c883d commit ed7100a

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

Sources/MultipartFormData/ContentType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public struct ContentType: HTTPHeaderField {
1111
public static let name: String = "Content-Type"
1212

1313
public var value: String {
14-
return mediaType._text
14+
return mediaType.rawValue
1515
}
1616

1717
/// The media type (MIME type) of the content type.

Sources/MultipartFormData/MediaType.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extension UTType {
8787
/// - Parameter mediaType: The media type.
8888
/// - Parameter supertype: Another UTType instance that the resulting type must conform to; for example, UTTypeData.
8989
public init?(mediaType: MediaType, conformingTo supertype: UTType = .data) {
90-
self.init(mimeType: mediaType._text, conformingTo: supertype)
90+
self.init(mimeType: mediaType.rawValue, conformingTo: supertype)
9191
}
9292
}
9393
#endif
@@ -96,14 +96,15 @@ extension UTType {
9696

9797
extension MediaType: CustomDebugStringConvertible {
9898
public var debugDescription: String {
99-
return _text
99+
return rawValue
100100
}
101101
}
102102

103103
// MARK: - Helpers
104104

105105
extension MediaType {
106-
internal var _text: String {
106+
/// The raw string representation of a media type.
107+
public var rawValue: String {
107108
return "\(type)/\(subtype)"
108109
}
109110
}

Tests/MultipartFormDataTests/MediaTypeTests.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import UniformTypeIdentifiers
1212
@testable import MultipartFormData
1313

1414
final class MediaTypeTests: XCTestCase {
15-
func testText() {
15+
func testRawValue() {
1616
let mediaType = MediaType(type: "type", subtype: "subtype")
17-
XCTAssertEqual(mediaType._text, "type/subtype")
17+
XCTAssertEqual(mediaType.rawValue, "type/subtype")
1818
}
1919

2020
func testDebugDescription() {
2121
let mediaType = MediaType(type: "type", subtype: "subtype")
22-
2322
let expectedDescription = "type/subtype"
2423
XCTAssertEqual(mediaType.debugDescription, expectedDescription)
2524
}
@@ -29,14 +28,12 @@ final class MediaTypeTests: XCTestCase {
2928
func testFromUTTypeConversion() throws {
3029
let uniformType = try XCTUnwrap(UTType("public.comma-separated-values-text"))
3130
let mediaType = try XCTUnwrap(MediaType(uniformType: uniformType))
32-
3331
XCTAssertEqual(mediaType, .textCsv)
3432
}
3533

3634
@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *)
3735
func testToUTTypeConversion() throws {
3836
let uniformType = try XCTUnwrap(UTType(mediaType: .applicationJson))
39-
4037
XCTAssertEqual(uniformType.identifier, "public.json")
4138
}
4239
#endif

0 commit comments

Comments
 (0)