Skip to content

Commit

Permalink
Changed function signature of redirectTo based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinmoris committed Apr 26, 2017
1 parent 7f5fe4d commit b82d835
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -796,16 +796,16 @@ let app =

### redirectTo

`redirectTo` uses a 302 or 301 (when permanent) HTTP response code to redirect the client to the specified location. It takes in two parameters, the location to redirect to and a boolean flag denoting whether the redirect should be permanent or not.
`redirectTo` uses a 302 or 301 (when permanent) HTTP response code to redirect the client to the specified location. It takes in two parameters, a boolean flag denoting whether the redirect should be permanent or not and the location to redirect to.

#### Example:

```fsharp
let app =
choose [
route "/" >=> redirectTo "/foo" false
route "/example" >=> redirectTo "http://example.org" true
route "/foo" >=> text "Some string"
route "/" >=> redirectTo false "/foo"
route "/permanent" >=> redirectTo true "http://example.org"
route "/foo" >=> text "Some string"
]
```

Expand Down
2 changes: 1 addition & 1 deletion src/Giraffe/HttpHandlers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ let negotiate (responseObj : obj) =
responseObj

///Redirects to a different location with a 302 or 301 (when permanent) HTTP status code.
let redirectTo (location : string) (permanent : bool) =
let redirectTo (permanent : bool) (location : string) =
fun (ctx:HttpHandlerContext) ->
ctx.HttpContext.Response.Redirect(location, permanent)
ctx |> Some |> async.Return
4 changes: 2 additions & 2 deletions tests/Giraffe.Tests/HttpHandlerTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,7 +1243,7 @@ let ``GET "/redirect" redirect to "/" `` () =
let app =
GET >=> choose [
route "/" >=> text "Hello World"
route "/redirect" >=> redirectTo "/" false
route "/redirect" >=> redirectTo false "/"
setStatusCode 404 >=> text "Not found" ]

ctx.Request.Method.ReturnsForAnyArgs "GET" |> ignore
Expand All @@ -1265,7 +1265,7 @@ let ``POST "/redirect" redirect to "/" `` () =
let app =
POST >=> choose [
route "/" >=> text "Hello World"
route "/redirect" >=> redirectTo "/" true
route "/redirect" >=> redirectTo true "/"
setStatusCode 404 >=> text "Not found" ]

ctx.Request.Method.ReturnsForAnyArgs "POST" |> ignore
Expand Down

0 comments on commit b82d835

Please sign in to comment.