~/bend-docscommunity

http_server/server.bend fails

raw source on the hub · import 0x7232384c42402f977ceed3b85efc3adc/http_server/server.bend as Server

7 imports
import Base
import ../wire/wire.bend as W
import ../http1/http1.bend as H1
import ../http1/bytes.bend as B
import ../http/request.bend as Req
import ../http/response.bend as Res
import ../http/status.bend as S

Laws

law sent unverifiedits file does not pass the checker (fails)source · line 45 · raw

@close:Bool -> @rest:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @m:RU -> @next:(@_:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @_:Nat -> @_:Socket -> IO(Unit)) -> IO(Unit)

after a response is sent: close, or go on with the bytes after the request

law late unverifiedits file does not pass the checker (fails)source · line 76 · raw

@m:RU -> IO(Unit)

law polled unverifiedits file does not pass the checker (fails)source · line 109 · raw

@idle:Bool -> @acc:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @+dl:Nat -> @m:RP -> @next:(@_:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @_:Nat -> @_:Socket -> IO(Unit)) -> IO(Unit)

more bytes came: go on with them, or close if the client has

Types

type Config source · line 19 · raw

Data

Definitions

def default source · line 22 · raw

@port:U32 -> Config

def RP source · line 25 · raw

Type

def RU source · line 28 · raw

Type

def copy source · line 31 · raw

@bs:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @acc:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> 0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes

def refuse source · line 39 · raw

@st:0x7232384c42402f977ceed3b85efc3adc/http/status.Status -> 0x7232384c42402f977ceed3b85efc3adc/http/response.Response

a refused request's answer: its status, with the reason as the text

def got.go source · line 62 · raw

@done:Bool -> @acc:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @bs:List<&2, U32> -> @+dl:Nat -> @s:Socket -> @next:(@_:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @_:Nat -> @_:Socket -> IO(Unit)) -> IO(Unit)

def empty source · line 69 · raw

@bs:List<&2, U32> -> Bool

def timed_out source · line 85 · raw

@s:Socket -> IO(Unit)

the deadline passed mid-request: 408, then close

def quiet source · line 92 · raw

@idle:Bool -> @s:Socket -> IO(Unit)

nothing came in time: an idle connection closes quietly, one mid-request is told why

def polled.fold source · line 99 · raw

@idle:Bool -> @r:Result<&1, &1, Pair(U32, String), Maybe<&1, List<&2, U32>>> -> @acc:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @+dl:Nat -> @s:Socket -> @next:(@_:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @_:Nat -> @_:Socket -> IO(Unit)) -> IO(Unit)

def deadline source · line 122 · raw

@+dl:Nat -> @+now:Nat -> @+ms:U32 -> Nat

the deadline: set by the first read of a request, kept after

def wait.go source · line 129 · raw

@over:Bool -> @+dl:Nat -> @+now:Nat -> @acc:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @s:Socket -> @next:(@_:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @_:Nat -> @_:Socket -> IO(Unit)) -> IO(Unit)

def wait.left source · line 136 · raw

@+dl:Nat -> @+now:Nat -> @acc:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @s:Socket -> @next:(@_:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @_:Nat -> @_:Socket -> IO(Unit)) -> IO(Unit)

def wait source · line 141 · raw

@idle:Bool -> @+ims:U32 -> @+rms:U32 -> @+dl:Nat -> @acc:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @s:Socket -> @next:(@_:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @_:Nat -> @_:Socket -> IO(Unit)) -> IO(Unit)

read on: an idle connection waits idle_ms; a request under way waits until its deadline

def closing source · line 151 · raw

@+close:Bool -> @+left:Nat -> Bool

the last allowed request closes the connection

def RA source · line 182 · raw

Type

Templates

template step source · line 159 · raw

@-h:(@_:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)) -> @p:0x7232384c42402f977ceed3b85efc3adc/http1/http1.Parsed -> @+acc:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @s:Socket -> @+left:Nat -> @+ims:U32 -> @+rms:U32 -> @+dl:Nat -> @next:(@_:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @_:Nat -> @_:Socket -> IO(Unit)) -> IO(Unit)

one parse of what has come so far, and what to do with it

template conn source · line 175 · raw

@-h:(@_:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)) -> @+fuel:Nat -> @+mh:U32 -> @+mb:U32 -> @+ims:U32 -> @+rms:U32 -> @+acc:0x7232384c42402f977ceed3b85efc3adc/http1/bytes.Bytes -> @+dl:Nat -> @s:Socket -> IO(Unit)

a connection: acc is what has come and is not yet a request; fuel counts the requests it may still serve

template accepted source · line 186 · raw

@-h:(@_:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)) -> @r:Result<&1, &1, Pair(U32, String), Socket> -> @l:Listener -> @+mh:U32 -> @+mb:U32 -> @+ims:U32 -> @+rms:U32 -> @+mr:Nat -> @k:(@_:Listener -> IO(Unit)) -> IO(Unit)

an accepted connection runs on its own; the loop goes on accepting

template accept.loop source · line 197 · raw

@-h:(@_:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)) -> @+fuel:Nat -> @+mh:U32 -> @+mb:U32 -> @+ims:U32 -> @+rms:U32 -> @+mr:Nat -> @m:RA -> IO(Unit)

fuel bounds the connections served: a server's loop is bounded by the outside world, which Bend's termination check sees as a count

template serve source · line 208 · raw

@-h:(@_:0x7232384c42402f977ceed3b85efc3adc/http/request.Request -> IO(0x7232384c42402f977ceed3b85efc3adc/http/response.Response)) -> @cfg:Config -> IO(Unit)

answer requests on cfg's port with h, one connection at a time each, many connections at once