Skip to content

Commit

Permalink
Upped version, moved private functions together, small text changes f…
Browse files Browse the repository at this point in the history
…or NuGet package
  • Loading branch information
dustinmoris committed Feb 16, 2017
1 parent 0f1c6d4 commit 5e6db01
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Read [this blog post on functional ASP.NET Core](https://dusted.codes/functional

[![Build history](https://buildstats.info/appveyor/chart/dustinmoris/aspnetcore-lambda?includeBuildsFromPullRequest=false)](https://ci.appveyor.com/project/dustinmoris/aspnetcore-lambda/history)

**ATTENTION: THIS PROJECT IS STILL IN AN EARLY ALPHA STAGE**
**ATTENTION: THIS PROJECT IS STILL IN ALPHA STAGE**

## Table of contents

Expand Down
66 changes: 37 additions & 29 deletions src/AspNetCore.Lambda/HttpHandlers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,43 @@ type HttpHandler = HttpHandlerContext -> Async<HttpHandlerContext option>

type ErrorHandler = exn -> HttpHandler

/// ---------------------------
/// Private helper functions
/// ---------------------------
let private strOption (str : string) =
if String.IsNullOrEmpty str then None else Some str

[<Literal>]
let private RouteKey = "aspnet_lambda_route"

let private getSavedSubPath (ctx : HttpContext) =
if ctx.Items.ContainsKey RouteKey
then ctx.Items.Item RouteKey |> string |> strOption
else None

let private getPath (ctx : HttpContext) =
match getSavedSubPath ctx with
| Some p -> ctx.Request.Path.ToString().[p.Length..]
| None -> ctx.Request.Path.ToString()

let private handlerWithRootedPath (path : string) (handler : HttpHandler) =
fun (ctx : HttpHandlerContext) ->
async {
let savedSubPath = getSavedSubPath ctx.HttpContext
try
ctx.HttpContext.Items.Item RouteKey <- ((savedSubPath |> Option.defaultValue "") + path)
return! handler ctx
finally
match savedSubPath with
| Some savedSubPath -> ctx.HttpContext.Items.Item RouteKey <- savedSubPath
| None -> ctx.HttpContext.Items.Remove RouteKey |> ignore
}

/// ---------------------------
/// Default HttpHandlers
/// ---------------------------
/// Combines two HttpHandler functions into one.
/// If the first HttpHandler returns Some HttpContext, then it will proceed to
/// the second handler, otherwise short circuit and return None as the final result.
Expand Down Expand Up @@ -140,35 +177,6 @@ let clearResponse =
ctx.HttpContext.Response.Clear()
async.Return (Some ctx)

let private strOption (str : string) =
if String.IsNullOrEmpty str then None else Some str

[<Literal>]
let private RouteKey = "aspnet_lambda_route"

let private getSavedSubPath (ctx : HttpContext) =
if ctx.Items.ContainsKey RouteKey
then ctx.Items.Item RouteKey |> string |> strOption
else None

let private getPath (ctx : HttpContext) =
match getSavedSubPath ctx with
| Some p -> ctx.Request.Path.ToString().[p.Length..]
| None -> ctx.Request.Path.ToString()

let private handlerWithRootedPath (path : string) (handler : HttpHandler) =
fun (ctx : HttpHandlerContext) ->
async {
let savedSubPath = getSavedSubPath ctx.HttpContext
try
ctx.HttpContext.Items.Item RouteKey <- ((savedSubPath |> Option.defaultValue "") + path)
return! handler ctx
finally
match savedSubPath with
| Some savedSubPath -> ctx.HttpContext.Items.Item RouteKey <- savedSubPath
| None -> ctx.HttpContext.Items.Remove RouteKey |> ignore
}

/// Filters an incoming HTTP request based on the request path (case sensitive).
let route (path : string) =
fun (ctx : HttpHandlerContext) ->
Expand Down
10 changes: 6 additions & 4 deletions src/AspNetCore.Lambda/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "AspNetCore.Lambda",
"version": "0.1.0-alpha002-*",
"description": "An attempt to make ASP.NET Core more functional.",
"version": "0.1.0-alpha003-*",
"description": "A native functional ASP.NET Core web framework for F# developers.",
"copyright": "Copyright 2017 Dustin Moris Gorski",
"authors": [
"Dustin Moris Gorski"
Expand Down Expand Up @@ -41,13 +41,15 @@
},
"dependencies": {},
"packOptions": {
"summary": "An attempt to make ASP.NET Core more functional.",
"summary": "A native functional ASP.NET Core web framework for F# developers.",
"tags": [
"ASP.NET Core",
"Lambda",
"FSharp",
"Functional",
"Http"
"Http",
"Web",
"Framework"
],
"owners": [
"Dustin Moris Gorski"
Expand Down

0 comments on commit 5e6db01

Please sign in to comment.