2 * Idea is to serve the files from the file system, so no need to setup apache etc...
3 * This should work for the static content like css / javascript etc.. but
4 * will cause issues with 'dynamic' xhr files (eg. the php stuff)
6 * the idea is nicked from geary.
10 public class FakeServer : Object
14 public FakeServer(WebKit.WebView wkview)
22 this.view.resource_load_started.connect(on_resource_request_starting);
23 //this.view.navigation_policy_decision_requested.connect(on_navigation_policy_decision_requested);
24 //this.view.new_window_policy_decision_requested.connect(on_navigation_policy_decision_requested);
27 this.view.get_context().register_uri_scheme("xhttp", serve);
31 private bool on_navigation_policy_decision_requested(
32 WebKit.WebFrame frame,
33 WebKit.NetworkRequest request,
34 WebKit.WebNavigationAction navigation_action,
35 WebKit.WebPolicyDecision policy_decision
37 policy_decision.ignore();
39 // not sure if we should allow navigations...
43 private void on_resource_request_starting(
44 WebKit.WebResource resource,
45 WebKit.URIRequest request) {
46 print("REQUEST-A : %s\n",uri);
47 if (resource == null) {
49 // A request that was previously approved resulted in a redirect.
53 string? uri = request.get_uri();
58 print("REQUEST : %s\n",uri);
59 if (Regex.match_simple ("\\.php", uri)) {
63 print("CHANGE TO : x%s\n",uri);
64 request.set_uri("x"+ uri);
67 public void serve(WebKit.URISchemeRequest request)
69 // request is URISchemeRequest
71 print(request.get_path());
73 var file = File.new_for_path ("/home/alan/gitlive/" + request.get_path());
74 var stream = file.read();
75 var info = file.query_info(
77 FileQueryInfoFlags.NONE
80 request.finish ( stream, info.get_size(), info.get_content_type());