Re: Catching 404

Gerd Stolpmann <[email protected]> Wed, 19 Sep 2012 18:29:26 +0200
Newsgroups gmane.comp.lang.ocaml.lib.net.devel
Message-ID <1348072166.22268.1@samsung>
Am 18.09.2012 17:31:17 schrieb(en) Pierre-Alexandre Voye:
> Hello,
>  is it possible to catch a 404 with ocamlnet ?
> Use case example : if the page doesn't exists then, it give a way to
> create/edit the unknown page.
> It seems, I would have to rewrite is_error_response according to
> http://projects.camlcity.org/projects/dl/ocamlnet-3.2.1/doc/html-main/Http_fs.html#VALis_error_response
> Is it the case ?

Hmm, Http_fs is a very thin layer on top of Http_client. HTTP codes are  
translated to Unix codes where it makes sense, so a 404 error will  
appear as Unix_error(ENOENT,_,_).

If you need more control, you should use Http_client directly (the  
pipeline is accessible, so you can do things like

let url = http_fs # translate "/the/path/to/the/file" in
let call_obj = new Http_client.get url in
http_fs # pipeline # add call_obj;
http_fs # pipeline # run();
let code = call_obj # response_status_code in
...

).

So far, there is no way to override is_error_code, so you would have to  
copy http_fs.ml to your own code tree.

> In the same way, is it possible to configure url rewriting with  
> ocamlnet ?

I am not exactly sure what you mean. So far I see this is mostly a  
question when redirects are followed. Http_client is able to follow  
redirects (and this is configurable, you can have a rewriting function  
here). Http_fs normally uses the default, so redirects are followed  
without rewriting, and it is not possible to change this (this is a  
per-request setting in Http_client, and you cannot get the request  
object unfortunately).

So, I'd also recommend here to use Http_client directly.

Gerd

> 
> Regards,
> 
> Pierre-Alexandre
> 
> --
> ---------------------
> https://twitter.com/#!/ontologiae/
> http://linuxfr.org/users/montaigne
> 

------Zitierte Anlage------
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond.  
> Discussions
> will include endpoint security, mobile security and the latest in  
> malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

------Zitierte Anlage------
> _______________________________________________
> Ocamlnet-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ocamlnet-devel
> 



-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    [email protected]
Creator of GODI and camlcity.org.
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/