Giter Site home page Giter Site logo

suaveio / suave Goto Github PK

View Code? Open in Web Editor NEW
1.3K 53.0 199.0 23.26 MB

Suave is a simple web development F# library providing a lightweight web server and a set of combinators to manipulate route flow and task composition.

Home Page: https://suave.io

License: Other

F# 99.85% Shell 0.02% Batchfile 0.02% Liquid 0.03% Dockerfile 0.07% HTML 0.01% CSS 0.01% JavaScript 0.01%
webserver fsharp suave dotnet functional async http-server

suave's People

Contributors

adamchester avatar ademar avatar alex-bogomaz avatar ctaggart avatar danieljsummers avatar dsyme avatar enricosada avatar forki avatar haf avatar jackmott avatar jamesjrg avatar jichang avatar jimfoye avatar kos59125 avatar lambdakris avatar lucasmreis avatar mastoj avatar matthid avatar mavnn avatar njlr avatar paavohuhtala avatar panesofglass avatar rmunn avatar scitesy avatar tamizhvendan avatar theimowski avatar tpetricek avatar valhallasw avatar varon avatar xkrt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

suave's Issues

Install package with NuGet fail

Suave 0.1.78 (1/19/2014)

Package Manager Console Host Version 2.7.41101.371

PM> install-package Suave
install-package : An item with the same key has already been added.
At line:1 char:1
+ install-package Suave
+ ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], ArgumentException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

I tried it with MSVS 2013 and MSVS 2012 with new F# library project, same error.

Have a sample with exported private key in pfx

mmc > CTRL+M > Computer Account > "Personal>Certificates" > All Tasks > Private key-something > Export... > Follow guide, check export private key checkbox

Right now the pfx is missing a private key

Document warnings from compilation

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5): warning MSB3270: There was a mismatch between the processor
architecture of the project being built "MSIL" and the processor architecture of the reference "ManagedOpenSsl", "x86". This mismatch may ca
use runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as t
o align the processor architectures between your project and references, or take a dependency on references with a processor architecture th
at matches the targeted processor architecture of your project. [Z:\dev\_vendor\suave\Suave\suave.fsproj]
  suave -> Z:\dev\_vendor\suave\Suave\bin\Release\suave.dll

Are we OK with these?

File upload form performance issues

Hello,

Facing performance issues (slow) when handling post data from a form, it seems a 40mb zip will take a 10 minutes when suave is hosted on localhost. Interestingly there is exactly 25% CPU usage (1 of 4 cores) utilised during this period, which indicates that there may be some unnecessary processing (and also some cpu-synchronicity issues)

HTML:


SuaveIO (just hooked up to handle all post as upload):
POST >>== handleUpload

Generate documentation for the combinators

Would be nice to extract the XML docs directly from Http.fsi and style them.

Otherwise we could work with the already generated suave.xml and extract and filter the ones we want to publish docs for from there.

Decide where to write docs

I saw the gh-pages branch, is that where we decide to write docs? What about me linking to the github page from the readme?

Write load tests for the library

I started a branch locally with Tsung for generating some load. I think it would be a good idea to run some load tests on a web server, for every commit.

  • start and tear down the server in test cases
  • keep track of performance changes over time

[question] Interop with NancyFX

Have you seen Nancyfx. Perhaps you can some of the best features of this project also or perhaps have a interoperability bridge.

Consider different abstraction than hard-coded 'username', 'password'

The abstraction for authentication could be improved.

In .Net it's IClaimPrincipal nowadays, but there could be other ways of writing authentication with a client, such as client certificates, SAML2 tokens, JWT, Hawk or Kerberos.

Consider moving the properties from the HttpRequest type to some context that has helpers to look up. Or do it as external assemblies that attach methods/properties to HttpRequest.

Tests Organization

Ademar,

Should Suave tests go in the Tests project? If so, should the Suave and Example Tests be separated into folders?

If not, should Suave (Suave.Tests) tests have its own project?

Finally, should the *.Tests project/s be included in the solution?

Scott

Support Windows?

When doing repeated connections/socket terminations on Windows, the server crashes.

x64 libs

Hi,

fyi It seems the libs that are bundled are only x86-32, so it isn't possible to build a 64-bit server with HTTPS (or so VS tells me). Not really an issue, but some may be unaware

Write tests for the library

Text

  • UTF-8 in query strings, bodies
  • ISO-8859-1 and URI encoding for headers

IO

  • state based generators from connecting clients, perhaps something like QuickCheck for TCP for testing how sending "funny" data on the TCP level works out
  • specialise QuickCheck for HTTP protocol (?)
  • test internal state - try to model state machine, FsCheck for generation/shrinking?

Framework-parts

  • scaffolding / code that makes it quick to get started with a server implementation

Happstack talks about Grammar Driven Testing. I'm not sure what grammar they are referring to and the article doesn't say. If we can make FsCheck generate valid (and invalid) HTTP requests I would be happy enough.

Similarly Prowess could be of use when they produce something.

Getting some confidence quickly with tsung

Secure Cookies

Implement cookie abstraction with the following attributes:

name    : string
value   : string
expires : date
path    : string
domain  : string
secure  : bool
httpOnly: bool

Common abstraction points

As I read through the code-base there are a couple of abstraction points that I would implement in the long run, to ensure easy testability and extensibility of the project. This issue is more a discussion issue; I want more feedback, and I would also like to know how these topics would affect performance and if there would be enough gain by implementing it.

Basically anything that is non-functional/non-referentially transparent is this issue.

File IO

It's often nice to be able to stub or use in-memory file systems when writing integration tests of web sites and there are libraries in .Net that allow such abstractions across operating systems, with even better semantics than what .Net gives. One example is DotNetIO. Using it would allow you to stub file systems, serve with in-memory file systems and would allow you to work cross-platform.

Example of existing code, Http.fs:

    if Directory.Exists dirname then
      let di = new DirectoryInfo(dirname)
      (di.GetFileSystemInfos()) |> Array.sortBy (fun x -> x.Name) |> Array.iter buildLine
      ok (bytes (result.ToString())) req
    else fail

DateTime handling

E.g. when adding code that traces an execution, is can be helpful in tests to 'own' the time. This allows you to test edge cases and NTP daemons moving time backwards.

I normally introduce a Clock interface that can be mocked/stubbed and expected on.

Example from existing code, Log.fs (related to #17):

/// Log a line with the given format, printing the current time in UTC ISO-8601 format
/// and then the string, like such:
/// '2013-10-13T13:03:50.2950037Z: today is the day'
let log format =
  Printf.kprintf (lock sync_root <| fun () -> printfn "%s: %s" (DateTime.UtcNow.ToString("o"))) format

Session support, idempotency handling

By moving away from globals we gain testability. While we can use function composition/currying to compose the application, such points of inversion (composing functions) need to be stated from the 'start' of the composition. In other words, it's easy to use a global variable 'far down' into the application and then have to do a lot of refactoring to expose that variable as an interface...

Example from code:

/// Static dictionary of sessions
let session_map = new ConcurrentDictionary<string, ConcurrentDictionary<string, obj>>()

/// Get the session from the HttpRequest
let session (request : HttpRequest) =
  let sessionId = request.SessionId
  // snip

(which by the way has a race condition)

While this doesn't mean that we necessarily use this global variable, it's still easy for a dev to use what's in the example:

 url "/session"
    >>= session_support
// snip

and be hit by the fact that suddenly the web app is no longer possible to load-balance without bugs. Instead session_support could take a parameter with a session store implementation:

url "/session" >>= session_support Globals.AppDomainSessionStore

if identical semantics is wanted.

Similarly, idempotency handling based on request ids or hashes could be made composable based on a single-purpose protocol.

Similarly for uploads (ties into the abstraction of a file system).

Types.fs - HttpRequest - Disposing pattern

I was under the impression that one can't use managed collection and similar during a Finalize() call to Dispose, that makes it Dispose(false). But the code seems to be iterating a file collection.

File upload is broken

Tested with pre-whitespace-formatting bout and post-whitespace-formatting bout, so it's not my changes that have broken it.

I'm testing this in particular on Windows 8, Firefox 24. Trying to upload a jpg file, about 2 MB large, named a.jpg. Suave goes into 40% file usage doesn't return within my human built-in timeout.

Testing only single-file upload, by navigating to test.html.

NuGet install fails

With error: An item with the same key has already been added.

On Visual Studio 2012, Nuget package manager version 2.7.41101.299. Same error with the 2.7 command line exe.

Web.fs:208

Hi ,

Seems there is some incomplete handling (only aesthetics) on web.fs:208, reproduced by cancelling an upload half way through. Was tempted to do a pull request but I don't have git happening yet.

License?

I really like Suave. It is cleanly written and the only web application toolkit I know of that is written in F# and also builds cleanly on Mono. Great work!

What is the license on Suave?

Thanks you!

Normalise coding standards

E.g. how methods are named;

  • Utils.fs uses names like my_method_name, Json.fs uses fromJson.
  • Many lines have trailling whitespace
  • Consistent whitespace around method parameters, e.g. for this method: let toString ( buff: byte[], index:int, count:int) = which uses both whitespace before parameters, no-whitespace-before-type and whitespace-before-type.
  • Consistent formatting for matches, e.g.:
let bind p rest =
    match p with
        | None -> fail
        | Some r -> rest r

let rec choose options arg = 
    match options with
    |[] -> None
    |p::tail  -> match p arg with
                 |None -> choose tail arg
                 |Some(x)  -> Some(x)
  • Such things:
let warbler f a = f a a //wich bird? A Warbler!

jpeg image 480356 pixels

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.