Initial Commit
[packages] / xemacs-packages / w3 / contrib / http-tunnel.el
1 (defvar http-tunnel-host "firewallmachine")
2 (defvar http-tunnel-port 80)
3
4 (defun open-http-tunneled-connection (name buffer host service)
5   (let ((proc (open-network-stream name buffer http-tunnel-host http-tunnel-port))
6         (need-to-spin t))
7     (if (or (null proc) (not (memq (process-status proc) '(run open))))
8         (error "Could not open connection"))
9     (process-send-string proc (format (eval-when-compile
10                                         (concat
11                                          "CONNECT %s:%s HTTP/1.0\r\n"
12                                          "User-Agent: Emacs/%d.%d\r\n"
13                                          "\r\n"))
14                                       host service
15                                       emacs-major-version
16                                       emacs-minor-version))
17     (save-excursion
18       (set-buffer buffer)
19       (while (and (memq (process-status proc) '(open run)) need-to-spin)
20         (accept-process-output proc 3)
21         (goto-char (point-min))
22         (if (re-search-forward "\r\n\r\n" nil t)
23             (progn
24               (delete-region (point-min) (match-end 0))
25               (setq need-to-spin nil)))
26         (goto-char (point-max))))
27     (if (not (memq (process-status proc) '(open run)))
28         (error "Could not open connection"))
29     proc))
30
31 (let ((socks-noproxy '(".*")))
32   (setq x (open-http-tunneled-connection "x" "x" "www.cs.indiana.edu" 80))
33   (process-send-string x "GET / HTTP/1.0\r\n\r\n"))