PDA

View Full Version : How does IAStream knows where to start?


avslivker
08-29-2003, 01:36 PM
I am doing a simple task of downloading image of the http url.
I am using IWeb interface.

1. Once connected to my server with the specified url I get hit in my Web response callback with WebRespInfo*.
2. Using ISource member from WebRespInfo* I create IAStream from ISource
3. I call IIMAGE_Notify(pIImage,OnImageLoaded,pUser) to setup "image complete callback"
4. I call IIMAGE_SetStream(pIImage, ppIAStream) on created IAStream.

Surprisingly! - I am hit in my OnImageLoaded callback and if I display image - it shows OK.

Now closer to my actual question:

ISource that I get from the web response contains HTTP stream
that starts with HTTP text lines (HTTP headers) until it finally goes to the body of HTTP request where the binary of my image is.

IAStream created out of ISource is probably some sort of asyncronious version of a stream built on top of ISource. Obviously neither of them has knowledge where the data I am interested in strats from.

So finally my actual question:

How does IImage knows that it needs to load data of IAStream with some offset from original HTTP stream data?

The answer to this question would help a lot to understand the undelying concepts of Brew SDK and hence to program against it more effectively.


Thank you,
Andrew Slivker

tyndal
08-31-2003, 10:07 PM
Are you asking how does it know the offset of the http "body" from the http headers?

This is what I WebResponse handles, it parses the Http headers to get stuff like Content Length, Content Type, etc (the other fields of the WebRespInfo structure). The ISource you are getting starts at the "body" of the message -- your binary data.. (the "body" of a http response is separated from the headers by an empty line IIRC) So, the ISource (and IAStream) doesnt know anything .. it already starts at the position of the image data.

-Tyndal

avslivker
09-02-2003, 07:30 AM
That would have been fine if ISource really "points" to HTTP message body rather then the whole http message. When I look deep into it I see that:

1. IWebResponse helps me to get WebRespInfo structure.
2. WebRespInfo has a pisMessage member that is ISource interface (and that is the one I connect to IAStream by using
ISOURCEUTIL_AStreamFromSource).
3. But.. if you look in the debugger at the memory pointed by
pisMessage (same as ISource) you will see ALL the http headers after some offset which probably is taken by ISource object's other things. - this tells me that ISource has http headers "embedded" into data and the question how does the next set of SDK calls (that has no idea about http ptotocol) know how much to skip to reach for actual data still remains.

Thank you,
Andrew Slivker

paras
03-09-2004, 04:47 AM
Hi,
I want to get image file from the server through http request and from responce directly I want to show the immage.

can you please send me sample code how to do this feature in BREW ?

Thanks.