Mercurial > dotfiles
annotate .elisp/http-twiddle.el @ 189:0487f0197755
emacs: disable whitespace-cleanup in makefiles, highlight tabs in makefiles
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Sat, 06 Mar 2010 23:09:39 -0600 |
parents | 35eef880a5ac |
children |
rev | line source |
---|---|
143
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
1 ;;; http-twiddle.el -- send & twiddle & resend HTTP requests |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
2 ;; |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
3 ;; Version 1.0 written by Luke Gorrie <luke@synap.se> in February 2006 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
4 ;; This program belongs to the public domain. |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
5 ;; |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
6 ;; (downloaded from http://fresh.homeunix.net/~luke/misc/emacs/http-twiddle.el) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
7 ;; |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
8 ;; This is a program for testing hand-written HTTP requests. You write |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
9 ;; your request in an Emacs buffer (using http-twiddle-mode) and then |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
10 ;; press `C-c C-c' each time you want to try sending it to the server. |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
11 ;; This way you can interactively debug the requests. To change port or |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
12 ;; destination do `C-u C-c C-c'. |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
13 ;; |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
14 ;; The program is particularly intended for the POST-"500 internal |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
15 ;; server error"-edit-POST loop of integration with SOAP programs. |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
16 ;; |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
17 ;; The mode is activated by `M-x http-twiddle-mode' or automatically |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
18 ;; when opening a filename ending with .http-twiddle. |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
19 ;; |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
20 ;; The request can either be written from scratch or you can paste it |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
21 ;; from a snoop/tcpdump and then twiddle from there. |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
22 ;; |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
23 ;; See the documentation for the `http-twiddle-mode' and |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
24 ;; `http-twiddle-mode-send' functions below for more details and try |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
25 ;; `M-x http-twiddle-mode-demo' for a simple get-started example. |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
26 ;; |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
27 ;; Tested with GNU Emacs 21.4.1 and not tested/ported on XEmacs yet. |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
28 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
29 ;;; Example buffer: |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
30 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
31 ;; POST / HTTP/1.0 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
32 ;; Connection: close |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
33 ;; Content-Length: $Content-Length |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
34 ;; |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
35 ;; The request body goes here |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
36 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
37 (require 'font-lock) ; faces |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
38 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
39 (eval-when-compile |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
40 (unless (fboundp 'define-minor-mode) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
41 (require 'easy-mmode) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
42 (defalias 'define-minor-mode 'easy-mmode-define-minor-mode)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
43 (require 'cl)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
44 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
45 (define-minor-mode http-twiddle-mode |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
46 "Major mode for twiddling around with HTTP requests and sending them. |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
47 Use `http-twiddle-mode-send' (\\[http-twiddle-mode-send]) to send the request." |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
48 nil |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
49 " http-twiddle" |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
50 '(("\C-c\C-c" . http-twiddle-mode-send))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
51 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
52 (defvar http-twiddle-show-request t |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
53 "*Show the request in the transcript.") |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
54 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
55 (add-to-list 'auto-mode-alist '("\\.http-twiddle$" . http-twiddle-mode)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
56 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
57 (defvar http-twiddle-endpoint nil |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
58 "Cache of the (HOST PORT) to send the request to.") |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
59 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
60 (defvar http-twiddle-process nil |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
61 "Socket connected to the webserver.") |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
62 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
63 (defvar http-twiddle-port-history '() |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
64 "History of port arguments entered in the minibuffer. |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
65 \(To make XEmacs happy.)") |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
66 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
67 (defvar http-twiddle-host-history '() |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
68 "History of port arguments entered in the minibuffer. |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
69 \(To make XEmacs happy.)") |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
70 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
71 (defun http-twiddle-mode-send (host port) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
72 "Send the current buffer to the server. |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
73 Linebreaks are automatically converted to CRLF (\\r\\n) format and any |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
74 occurences of \"$Content-Length\" are replaced with the actual content |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
75 length." |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
76 (interactive (http-twiddle-read-endpoint)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
77 ;; close any old connection |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
78 (when http-twiddle-process |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
79 (kill-buffer (process-buffer http-twiddle-process))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
80 (let ((content (buffer-string))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
81 (with-temp-buffer |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
82 (insert content) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
83 (http-twiddle-convert-cr-to-crlf) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
84 (http-twiddle-expand-content-length) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
85 (let ((request (buffer-string))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
86 (setq http-twiddle-process |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
87 (open-network-stream "http-twiddle" "*HTTP Twiddle*" host port)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
88 (set-process-filter http-twiddle-process 'http-twiddle-process-filter) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
89 (set-process-sentinel http-twiddle-process 'http-twiddle-process-sentinel) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
90 (process-send-string http-twiddle-process request) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
91 (save-selected-window |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
92 (pop-to-buffer (process-buffer http-twiddle-process)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
93 (when http-twiddle-show-request |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
94 (insert request) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
95 (set-window-start (selected-window) (point)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
96 (add-text-properties (point-min) (point-max) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
97 '(face font-lock-comment-face))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
98 (set-mark (point))))))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
99 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
100 (defun http-twiddle-read-endpoint () |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
101 "Return the endpoint (HOST PORT) to send the request to." |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
102 (if (and http-twiddle-endpoint (null current-prefix-arg)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
103 http-twiddle-endpoint |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
104 (setq http-twiddle-endpoint |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
105 (list (read-string "Host: (default localhost) " |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
106 nil 'http-twiddle-host-history "localhost") |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
107 (let ((input (read-from-minibuffer "Port: " nil nil t 'http-twiddle-port-history))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
108 (if (integerp input) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
109 input |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
110 (error "Not an integer: %S" input))))))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
111 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
112 (defun http-twiddle-convert-cr-to-crlf () |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
113 "Convert \\n linebreaks to \\r\\n in the whole buffer." |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
114 (save-excursion |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
115 (goto-char (point-min)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
116 (while (re-search-forward "[^\r]\n" nil t) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
117 (backward-char) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
118 (insert "\r")))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
119 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
120 (defun http-twiddle-expand-content-length () |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
121 "Replace any occurences of $Content-Length with the actual Content-Length." |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
122 (save-excursion |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
123 (goto-char (point-min)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
124 (let ((content-length |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
125 (save-excursion (when (search-forward "\r\n\r\n" nil t) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
126 (- (point-max) (point)))))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
127 (unless (null content-length) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
128 (let ((case-fold-search t)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
129 (while (search-forward "$content-length" nil t) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
130 (replace-match (format "%d" content-length) nil t))))))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
131 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
132 (defun http-twiddle-process-filter (process string) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
133 "Process data from the socket by inserting it at the end of the buffer." |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
134 (with-current-buffer (process-buffer process) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
135 (goto-char (point-max)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
136 (insert string))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
137 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
138 (defun http-twiddle-process-sentinel (process what) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
139 (with-current-buffer (process-buffer process) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
140 (goto-char (point-max)) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
141 (let ((start (point))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
142 (insert "Connection closed\n") |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
143 (add-text-properties start (point) '(face font-lock-string-face))))) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
144 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
145 (defun http-twiddle-mode-demo () |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
146 (interactive) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
147 (pop-to-buffer (get-buffer-create "*http-twiddle demo*")) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
148 (http-twiddle-mode 1) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
149 (erase-buffer) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
150 (insert "POST / HTTP/1.0\nContent-Length: $Content-Length\nConnection: close\n\nThis is the POST body.\n") |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
151 (message "Now press `C-c C-c' and enter a webserver address (e.g. google.com port 80).")) |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
152 |
35eef880a5ac
emacs: add http-twiddle for POST debugging
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
153 (provide 'http-twiddle) |