HttpResponse

public protocol HttpResponse : Sendable

Protocol defining the contract for HTTP responses.

HttpResponse provides access to the response status, headers, body, and cookies from an HTTP request.

  • The original request that generated this response.

    Declaration

    Swift

    var request: HttpRequest { get }
  • The HTTP status code (e.g., 200, 404, 500).

    Declaration

    Swift

    var status: Int { get }
  • The response body as raw data.

    Declaration

    Swift

    var body: Data? { get }
  • Gets a specific header value by name.

    Declaration

    Swift

    func getHeader(name: String) -> String?

    Parameters

    name

    The header name (case-insensitive).

    Return Value

    The header value, or nil if not present.

  • Gets all header values by name.

    Declaration

    Swift

    func getHeaders(name: String) -> [String]?

    Parameters

    name

    The header name (case-insensitive).

    Return Value

    Array of header values or nil if not present.

  • Gets all cookies from the response.

    Declaration

    Swift

    func getCookies() -> [HTTPCookie]

    Return Value

    Array of cookies from Set-Cookie headers.

  • Gets raw Set-Cookie header strings.

    Declaration

    Swift

    func getCookieStrings() -> [String]

    Return Value

    Array of raw Set-Cookie header values.

  • Gets the response body as a UTF-8 string.

    Declaration

    Swift

    func bodyAsString() -> String

    Return Value

    The body as a string, or empty string if body is nil or invalid UTF-8.