Contents

CFReadStreamCreateForStreamedHTTPRequest(_:_:_:)

Creates a read stream for a CFHTTP request message object whose body is too long to keep in memory.

Declaration

func CFReadStreamCreateForStreamedHTTPRequest(_ alloc: CFAllocator?, _ requestHeaders: CFHTTPMessage, _ requestBody: CFReadStream) -> Unmanaged<CFReadStream>

Parameters

  • alloc:

    The allocator to use to allocate memory for the new object. Pass NULL or kCFAllocatorDefault to use the current default allocator.

  • requestHeaders:

    A CFHTTP request header.

  • requestBody:

    Read stream reference for the request body.

Return Value

A new read stream, or NULL if there was a problem creating the object. Ownership follows the The Create Rule.

Discussion

This function creates a read stream for the response to the requestHeaders plus requestBody. Call this function instead of CFReadStreamCreateForHTTPRequest(_:_:) when the body of the request is so long that you do not want it to be resident in memory.

Because streams cannot be reset, read streams created this way cannot be enabled for autoredirection.

If the Content-Length header is set in requestHeaders, it is assumed that the length is correct and that requestBody will report end-of-stream after precisely Content-Length bytes have been read from it. If the Content-Length header is not set, the chunked transfer-encoding will be added to requestHeaders, and bytes read from requestBody will be transmitted chunked. The body of requestHeaders is ignored.

After creating the read stream, you can call CFReadStreamGetError(_:) at any time to check the status of the stream. You may want to call CFHTTPReadStreamSetProxy to set the name and port number for a proxy. To serialize the request and send it, call CFReadStreamOpen(_:).

See Also

Streams