At 10:26 -0700 9/9/08, Jack Brindle wrote:
For file transfers we do the same thing except create the dual
socket setup and call CFReadStreamCreateForStreamedHTTPRequest on
the read stream. However the read stream looks to be handled as a
raw stream of bits, without http-specific handling. It uses
CFWriteStreamWrite to send the data. No calls are made to anything
with the characters HTTP in the name for this stream. Am I right in
the feeling that this really isn't what I need to have?
It depends (-: When you create a streamed CFHTTP request (by calling
CFReadStreamCreateForStreamedHTTPRequest) CFHTTP will call the
supplied read stream to get the bytes for the body of the request.
This isn't HTTP at all, it's just a raw stream of bytes. A typical
usage is, if you want to upload a file, you create a file read stream
(CFReadStreamCreateWithFile) and pass that to
CFReadStreamCreateForStreamedHTTPRequest.
The only reason you need to do the whole socket pair thing is if the
data that you want to upload isn't present in one single file (or one
single block of memory). In that case, you have a number of options:
A. If the data is relatively small, you can flatten it to a temporary
file and then create a file read stream and use that. Similarly, you
can flatten it to a temporary block of memory.
OTOH, if the data is large, this approach is too inefficient.
B. If you're OK with using Objective-C and the data is all present
(that is, you don't need to be scheduled on a runloop in order to
produce the data), you can create the data from a custom subclass of
NSInputStream. Subclassing NSInputStream for asynchronous streams
isn't something we support, but it should be OK for synchronous
streams.
I haven't actually tried this though (-:
C. If all else fails, you can produce the data using the technique
that you're already using, that is, create a socket pair, create a
read stream for one member of the pair and a write stream for the
other, and feed the data to the CFHTTP request by writing it to the
write stream.
If you do this you won't need to mess with proxies on the streams you
create for the socket pair. Those streams are just used for internal
communication within your program. The only stream that needs to
deal with proxies is the main CFHTTP stream.
S+E