views:

54

answers:

1

I am integrating WebKit (via Qt) into an application. Instead of having WebKit retrieve scripts, CSS files and images via URLs, I want my application to provide them (e.g. retrieved from a database).

For example, a "regular" web page may contain this tag:

<IMG src="photos/album1/123456.jpg">

Instead of WebKit fetching this image from a server or the file system, I would prefer some kind of callback that allows my application to provide this image.

How can I accomplish this?

+1  A: 

Maybe this is a bit overkill, but maybe it could work for you.

Simply have your application act as a HTTP server. Then you could have paths like this:

<IMG src="http://localhost:73617/photos/album1/123456.jpg"&gt;

Where 73617 is a random port, you can have your application listen on another port. Then, when your app retrieves the request for the image, it fetches it from wherever you want it to. It still involves a a server but at least you have complete control on where you get your resources from.

So, WebKit sees the url in the image, sends a request, your App gets the request, reads the resource, returns the resource. So basically you are still getting it from your App.

Hope this helps.

vanneto
Thanks. I thought about localhost, but was hoping there would be a simpler way. How do I implement my server? Is it simply a matter of creating a socket and serving requests?
Jen
Indeed it is just a matter of listening on a certain port by creating a socket. Also you would need to implement the HTTP protocol. Not everything of course. You would need to implement the GET command, maybe HEAD, and thats it. Shouldn't take long.You would simply need to parse HTTP commands and return the appropriate resource + headers. Luckily there is very much documentation on the HTTP protocol so you should have no problem.
vanneto