Skip to content

Commit

Permalink
Updates for review.
Browse files Browse the repository at this point in the history
  • Loading branch information
jshier committed Nov 21, 2018
1 parent 8fab9b8 commit aaa3e6a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
25 changes: 21 additions & 4 deletions Source/HTTPHeaders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public struct HTTPHeaders {
update(HTTPHeader(name: name, value: value))
}

/// Case-insensitively updates or apprends the provided `HTTPHeader` into the instance.
/// Case-insensitively updates or appends the provided `HTTPHeader` into the instance.
///
/// - Parameter header: The `HTTPHeader` to update or append.
public mutating func update(_ header: HTTPHeader) {
Expand All @@ -80,7 +80,7 @@ public struct HTTPHeaders {

/// Sort the current instance by header name.
mutating public func sort() {
return headers.sort { $0.name < $1.name }
headers.sort { $0.name < $1.name }
}

/// Returns an instance sorted by header name.
Expand Down Expand Up @@ -198,6 +198,14 @@ extension HTTPHeader: CustomStringConvertible {
}

extension HTTPHeader {
/// Returns an `Accept-Charset` header.
///
/// - Parameter value: The `Accept-Charset` value.
/// - Returns: The header.
public static func acceptCharset(_ value: String) -> HTTPHeader {
return HTTPHeader(name: "Accept-Charset", value: value)
}

/// Returns an `Accept-Language` header.
///
/// Alamofire offers a default Accept-Language header that accumulates and encodes the system's preferred languages.
Expand Down Expand Up @@ -231,11 +239,20 @@ extension HTTPHeader {

return authorization("Basic \(credential)")
}

/// Returns a `Bearer` `Authorization` header using the `bearerToken` provided
///
/// - Parameter bearerToken: The bearer token.
/// - Returns: The header.
public static func authorization(bearerToken: String) -> HTTPHeader {
return authorization("Bearer \(bearerToken)")
}

/// Returns an `Authorization` header.
///
/// Alamofire provides a built-in method to produce Basic Authorization headers. Use
/// `HTTPHeader.authorization(username: password:)`.
/// Alamofire provides built-in methods to produce `Authorization` headers. For a Basic `Authorization` header use
/// `HTTPHeader.authorization(username: password:)`. For a Bearer `Authorization` header, use
/// `HTTPHeader.authorization(bearerToken:)`.
///
/// - Parameter value: The `Authorization` value.
/// - Returns: The header.
Expand Down
12 changes: 6 additions & 6 deletions Source/Response.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ extension DataResponse: CustomStringConvertible, CustomDebugStringConvertible {
let sortedHeaders = response.httpHeaders.sorted()

return """
Status Code: \(response.statusCode)
Headers:
[Status Code]: \(response.statusCode)
[Headers]:
\(sortedHeaders)
"""
} ?? "nil"
let metricsDescription = metrics.map { "\($0.taskInterval.duration)s" } ?? "None"

return """
[Request]: \(requestDescription)
[Response]: \(responseDescription)
[Response]: \n\(responseDescription)
[Data]: \(data?.description ?? "None")
[Network Duration]: \(metricsDescription)
[Serialization Duration]: \(serializationDuration)s
Expand Down Expand Up @@ -276,8 +276,8 @@ extension DownloadResponse: CustomStringConvertible, CustomDebugStringConvertibl
let sortedHeaders = response.httpHeaders.sorted()

return """
Status Code: \(response.statusCode)
Headers:
[Status Code]: \(response.statusCode)
[Headers]:
\(sortedHeaders)
"""
} ?? "nil"
Expand All @@ -286,7 +286,7 @@ extension DownloadResponse: CustomStringConvertible, CustomDebugStringConvertibl

return """
[Request]: \(requestDescription)
[Response]: \(responseDescription)
[Response]: \n\(responseDescription)
[File URL]: \(fileURL?.path ?? "nil")
[ResumeData]: \(resumeDataDescription)
[Network Duration]: \(metricsDescription)
Expand Down
3 changes: 1 addition & 2 deletions Tests/HTTPHeadersTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// HTTPHeaders.swift
// HTTPHeadersTests.swift
//
// Copyright (c) 2014-2018 Alamofire Software Foundation (http://alamofire.org/)
//
Expand Down Expand Up @@ -111,7 +111,6 @@ class HTTPHeadersTests: BaseTestCase {
// When
headers["C"] = "c"


// Then
XCTAssertEqual(headers.description, "C: c")
}
Expand Down

0 comments on commit aaa3e6a

Please sign in to comment.