Created
June 4, 2013 08:55
-
-
Save nicferrier/5704616 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; elnode-proxy.el -- proxying with elnode -*- lexical-binding: t -*- | |
| (require 's) | |
| (require 'web) | |
| (defun elnode/web->elnode-hdr (hdr httpcon) | |
| (apply | |
| 'elnode-http-start | |
| httpcon 200 | |
| (mapcar | |
| (lambda (hdr-pair) | |
| (cons (symbol-name (car hdr-pair)) | |
| (cdr hdr-pair))) | |
| (kvhash->alist hdr)))) | |
| (defun elnode-make-proxy (url) | |
| (lambda (httpcon) | |
| (let* ((method (elnode-http-method httpcon)) | |
| (path (elnode-http-pathinfo httpcon)) | |
| (params (web-to-query-string | |
| (elnode-http-params httpcon))) | |
| (params-alist (list (cons "path" path) | |
| (cons "params" params))) | |
| (web-url (s-format url 'aget params-alist)) | |
| hdr-sent) | |
| (process-put | |
| httpcon | |
| :elnode-child-process | |
| (web-http-call | |
| method | |
| (lambda (httpc hdr data) | |
| (unless hdr-sent | |
| (elnode/web->elnode-hdr hdr httpcon) | |
| (setq hdr/sent t)) | |
| (if (eq data :done) | |
| (elnode-http-return httpcon) | |
| (elnode-http-send-string httpcon data))) | |
| :mode 'stream | |
| :url web-url))))) | |
| (elnode-start | |
| (elnode-make-proxy "http://localhost:8090${path}") | |
| :port 8091) | |
| ;;; elnode-proxy.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment