A http (and Websockets!) server, implemented in C#.
Originally built for the /r/dailyprogrammer hard challenge #322.
GlidingSquirrel is currently in alpha testing! Don't use this in production unless you really know what you're doing :P
The logo is temporary!
- HTTP 1.0 / 1.1 (RFC 1945 / RFC 1616) supported (mostly - bug reports & pull requests welcome :D)
- Uses C♯ 7
- Does not have anything to do with
System.Net.HttpServerwhatsoever at all
- Easily extendable (it's an abstract class)
- Supports client requests with bodies (e.g.
PUT, but any http verb with a
- Parses and respects the
- Supports keep-alive connections (HTTP 1.1 only, of course)
- Supports Websockets (RFC 6455, Initial implementation, version 13 only, needs thorough testing - detailed bug reports welcome :D)
- Global configurable logging level
- Ability to cleanly shut the server down
- Trailing headers
- Give implementors of
WebsocketServera cleaner way to decide whether they want to accept a connection or not
Start by making sure your project is using the .NET framework 4.6.2 or higher, and then install the
GlidingSquirrel (pre-release) NuGet package. Here's an overview of the important classes you'll probably come into contact with:
SBRL.GlidingSquirrel.Http.HttpServer- The main HTTP server class. Inherit from this to create a HTTP server.
SBRL.GlidingSquirrel.Http.HttpRequest- Represents HTTP requests incoming from clients.
SBRL.GlidingSquirrel.Http.HttpResponse- Represents the HTTP response that will be sent by to the client.
SBRL.GlidingSquirrel.Http.HttpMessage- The base class that
SBRL.GlidingSquirrel.Http.HttpResponseCode- Represents a HTTP response code that is returned to the client.
SBRL.GlidingSquirrel.Websocket.WebsocketServer- The main Websockets server class. Inherit from this to create a websockets-capable server!
SBRL.GlidingSquirrel.Websocket.WebsocketClient- Represents a single Websocket client.
SBRL.GlidingSquirrel.Websocket.WebsocketFrame- Represents a single frame received from / about to be sent to a client.
SBRL.GlidingSquirrel.Log- The global logging class that all log messages flow through. Can be tuned to increase / decrease the verbosity of the logging messages.
SBRL.GlidingSquirrel.LogLevel- The enum that contains the different logging levels.
The best way I'm currently aware of to get an idea as to how to utilise this library for yourself is to take a look at the demo server modes built into the CLI project that's part of the main GlidingSquirrel solution.
GlidingSquirrel now has automatically generated documentation with mdoc! You can find it here.
Things to watch out for
- If you don't set the response body (either with
response.Body = StreamReader), then no response will be sent to the browser and clients will sit there waiting for a response indefinitely!
- If you set the response body directly via
response.Body = StreamReader, some clients may require the
ContentLengthproperty to be specified also (
response.SetBody()does this automatically) - especially if a client is using a persistent connection.
- As the GlidingSquirrel supports HTTP/1.1 persistent connection, you can tell it what (not?) to do with a connection either before or after sending a response via the
HttpConnectionActionenum that you return a value from in
HandleHttpRequestfor websockets servers).