Skip to content

Commit

Permalink
Added HttpContext helper extension methods
Browse files Browse the repository at this point in the history
Added two more HttpContext extension methods, which make accessing Cookie values and Form values more F# idiomatic.
  • Loading branch information
dustinmoris committed Feb 10, 2019
1 parent 6d86874 commit 91c28a2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
8 changes: 7 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
Release Notes
=============

## 3.5.1
## 3.6.0

#### Bug fixes

- Fixed a bug in Giraffe's model binding to not try to set read only properties anymore.

#### New features

- Added two new `HttpContext` extension methods to retrieve cookie and form values:
- `GetCookieValue (key : string)`
- `GetFormValue (key : string)`

## 3.5.0

#### New features
Expand Down
37 changes: 37 additions & 0 deletions src/Giraffe/Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,43 @@ type HttpContext with
| true, value -> Ok (value.ToString())
| _ -> Error (sprintf "Query string value '%s' is missing." key)

/// **Description**
///
/// Retrieves the `string` value of a cookie from the request.
///
/// **Parameters**
///
/// `key`: The name of the cookie.
///
/// **Output**
///
/// Returns `Some string` if the cookie was set, otherwise returns `None`.
///
member this.GetCookieValue (key : string) =
match this.Request.Cookies.TryGetValue key with
| true , cookie -> Some cookie
| false, _ -> None

/// **Description**
///
/// Retrieves the `string` value of a form parameter from the request.
///
/// **Parameters**
///
/// `key`: The name of the form parameter.
///
/// **Output**
///
/// Returns `Some string` if the form parameter was set, otherwise returns `None`.
///
member this.GetFormValue (key : string) =
match this.Request.HasFormContentType with
| false -> None
| true ->
match this.Request.Form.TryGetValue key with
| true , value -> Some (value.ToString())
| false, _ -> None

// ---------------------------
// HttpHandler definition
// ---------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/Giraffe/Giraffe.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<!-- General -->
<AssemblyName>Giraffe</AssemblyName>
<Version>3.5.1</Version>
<Version>3.6.0</Version>
<Description>A native functional ASP.NET Core web framework for F# developers.</Description>
<Copyright>Copyright 2018 Dustin Moris Gorski</Copyright>
<Authors>Dustin Moris Gorski and contributors</Authors>
Expand Down

0 comments on commit 91c28a2

Please sign in to comment.