~/bend-docscommunity

http_server/middleware.bend checks

raw source on the hub · import 0x7232384c42402f977ceed3b85efc3adc/http_server/middleware.bend as Middleware

6 imports
import Base
import ../http/method.bend as M
import ../http/status.bend as S
import ../http/request.bend as Req
import ../http/headers.bend as H
import ../http/response.bend as Res

Types

type Sized source · line 40 · raw

Data

a body and its length, counted in one read

Definitions

def RS source · line 16 · raw

Type

def recover.go source · line 22 · raw

@r:RS -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)

def count source · line 43 · raw

@bs:List<&2, U32> -> @+n:U32 -> @acc:List<&2, U32> -> Sized

def hex.digit source · line 72 · raw

@+d:U32 -> Char

def hex.go source · line 75 · raw

@n:Nat -> @+x:U32 -> @acc:String -> String

def hex source · line 82 · raw

@+x:U32 -> String

def random source · line 85 · raw

@r:Result<&1, &1, Pair(U32, String), U32> -> U32

def copy source · line 103 · raw

@s:String -> @acc:String -> String

def method_name source · line 112 · raw

@m:0x7232384c42402f977ceed3b85efc3adc/http/method.Method -> String

the method's name, copied: M.show hands back MOther's own String, which would take the method the request still needs

def logged source · line 135 · raw

@line:String -> @+start:Nat -> @res:0x7232384c42402f977ceed3b85efc3adc/http/response.Response -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)

Templates

template recover source · line 33 · raw

@-next:(@_:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(RS)) -> @r:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)

a handler that may fail: Fail{why} logs why to stderr and answers 500, so a handler's error never reaches the client

template body_limit.go source · line 50 · raw

@-next:(@_:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)) -> @ok:Bool -> @m:0x7232384c42402f977ceed3b85efc3adc/http/method.Method -> @t:String -> @hs:List<&2, 0x7232384c42402f977ceed3b85efc3adc/http/headers.Header> -> @b:List<&2, U32> -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)

template body_limit.sized source · line 57 · raw

@-max:U32 -> @-next:(@_:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)) -> @s:Sized -> @m:0x7232384c42402f977ceed3b85efc3adc/http/method.Method -> @t:String -> @hs:List<&2, 0x7232384c42402f977ceed3b85efc3adc/http/headers.Header> -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)

template body_limit source · line 64 · raw

@-max:U32 -> @-next:(@_:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)) -> @r:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)

a body over max bytes answers 413 before next sees it; the server's max_body_bytes bounds every body, this one a handler's

template request_id source · line 93 · raw

@-next:(@_:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)) -> @r:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)

every response gets x-request-id: 16 random hex digits

template logger.go source · line 143 · raw

@-next:(@_:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)) -> @line:String -> @r:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)

template logger source · line 150 · raw

@-next:(@_:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)) -> @r:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)

one line per request on stdout: "GET /todos/2 200 0ms"