Guest User

Untitled

a guest
May 19th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #
  2. # Mansur Mamkin <[email protected]>
  3. # httpjson.l adds support for POST-requests with JSON body
  4. #
  5.  
  6. (push '*Mimes '(`(chop "json") "application/json; charset=utf-8"))
  7.  
  8. (de _htJson ()
  9. (let F (tmp "json.json")
  10. (out F (echo *ContLen))
  11. (in F (setq *JSON (readJson T))) ) )
  12.  
  13. (patch http
  14. '(cond @A ((=0 *ContLen)) @B)
  15. (fill
  16. '(cond
  17. ^ @A
  18. ((=0 *ContLen))
  19. ((pre? "application/json" *ContentType) (_htJson))
  20. ^ @B ) ) )
  21.  
  22.  
  23. (patch _htHead
  24. '("content-type:" @A)
  25. '("content-type:"
  26. (char) # or better (skip)?
  27. (case (lowc (till "/" T))
  28. ("multipart"
  29. (if (= "/form-data; boundary" (lowc (till "=" T)))
  30. (setq
  31. *ContentType "multipart/form-data"
  32. *MPartLim (append '(- -) (cdr (line)))
  33. *MPartEnd (append *MPartLim '(- -)) )
  34. (line) ) )
  35. (T (setq *ContentType (pack @ (line T))) ) ) ) )
  36.  
  37. #example
  38. #{
  39. (allow "!getjson")
  40.  
  41. (de getjson ()
  42. (msg 'JSON= (sym *JSON))
  43. (let F (tmp "out.json")
  44. (out F (printJson '(("answerParam" . "ok"))))
  45. (httpEcho F "application/json; charset=utf-8" 1) ) )
  46.  
  47. }#
Advertisement
Add Comment
Please, Sign In to add comment