c++ - Reasoning behind CFReadStreamCreateForHTTPRequest in OSX/IOS -


i have written asynchronous http client in c++ ios/osx. confused why headers not arriving in cfhttpmessageref response object until realised there object lurking property of stream contains headers (after handling kcfstreameventbytesavailable event).

so copy headers property response object during notification of stream ending, before calling event handler.

(code available on request, there's quite lot of it)

the apple documentation characteristically silent on subject , wondering if out there knows reason design decision apple. keen know in case have fundamental misunderstanding somewhere?

edit: documentation says this:

after schedule request on run loop, header complete callback. @ point, can call cfreadstreamcopyproperty message response read stream

however there seems no indication name or value of event mask is.

edit: having done experimenting, see stream creates own response object time after sending kcfstreameventopencompleted notification , before first kcfstreameventhasbytesavailable notification.

in kcfstreameventhasbytesavailable event handler can this:

auto response = (cfhttpmessageref)cfreadstreamcopyproperty(readstream,                                           kcfstreampropertyhttpresponseheader); constexpr cfindex buffersize = 1024; uint8 buffer[buffersize]; auto bytesread = cfreadstreamread(readstream, buffer, buffersize); if (bytesread > 0) {     cfhttpmessageappendbytes(response, buffer, bytesread); } cfrelease(response); 

and stream's response message object indeed updated new body data. curious why not done automatically stream?


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -