-
Notifications
You must be signed in to change notification settings - Fork 1
HTTPHeader
A representation of a single HTTP header's name / value pair.
public struct HTTPHeader: Hashable
Hashable
, CustomStringConvertible
Creates an instance from the given name
and value
.
public init(name: String, value: String)
- name: The name of the header.
- value: The value of the header.
Name of the header.
let name: String
Value of the header.
let value: String
var description: String
Returns Alamofire's default Accept-Encoding
header, appropriate for the encodings supported by particular OS
versions.
let defaultAcceptEncoding: HTTPHeader = {
let encodings: [String]
if #available(iOS 11.0, macOS 10.13, tvOS 11.0, watchOS 4.0, *) {
encodings = ["br", "gzip", "deflate"]
} else {
encodings = ["gzip", "deflate"]
}
return .acceptEncoding(encodings.qualityEncoded())
}()
See the Accept-Encoding HTTP header documentation .
Returns Alamofire's default Accept-Language
header, generated by querying Locale
for the user's
preferredLanguages
.
let defaultAcceptLanguage: HTTPHeader = {
.acceptLanguage(Locale.preferredLanguages.prefix(6).qualityEncoded())
}()
See the Accept-Language HTTP header documentation.
Returns Alamofire's default User-Agent
header.
let defaultUserAgent: HTTPHeader = {
let userAgent: String = {
if let info = Bundle.main.infoDictionary {
let executable = info[kCFBundleExecutableKey as String] as? String ?? "Unknown"
let bundle = info[kCFBundleIdentifierKey as String] as? String ?? "Unknown"
let appVersion = info["CFBundleShortVersionString"] as? String ?? "Unknown"
let appBuild = info[kCFBundleVersionKey as String] as? String ?? "Unknown"
let osNameVersion: String = {
let version = ProcessInfo.processInfo.operatingSystemVersion
let versionString = "\(version.majorVersion).\(version.minorVersion).\(version.patchVersion)"
// swiftformat:disable indent
let osName: String = {
#if os(iOS)
return "iOS"
#elseif os(watchOS)
return "watchOS"
#elseif os(tvOS)
return "tvOS"
#elseif os(macOS)
return "macOS"
#elseif os(Linux)
return "Linux"
#else
return "Unknown"
#endif
}()
// swiftformat:enable indent
return "\(osName) \(versionString)"
}()
let alamofireVersion = "Alamofire/\(AF.version)"
return "\(executable)/\(appVersion) (\(bundle); build:\(appBuild); \(osNameVersion)) \(alamofireVersion)"
}
return "Alamofire"
}()
return .userAgent(userAgent)
}()
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
Returns an Accept
header.
public static func accept(_ value: String) -> HTTPHeader
- Parameter value: The
Accept
value.
The header.
Returns an Accept-Charset
header.
public static func acceptCharset(_ value: String) -> HTTPHeader
- Parameter value: The
Accept-Charset
value.
The header.
Returns an Accept-Language
header.
public static func acceptLanguage(_ value: String) -> HTTPHeader
Alamofire offers a default Accept-Language header that accumulates and encodes the system's preferred languages.
Use HTTPHeader.defaultAcceptLanguage
.
- Parameter value: The
Accept-Language
value.
The header.
Returns an Accept-Encoding
header.
public static func acceptEncoding(_ value: String) -> HTTPHeader
Alamofire offers a default accept encoding value that provides the most common values. Use
HTTPHeader.defaultAcceptEncoding
.
- Parameter value: The
Accept-Encoding
value.
The header
Returns a Basic
Authorization
header using the username
and password
provided.
public static func authorization(username: String, password: String) -> HTTPHeader
- username: The username of the header.
- password: The password of the header.
The header.
Returns a Bearer
Authorization
header using the bearerToken
provided
public static func authorization(bearerToken: String) -> HTTPHeader
- Parameter bearerToken: The bearer token.
The header.
Returns an Authorization
header.
public static func authorization(_ value: String) -> HTTPHeader
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.
The header.
Returns a Content-Disposition
header.
public static func contentDisposition(_ value: String) -> HTTPHeader
- Parameter value: The
Content-Disposition
value.
The header.
Returns a Content-Type
header.
public static func contentType(_ value: String) -> HTTPHeader
All Alamofire ParameterEncoding
s and ParameterEncoder
s set the Content-Type
of the request, so it may not be necessary to manually
set this value.
- Parameter value: The
Content-Type
value.
The header.
Returns a User-Agent
header.
public static func userAgent(_ value: String) -> HTTPHeader
- Parameter value: The
User-Agent
value.
The header.
Generated at 2020-09-24T22:11:06+0000 using swift-doc 1.0.0-beta.4.
Types
- AF
- AFError
- AFError.MultipartEncodingFailureReason
- AFError.ParameterEncoderFailureReason
- AFError.ParameterEncoderFailureReason.RequiredComponent
- AFError.ParameterEncodingFailureReason
- AFError.ResponseSerializationFailureReason
- AFError.ResponseValidationFailureReason
- AFError.ServerTrustFailureReason
- AFError.ServerTrustFailureReason.Output
- AFError.URLRequestValidationFailureReason
- Adapter
- AlamofireExtension
- AlamofireNotifications
- ClosureEventMonitor
- CompositeEventMonitor
- CompositeTrustEvaluator
- ConnectionLostRetryPolicy
- DataRequest
- DataResponse
- DataResponseSerializer
- DecodableResponseSerializer
- DefaultTrustEvaluator
- DisabledEvaluator
- DownloadRequest
- DownloadRequest.Downloadable
- DownloadRequest.Options
- DownloadResponse
- Empty
- GoogleXSSIPreprocessor
- HTTPHeader
- HTTPHeaders
- HTTPMethod
- Interceptor
- JSONEncoding
- JSONParameterEncoder
- JSONResponseSerializer
- MultipartFormData
- NetworkReachabilityManager
- NetworkReachabilityManager.NetworkReachabilityStatus
- NetworkReachabilityManager.NetworkReachabilityStatus.ConnectionType
- PassthroughPreprocessor
- PinnedCertificatesTrustEvaluator
- PublicKeysTrustEvaluator
- Redirector
- Redirector.Behavior
- Request
- Request.State
- ResponseCacher
- ResponseCacher.Behavior
- Retrier
- RetryPolicy
- RetryResult
- RevocationTrustEvaluator
- RevocationTrustEvaluator.Options
- ServerTrustManager
- Session
- SessionDelegate
- StringResponseSerializer
- URLEncodedFormEncoder
- URLEncodedFormEncoder.ArrayEncoding
- URLEncodedFormEncoder.BoolEncoding
- URLEncodedFormEncoder.DataEncoding
- URLEncodedFormEncoder.DateEncoding
- URLEncodedFormEncoder.Error
- URLEncodedFormEncoder.KeyEncoding
- URLEncodedFormEncoder.SpaceEncoding
- URLEncodedFormParameterEncoder
- URLEncodedFormParameterEncoder.Destination
- URLEncoding
- URLEncoding.ArrayEncoding
- URLEncoding.BoolEncoding
- URLEncoding.Destination
- UploadRequest
- UploadRequest.Uploadable
Protocols
- AlamofireExtended
- CachedResponseHandler
- DataDecoder
- DataPreprocessor
- DataResponseSerializerProtocol
- DownloadResponseSerializerProtocol
- EmptyResponse
- EventMonitor
- ParameterEncoder
- ParameterEncoding
- RedirectHandler
- RequestAdapter
- RequestDelegate
- RequestInterceptor
- RequestRetrier
- ResponseSerializer
- ServerTrustEvaluating
- URLConvertible
- URLRequestConvertible
- UploadConvertible
- UploadableConvertible