HTTPHeader
public struct HTTPHeader : Equatable, Hashable, Sendable
extension HTTPHeader: CustomStringConvertible
A representation of a single HTTP header’s name / value pair.
-
Name of the header.
Declaration
Swift
public let name: String
-
Value of the header.
Declaration
Swift
public let value: String
-
Declaration
Swift
public var description: String { get }
-
Returns an
Accept
header.Declaration
Swift
public static func accept(_ value: String) -> HTTPHeader
Parameters
value
The
Accept
value.Return Value
The header.
-
Returns an
Accept-Charset
header.Declaration
Swift
public static func acceptCharset(_ value: String) -> HTTPHeader
Parameters
value
The
Accept-Charset
value.Return Value
The header.
-
Returns an
Accept-Language
header.Alamofire offers a default Accept-Language header that accumulates and encodes the system’s preferred languages. Use
HTTPHeader.defaultAcceptLanguage
.Declaration
Swift
public static func acceptLanguage(_ value: String) -> HTTPHeader
Parameters
value
The
Accept-Language
value.Return Value
The header.
-
Returns an
Accept-Encoding
header.Alamofire offers a default accept encoding value that provides the most common values. Use
HTTPHeader.defaultAcceptEncoding
.Declaration
Swift
public static func acceptEncoding(_ value: String) -> HTTPHeader
Parameters
value
The
Accept-Encoding
value.Return Value
The header
-
Returns a
Basic
Authorization
header using theusername
andpassword
provided.Declaration
Swift
public static func authorization(username: String, password: String) -> HTTPHeader
Parameters
username
The username of the header.
password
The password of the header.
Return Value
The header.
-
Returns a
Bearer
Authorization
header using thebearerToken
provided.Declaration
Swift
public static func authorization(bearerToken: String) -> HTTPHeader
Parameters
bearerToken
The bearer token.
Return Value
The header.
-
Returns an
Authorization
header.Alamofire provides built-in methods to produce
Authorization
headers. For a BasicAuthorization
header useHTTPHeader.authorization(username:password:)
. For a BearerAuthorization
header, useHTTPHeader.authorization(bearerToken:)
.Declaration
Swift
public static func authorization(_ value: String) -> HTTPHeader
Parameters
value
The
Authorization
value.Return Value
The header.
-
Returns a
Content-Disposition
header.Declaration
Swift
public static func contentDisposition(_ value: String) -> HTTPHeader
Parameters
value
The
Content-Disposition
value.Return Value
The header.
-
Returns a
Content-Encoding
header.Declaration
Swift
public static func contentEncoding(_ value: String) -> HTTPHeader
Parameters
value
The
Content-Encoding
.Return Value
The header.
-
Returns a
Content-Type
header.All Alamofire
ParameterEncoding
s andParameterEncoder
s set theContent-Type
of the request, so it may not be necessary to manually set this value.Declaration
Swift
public static func contentType(_ value: String) -> HTTPHeader
Parameters
value
The
Content-Type
value.Return Value
The header.
-
Returns a
User-Agent
header.Declaration
Swift
public static func userAgent(_ value: String) -> HTTPHeader
Parameters
value
The
User-Agent
value.Return Value
The header.
-
Returns a
Sec-WebSocket-Protocol
header.Declaration
Swift
public static func websocketProtocol(_ value: String) -> HTTPHeader
Parameters
value
The
Sec-WebSocket-Protocol
value.Return Value
The header.
-
Returns Alamofire’s default
Accept-Encoding
header, appropriate for the encodings supported by particular OS versions.Declaration
Swift
public static let defaultAcceptEncoding: HTTPHeader
-
Returns Alamofire’s default
Accept-Language
header, generated by queryingLocale
for the user’spreferredLanguages
.Declaration
Swift
public static let defaultAcceptLanguage: HTTPHeader
-
Returns Alamofire’s default
User-Agent
header.See the User-Agent header documentation.
Example:
iOS Example/1.0 (org.alamofire.iOS-Example; build:1; iOS 13.0.0) Alamofire/5.0.0
Declaration
Swift
public static let defaultUserAgent: HTTPHeader