kernel.hoon 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /+ *wrapper
  2. =>
  3. |%
  4. +$ server-state %stateless
  5. ++ moat (keep server-state)
  6. +$ header [k=@t v=@t]
  7. +$ octs [p=@ q=@]
  8. +$ method
  9. $? %'GET'
  10. %'HEAD'
  11. %'POST'
  12. %'PUT'
  13. %'DELETE'
  14. %'CONNECT'
  15. %'OPTIONS'
  16. %'TRACE'
  17. %'PATCH'
  18. ==
  19. ::
  20. +$ cause
  21. $: %req
  22. id=@
  23. uri=@t
  24. =method
  25. headers=(list header)
  26. body=(unit octs)
  27. ==
  28. ::
  29. +$ effect
  30. $: %res
  31. id=@
  32. status=@ud
  33. headers=(list header)
  34. body=(unit octs)
  35. ==
  36. ::
  37. ++ to-octs
  38. |= bod=@
  39. ^- (unit octs)
  40. =/ len (met 3 bod)
  41. ?: =(len 0) ~
  42. `[len bod]
  43. --
  44. ::
  45. ~& %serving
  46. %- (moat |)
  47. ^- fort:moat
  48. |_ k=server-state
  49. ::
  50. :: +load: upgrade from previous state
  51. ::
  52. ++ load
  53. |= arg=server-state
  54. arg
  55. ::
  56. :: +peek: external inspect
  57. ::
  58. ++ peek
  59. |= =path
  60. ^- (unit (unit *))
  61. !!
  62. ::
  63. :: +poke: external apply
  64. ::
  65. ++ poke
  66. |= [=wire eny=@ our=@ux now=@da dat=*]
  67. ^- [(list effect) server-state]
  68. =/ sof-cau=(unit cause) ((soft cause) dat)
  69. ?~ sof-cau
  70. ~& "cause incorrectly formatted!"
  71. ~& dat
  72. !!
  73. =/ [id=@ uri=@t =method headers=(list header) body=(unit octs)] +.u.sof-cau
  74. ~& [id+id uri+uri method+method headers+headers]
  75. :_ k
  76. :_ ~
  77. ^- effect
  78. =- ~& effect+-
  79. -
  80. ?+ method [%res ~ %400 ~ ~]
  81. %'GET'
  82. :* %res id=id %200
  83. ['content-type' 'text/html']~
  84. %- to-octs
  85. '''
  86. <!doctype html>
  87. <html>
  88. <body>
  89. <h1>Hello NockApp!</h1>
  90. </body>
  91. </html>
  92. '''
  93. ==
  94. ::
  95. %'POST'
  96. !!
  97. ==
  98. --