URLSessionHttpResponse
public final class URLSessionHttpResponse : HttpResponse, @unchecked Sendable
URLSession-based implementation of HttpResponse.
This class is thread-safe and can be safely shared across threads.
-
The original HTTP request that generated this response.
Declaration
Swift
public let request: HttpRequest -
The HTTP status code (e.g., 200, 404, 500).
Declaration
Swift
public var status: Int { get } -
The response body as raw data.
Declaration
Swift
public let body: Data? -
Creates a new HTTP response from URLSession data.
Declaration
Swift
public init( request: HttpRequest, body: Data?, httpURLResponse: HTTPURLResponse? )Parameters
requestThe original HTTP request.
bodyThe response body data.
httpURLResponseThe underlying HTTPURLResponse object.
-
Gets the first value for a header by name.
Performs case-insensitive header name lookup.
Declaration
Swift
public func getHeader(name: String) -> String?Parameters
nameThe header name to look up.
Return Value
The first header value, or nil if not present.
-
Gets all values for a header by name.
HTTP headers can have multiple values. Performs case-insensitive lookup.
Declaration
Swift
public func getHeaders(name: String) -> [String]?Parameters
nameThe header name to look up.
Return Value
Array of header values, or nil if not present.
-
Parses Set-Cookie headers and returns HTTPCookie objects.
Handles multiple Set-Cookie headers and comma-separated values, matching Android SDK behavior.
Declaration
Swift
public func getCookies() -> [HTTPCookie]Return Value
Array of parsed HTTP cookies.
-
Converts the response body to a UTF-8 string.
Declaration
Swift
public func bodyAsString() -> StringReturn Value
The decoded body string, or an empty string if body is nil or not valid UTF-8.
-
Gets raw Set-Cookie header values before parsing.
This method extracts Set-Cookie headers from both the normalized headers dictionary and the raw HTTPURLResponse, handling line breaks and comma separation.
Declaration
Swift
public func getCookieStrings() -> [String]Return Value
Array of raw Set-Cookie header strings.
View on GitHub