Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Mansur Mamkin <[email protected]>
- # httpjson.l adds support for POST-requests with JSON body
- #
- (push '*Mimes '(`(chop "json") "application/json; charset=utf-8"))
- (de _htJson ()
- (let F (tmp "json.json")
- (out F (echo *ContLen))
- (in F (setq *JSON (readJson T))) ) )
- (patch http
- '(cond @A ((=0 *ContLen)) @B)
- (fill
- '(cond
- ^ @A
- ((=0 *ContLen))
- ((pre? "application/json" *ContentType) (_htJson))
- ^ @B ) ) )
- (patch _htHead
- '("content-type:" @A)
- '("content-type:"
- (char) # or better (skip)?
- (case (lowc (till "/" T))
- ("multipart"
- (if (= "/form-data; boundary" (lowc (till "=" T)))
- (setq
- *ContentType "multipart/form-data"
- *MPartLim (append '(- -) (cdr (line)))
- *MPartEnd (append *MPartLim '(- -)) )
- (line) ) )
- (T (setq *ContentType (pack @ (line T))) ) ) ) )
- #example
- #{
- (allow "!getjson")
- (de getjson ()
- (msg 'JSON= (sym *JSON))
- (let F (tmp "out.json")
- (out F (printJson '(("answerParam" . "ok"))))
- (httpEcho F "application/json; charset=utf-8" 1) ) )
- }#
Advertisement
Add Comment
Please, Sign In to add comment