SaturnFramework / Saturn

Opinionated, web development framework for F# which implements the server-side, functional MVC pattern
https://saturnframework.org
MIT License
708 stars 108 forks source link

Cannot use accept plug in pipeline #183

Closed isaacabraham closed 4 years ago

isaacabraham commented 5 years ago

On Saturn 0.8.0, the following code fails:

let myPipe = pipeline {
    plug acceptJson
}

let routes = router {
    pipe_through myPipe
    get "/status" (text "Saturn is awesome!")
}

let app = application {
    url "http://localhost:8080"
    use_router routes
}

run app

with the following request:

GET http://localhost:8080/status
content-type: application/json

The error given is:

info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
      Request starting HTTP/1.1 GET http://localhost:8080/status application/json
fail: Giraffe.Middleware.GiraffeErrorHandlerMiddleware[0]
      An unhandled exception has occurred while executing the request.
System.ArgumentNullException: Value cannot be null.
Parameter name: source
   at Microsoft.FSharp.Collections.SeqModule.Map[T,TResult](FSharpFunc`2 mapping, IEnumerable`1 source)
   at Giraffe.Core.mustAccept(FSharpList`1 mimeTypes, FSharpFunc`2 next, HttpContext ctx) in C:\projects\giraffe\src\Giraffe\Core.fs:line 518
   at Giraffe.Middleware.Invoke@29.Invoke(Unit unitVar) in C:\projects\giraffe\src\Giraffe\Middleware.fs:line 31
   at FSharp.Control.Tasks.TaskBuilder.run[a](FSharpFunc`2 firstStep) in C:\Users\humbo\source\repos\TaskBuilder.fs\TaskBuilder.fs:line 226
--- End of stack trace from previous location where exception was thrown ---
   at Giraffe.Middleware.Invoke@63-5.Invoke(Unit unitVar) in C:\projects\giraffe\src\Giraffe\Middleware.fs:line 63
   at FSharp.Control.Tasks.TaskBuilder.tryWith[a](FSharpFunc`2 step, FSharpFunc`2 catch) in C:\Users\humbo\source\repos\TaskBuilder.fs\TaskBuilder.fs:line 165
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 280.697ms 500 application/json; charset=utf-8

I've tried a POST as well with the same error.

ChrSteinert commented 4 years ago

I think this can be closed. With Saturn 0.12.1 this no longer throws an error, but returns an expected 404 - the acceptJson filters allows requests, that have the Accept header set to application/json, which also works as expected :)