Skip to content

Instantly share code, notes, and snippets.

@samueleaton
samueleaton / remote_address.cr
Created March 15, 2019 00:20
Adds remote_address to server context
require "http/server"
# from https://github.com/crystal-lang/crystal/pull/7302
class HTTP::Request
@io : IO?
def initialize(@method : String, @resource : String, headers : Headers? = nil, body : String | Bytes | IO | Nil = nil, @version = "HTTP/1.1", @io : IO? = nil)
@headers = headers.try(&.dup) || Headers.new
self.body = body
@samueleaton
samueleaton / handlers.fs
Last active November 29, 2020 22:44
simple hello world server in F#
namespace MyApp
open Sol.Context
module Middlewares =
let authenticateAdmin next ctx =
let isAdmin = hasQueryParam "is_admin" ctx