[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [MirageOS-devel] Web server MIME types / content types



Hi Len,

Thanks for the reply. :-)

I hope Iâm not coming across as too negative if I suggest that without the 
correct content type for HTML files the Mirageos unikernel web server serving 
static files is effectively broken for real world application. Sorry that 
sounds a bit harsh written in an email.

For example if you go to http://54.177.71.245 and click on the âLooking for 
Larry and Sergeyâ link, in Chrome it returns an error.  It should display fine 
since itâs just a plain HTML page - the primary use case of web serving.

I do appreciate the directions to how to implement content type thank you, but 
at this stage was hoping more just to build and use the Mirageos unikernel for 
serving static websites.

Do you know if there is there an alternative OCaml web server that can run in a 
Mirageos unikernel, bake in the static files and serve them with content-type?

thanks!

as



On 29 May 2015, at 10:23 pm, Len Maxwell <len@xxxxxxxx> wrote:

Hi Andrew,

It looks like Cohttp will respond with content-type, but only when
using Cohttp_lwt_unix.respond_file [1].  That's a convenience function
for serving a file from the local filesystem, which assumes too much
for a unikernel environment (hence it is in the _unix module).

Assuming you are using something like mirage-skeleton/static_website,
you can add the content-type bits to your dispatch function [2].
After read_fs returns the content data, feed the vpath to magic-mime
to guess the type and add your own content-type header -- maybe:

   try_lwt
     read_fs path
>> = fun body ->
     let mime_type = Magic_mime.lookup path in
     let headers = Cohttp.Header.init in
     let headers = Cohttp.Header.add_opt headers "content-type" mime_type in
     S.respond_string ~status:`OK ~body ~headers ()

To include magic-mime in your kernel, you will need to reference it
with add_to_ocamlfind_libraries / add_to_opam_packages in config.ml.

This would be a nice feature to have in a higher-level project like
mirage-seal [3].

[1] 
https://github.com/mirage/ocaml-cohttp/blob/84450beb6a532be8455a30c7782dbf1b3294622e/lwt/cohttp_lwt_unix.ml#L55
[2] 
https://github.com/mirage/mirage-skeleton/blob/a13cde3bb0421f3685c16b1ae5ef334986c6d0f0/static_website/dispatch.ml#L39
[3] https://github.com/mirage/mirage-seal/


--
Len

On Fri, May 29, 2015 at 6:49 AM, Andrew Stuart
<andrew.stuart@xxxxxxxxxxxxxxxxxx> wrote:
>>> Which version of which web server are you using?
> 
> ubuntu@ip-172-30-2-123:~/www.supercoders.com.au$ opam list | grep http
> cohttp                 0.17.2  HTTP library for Lwt, Async and Mirage
> mirage-http             2.2.0  Mirage HTTP client and server driver
> ubuntu@ip-172-30-2-123:~/www.supercoders.com.au$
> 
>>> What are you serving and what media type is being set?
> 
> Just plain HTML pages and images.
> 
>>> What configuration are you using?
> 
> Err, not sure.  How can I say?  Itâs a unikernel built with the latest 
> release as far as I can tell.
> 
> Interestingly the release notes here 
> https://github.com/mirage/ocaml-cohttp/blob/master/CHANGES
> 
> says:
> 
> 0.16.0 (2015-03-23):
> New features and bug fixes:
> * Use the `magic-mime` library to add a MIME type by probing filename
>  during static serving in the Lwt/Async backends. (#260)
> 
> But it does not appear to be doing so.
> 
> 
> Below are two requests, one to nginx and one Mirageos.  You can see that 
> Mirageos is not returning Content-Type: text/html
> 
> **************************************************
> *********************************************NGINX:
> ubuntu@xxxxxxxxxxxxxxxxxxxxxx:/var/www/supercoders.com.au/htdocs$ curl -v -D 
> - http://www.supercoders.com.au
> * Rebuilt URL to: http://www.supercoders.com.au/
> * Hostname was NOT found in DNS cache
> *   Trying 54.215.13.78...
> * Connected to www.supercoders.com.au (54.215.13.78) port 80 (#0)
>> GET / HTTP/1.1
>> User-Agent: curl/7.35.0
>> Host: www.supercoders.com.au
>> Accept: */*
>> 
> < HTTP/1.1 200 OK
> HTTP/1.1 200 OK
> * Server nginx/1.4.6 (Ubuntu) is not blacklisted
> < Server: nginx/1.4.6 (Ubuntu)
> Server: nginx/1.4.6 (Ubuntu)
> < Date: Fri, 29 May 2015 10:47:52 GMT
> Date: Fri, 29 May 2015 10:47:52 GMT
> < Content-Type: text/html
> Content-Type: text/html
> < Transfer-Encoding: chunked
> Transfer-Encoding: chunked
> < Connection: keep-alive
> Connection: keep-alive
> 
> <
> <html >
> <head>
> 
> 
> **************************************************
> *********************************************MirageOS:
> ubuntu@xxxxxxxxxxxxxxxxxxxxxx:/var/www/supercoders.com.au/htdocs$ curl -v -D 
> - http://54.177.71.245
> * Rebuilt URL to: http://54.177.71.245/
> * Hostname was NOT found in DNS cache
> *   Trying 54.177.71.245...
> * Connected to 54.177.71.245 (54.177.71.245) port 80 (#0)
>> GET / HTTP/1.1
>> User-Agent: curl/7.35.0
>> Host: 54.177.71.245
>> Accept: */*
>> 
> < HTTP/1.1 200 OK
> HTTP/1.1 200 OK
> < content-length: 21281
> content-length: 21281
> 
> <
> <html >
> <head>
> 
> 
> 
> 
> 
> _______________________________________________
> MirageOS-devel mailing list
> MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
> http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel


_______________________________________________
MirageOS-devel mailing list
MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.