operating-function / pallas

An event sourced, purely functional application platform.
https://opfn.gitbook.io/pallas
Other
33 stars 0 forks source link

`proc_http`, `lib_http` improvements #19

Open vcavallo opened 1 week ago

vcavallo commented 1 week ago

Items that fell out of http cleanup (https://github.com/operating-function/pallas/pull/21) and needed a place go to be addressed in a separate chunk of work.

vcavallo commented 1 week ago

May be useful later

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Unused for now - potentially useful later.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

> Bar > Word32
= (ipToWord ipBar)
@ octets (listToRow | barSplit 46 ipBar) ; 46 is ASCII for '.'
| if (neq 4 | len octets)
  | die {Invalid IP address format}
^ foldl _ 0 octets
& (acc octet)
@ value (barLoadDecimal octet)
| if (or (lth value 0) (gth value 255))
  | die {Invalid octet value}
| add (lsh acc 8) value

> Word32 > Bar
= (wordToIp ipWord)
@ octet1 | barShowDecimal (div ipWord 16777216)
@ octet2 | barShowDecimal (mod (div ipWord 65536) 256)
@ octet3 | barShowDecimal (mod (div ipWord 256) 256)
@ octet4 | barShowDecimal (mod ipWord 256)
| barCat [octet1 b#{.} octet2 b#{.} octet3 b#{.} octet4]

= testIp b#{192.168.1.2}
= testWord (ipToWord testIp)
= backToIp (wordToIp testWord)

=?= testIp backToIp

= testIp b#{192.0.0.0}
= testWord (ipToWord testIp)
= backToIp (wordToIp testWord)

=?= testIp backToIp