Skip to content

Commit

Permalink
Condensed 3 MultipartFormData data APIs into 1 (#2766)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnoon committed Mar 27, 2019
1 parent f4ced94 commit 0998c25
Showing 1 changed file with 1 addition and 39 deletions.
40 changes: 1 addition & 39 deletions Source/MultipartFormData.swift
Expand Up @@ -126,44 +126,6 @@ open class MultipartFormData {

// MARK: - Body Parts

/// Creates a body part from the data and appends it to the multipart form data object.
///
/// The body part data will be encoded using the following format:
///
/// - `Content-Disposition: form-data; name=#{name}` (HTTP Header)
/// - Encoded data
/// - Multipart form boundary
///
/// - parameter data: The data to encode into the multipart form data.
/// - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header.
public func append(_ data: Data, withName name: String) {
let headers = contentHeaders(withName: name)
let stream = InputStream(data: data)
let length = UInt64(data.count)

append(stream, withLength: length, headers: headers)
}

/// Creates a body part from the data and appends it to the multipart form data object.
///
/// The body part data will be encoded using the following format:
///
/// - `Content-Disposition: form-data; name=#{name}` (HTTP Header)
/// - `Content-Type: #{generated mimeType}` (HTTP Header)
/// - Encoded data
/// - Multipart form boundary
///
/// - parameter data: The data to encode into the multipart form data.
/// - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header.
/// - parameter mimeType: The MIME type to associate with the data content type in the `Content-Type` HTTP header.
public func append(_ data: Data, withName name: String, mimeType: String) {
let headers = contentHeaders(withName: name, mimeType: mimeType)
let stream = InputStream(data: data)
let length = UInt64(data.count)

append(stream, withLength: length, headers: headers)
}

/// Creates a body part from the data and appends it to the multipart form data object.
///
/// The body part data will be encoded using the following format:
Expand All @@ -177,7 +139,7 @@ open class MultipartFormData {
/// - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header.
/// - parameter fileName: The filename to associate with the data in the `Content-Disposition` HTTP header.
/// - parameter mimeType: The MIME type to associate with the data in the `Content-Type` HTTP header.
public func append(_ data: Data, withName name: String, fileName: String, mimeType: String) {
public func append(_ data: Data, withName name: String, fileName: String? = nil, mimeType: String? = nil) {
let headers = contentHeaders(withName: name, fileName: fileName, mimeType: mimeType)
let stream = InputStream(data: data)
let length = UInt64(data.count)
Expand Down

0 comments on commit 0998c25

Please sign in to comment.