Function

CFHTTPMessageAppendBytes(_:_:_:)

Appends data to a CFHTTPMessage object.

Declaration

func CFHTTPMessageAppendBytes(_ message: CFHTTPMessage, _ newBytes: UnsafePointer<UInt8>, _ numBytes: CFIndex) -> Bool

Parameters

message

The message to modify.

newBytes

A reference to the data to append.

numBytes

The length of the data pointed to by newBytes.

Return Value

TRUE if the data was successfully appended, otherwise FALSE.

Discussion

This function appends the data specified by newBytes to the specified message object which was created by calling CFHTTPMessageCreateEmpty(_:_:). The data is an incoming serialized HTTP request or response received from a client or a server. While appending the data, this function deserializes it, removes any HTTP-based formatting that the message may contain, and stores the message in the message object. You can then call CFHTTPMessageCopyVersion(_:), CFHTTPMessageCopyBody(_:), CFHTTPMessageCopyHeaderFieldValue(_:_:), and CFHTTPMessageCopyAllHeaderFields(_:) to get the message’s HTTP version, the message’s body, a specific header field, and all of the message’s headers, respectively.

If the message is a request, you can also call CFHTTPMessageCopyRequestURL(_:) and CFHTTPMessageCopyRequestMethod(_:) to get the message’s request URL and request method, respectively.

If the message is a response, you can also call CFHTTPMessageGetResponseStatusCode(_:) and CFHTTPMessageCopyResponseStatusLine(_:) to get the message’s status code and status line, respectively.

See Also

HTTP Messages

class CFHTTPMessage

An opaque reference representing an HTTP message.

func CFHTTPMessageApplyCredentialDictionary(CFHTTPMessage, CFHTTPAuthentication, CFDictionary, UnsafeMutablePointer<CFStreamError>?) -> Bool

Use a dictionary containing authentication credentials to perform the authentication method specified by a CFHTTPAuthentication object.

func CFHTTPMessageCopyBody(CFHTTPMessage) -> Unmanaged<CFData>?

Gets the body from a CFHTTPMessage object.

func CFHTTPMessageCopyHeaderFieldValue(CFHTTPMessage, CFString) -> Unmanaged<CFString>?

Gets the value of a header field from a CFHTTPMessage object.

func CFHTTPMessageCopyRequestMethod(CFHTTPMessage) -> Unmanaged<CFString>?

Gets the request method from a CFHTTPMessage object.

func CFHTTPMessageCopyVersion(CFHTTPMessage) -> Unmanaged<CFString>

Gets the HTTP version from a CFHTTPMessage object.

func CFHTTPMessageCreateEmpty(CFAllocator?, Bool) -> Unmanaged<CFHTTPMessage>

Creates and returns a new, empty CFHTTPMessage object.

func CFHTTPMessageGetResponseStatusCode(CFHTTPMessage) -> CFIndex

Gets the status code from a CFHTTPMessage object representing an HTTP response.

func CFHTTPMessageGetTypeID() -> CFTypeID

Returns the Core Foundation type identifier for the CFHTTPMessage opaque type.

func CFHTTPMessageIsHeaderComplete(CFHTTPMessage) -> Bool

Determines whether a message header is complete.

func CFHTTPMessageIsRequest(CFHTTPMessage) -> Bool

Returns a Boolean indicating whether the HTTP message is a request or a response.

func CFHTTPMessageSetBody(CFHTTPMessage, CFData)

Sets the body of a CFHTTPMessage object.

func CFHTTPMessageSetHeaderFieldValue(CFHTTPMessage, CFString, CFString?)

Sets the value of a header field in an HTTP message.

let kCFHTTPVersion1_0: CFString

Specifies HTTP version 1.0.

let kCFHTTPVersion1_1: CFString

Specifies HTTP version 1.1.