Request information (including the headers) is also available in the Context object passed to the Content. For example you can create a Content like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
        Content.CustomContent <| fun context ->
            let accept =
                context.Request.Headers
                |> Seq.tryFind (fun h -> h.Name = "Accept")
                |> Option.map (fun h -> h.Value)
            match accept with
            | Some "application/json" ->
                {
                    Headers = [Http.Header.Custom "Content-Type" "application/json"]
                    Status = Http.Status.Ok
                    WriteBody = fun stream -> // write content as json
                }
            | Some "application/xml" ->
                {
                    Headers = [Http.Header.Custom "Content-Type" "application/xml"]
                    Status = Http.Status.Ok
                    WriteBody = fun stream -> // write content as xml
                }
            | _ -> // Either no Accept, or invalid Accept value
                {
                    Headers = []
                    Status = Http.Status.Custom 406 (Some "Not acceptable")
                    WriteBody = ignore
                }
By on 8/10/2013 1:43 PM ()

Thanks, that is what I was missing. I was expecting to deal with this in the Handle method on the controller.

By on 8/12/2013 12:55 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper