30 | %hide Control.Category.Category
31 | %hide Control.Category.(.)
32 | %hide IPCOptions.path
34 | export
39 | ------------------------------------------------------------------------------------
40 | -- DSL primitives for parsable data
41 | ------------------------------------------------------------------------------------
65 | -- IO effect is just for memory allocation of the buffer
68 | export
73 | export
82 | export
86 | export
94 | export
98 | export
102 | export
137 | fromContentType PDF = String -- incorrect but that will do for the demo should probably be Buffer or something
147 | where
153 | in
168 | where
173 | ||| Lookup a value and pop the found key-value pair from the list if it is present
174 | lookupPop : Eq a => List (a, b) -> {default [] acc : List (a, b)} -> a -> Maybe (b, List (a, b))
182 | ------------------------------------------------------------------------------------
183 | -- Request parsing
184 | ------------------------------------------------------------------------------------
185 | %hide Request.(.url)
187 | ||| A helper to parse a GET request given a function that parses the URL and the request body
188 | export
197 | where
202 | | False => trace "expected method \{show method}, but this request has method \{show req.method}" Nothing
212 | ||| A helper to parse a GET request given a function that parses the URL and the body
213 | export
220 | ||| A helper to parse a GET request given a function that matches the URL and parses the body from JSON
221 | export
225 | parsePost' matchURL = parseGeneric {argBody, finalResult = argBody} POST (fromBool . matchURL) (const id)
227 | ||| A helper to parse a GET request given a function that parses the URL and the body
228 | export
235 | ||| A helper to parse a GET request given a function that matches the URL and parses the body from JSON
236 | export
240 | parsePut' matchURL = parseGeneric {argBody, finalResult = argBody} PUT (fromBool . matchURL) (const id)
242 | ||| A helper to parse a GET request given a function that matches the URL and parses the body from JSON
243 | export
249 | ||| A helper to parse a GET request given a function that parses the URL
250 | export
251 | parseGet : forall arg. (tj : ToJSON t) => (matchURL : WFURL -> Maybe arg) -> JSONHTTP =&> Any.Maybe (arg :- t)
254 | ||| A helper to parse a GET request given a function that matches on the URL
255 | export
259 | parseGet' matchURL = parseGeneric {argBody = (), finalResult = ()} GET (fromBool . matchURL) (const id)
261 | ||| Root of the file system "/".
262 | export
266 | export
270 | export
274 | ------------------------------------------------------------------------------------
275 | -- convert HTTP request/responses
276 | ------------------------------------------------------------------------------------
278 | ||| parse the URL of an HTTP request into its own URL type for further analysis
279 | export
284 | where
294 | ||| Ensures a request has a specific header
295 | ||| Returns the request if it does, returns `Nothign` otherwise
296 | export
302 | ||| Parse a request body as JSON, does not check for `content-type=application/json`
303 | export
312 | ||| Parse a request body as JSON, does not check for `content-type=application/json`
313 | export
322 | ||| Parses a request body as JSON, checks for `content-type=application/json`
323 | export
327 | %hide TyTTP.Core.Response.Response.(.body)
332 | ||| Convert the request body into JSON. Checks for content-type: application/json header
333 | export
336 | Just y => Just y ## \x => map (maybe emptyBuffer (Builtin.snd . unsafePerformIO . toBuffer)) (extract x)
339 | ||| Convert all requests and responses are ones that manipulate JSON
340 | export
344 | ||| Return bad request if the request could not be parsed
345 | export
349 | ||| Convert an execution for JSON-bodied requests to general HTTP requests
350 | export
359 | ||| Convert the request body into a JSON value, do not check for content-type header
360 | export
367 | ||| Convert all requests and responses are ones that manipulate JSON, does not check for content-type header
368 | export
372 | ||| Return bad request if the request could not be parsed
373 | export
377 | ||| Convert an execution for JSON-bodied requests to general HTTP requests
378 | export
393 | ||| Convert the request body into a JSON value, do not check for content-type header
394 | export
400 | in map (maybe emptyBuffer (\xx => Builtin.snd $ unsafePerformIO $ toBuffer @{SerialiseToJSON} xx)) ix
402 | ||| Convert all requests and responses are ones that manipulate JSON, does not check for content-type header
403 | export
407 | ||| Return bad request if the request could not be parsed
408 | export
412 | ||| Convert an execution for JSON-bodied requests to general HTTP requests
413 | export