A response for the browser to download
About
This is just a simple response that will trigger the browser to download something.
Code
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Hosting
open Giraffe
let handler : HttpHandler =
fun (_ : HttpFunc) (context : HttpContext) -> task {
context.SetHttpHeader("Content-Disposition","attachment; filename=\"foobar.txt\"")
let bytes = "helloworld" |> System.Text.Encoding.UTF8.GetBytes
return! context.WriteBytesAsync(bytes)
}
[<EntryPoint>]
let main args =
let builder = WebApplication.CreateBuilder(args)
builder.Services.AddGiraffe() |> ignore
let app = builder.Build()
app.UseGiraffe(handler)
app.Run()
0