comparison lisp/url/url-http.el @ 73600:fe1f7fc1d1d6

(url-http-create-request): Use buffer-locale equivalents of dynamically bound variables.
author Magnus Henoch <mange@freemail.hu>
date Wed, 01 Nov 2006 15:16:22 +0000
parents a4f1d5ea6dee
children 064fe7ff7747
comparison
equal deleted inserted replaced
73599:65d9fbabd719 73600:fe1f7fc1d1d6
149 (concat " (" (or url-system-type url-os-type) ")")) 149 (concat " (" (or url-system-type url-os-type) ")"))
150 (t ""))))) 150 (t "")))))
151 151
152 (defun url-http-create-request (url &optional ref-url) 152 (defun url-http-create-request (url &optional ref-url)
153 "Create an HTTP request for URL, referred to by REF-URL." 153 "Create an HTTP request for URL, referred to by REF-URL."
154 (declare (special proxy-object proxy-info)) 154 (declare (special proxy-object proxy-info
155 url-http-method url-http-data
156 url-http-extra-headers))
155 (let* ((extra-headers) 157 (let* ((extra-headers)
156 (request nil) 158 (request nil)
157 (no-cache (cdr-safe (assoc "Pragma" url-request-extra-headers))) 159 (no-cache (cdr-safe (assoc "Pragma" url-http-extra-headers)))
158 (proxy-obj (and (boundp 'proxy-object) proxy-object)) 160 (proxy-obj (and (boundp 'proxy-object) proxy-object))
159 (proxy-auth (if (or (cdr-safe (assoc "Proxy-Authorization" 161 (proxy-auth (if (or (cdr-safe (assoc "Proxy-Authorization"
160 url-request-extra-headers)) 162 url-http-extra-headers))
161 (not proxy-obj)) 163 (not proxy-obj))
162 nil 164 nil
163 (let ((url-basic-auth-storage 165 (let ((url-basic-auth-storage
164 'url-http-proxy-basic-auth-storage)) 166 'url-http-proxy-basic-auth-storage))
165 (url-get-authentication url nil 'any nil)))) 167 (url-get-authentication url nil 'any nil))))
166 (real-fname (concat (url-filename (or proxy-obj url)) 168 (real-fname (concat (url-filename (or proxy-obj url))
167 (url-recreate-url-attributes (or proxy-obj url)))) 169 (url-recreate-url-attributes (or proxy-obj url))))
168 (host (url-host (or proxy-obj url))) 170 (host (url-host (or proxy-obj url)))
169 (auth (if (cdr-safe (assoc "Authorization" url-request-extra-headers)) 171 (auth (if (cdr-safe (assoc "Authorization" url-http-extra-headers))
170 nil 172 nil
171 (url-get-authentication (or 173 (url-get-authentication (or
172 (and (boundp 'proxy-info) 174 (and (boundp 'proxy-info)
173 proxy-info) 175 proxy-info)
174 url) nil 'any nil)))) 176 url) nil 'any nil))))
189 (if (or (memq url-privacy-level '(low high paranoid)) 191 (if (or (memq url-privacy-level '(low high paranoid))
190 (and (listp url-privacy-level) 192 (and (listp url-privacy-level)
191 (memq 'lastloc url-privacy-level))) 193 (memq 'lastloc url-privacy-level)))
192 (setq ref-url nil)) 194 (setq ref-url nil))
193 195
194 ;; url-request-extra-headers contains an assoc-list of 196 ;; url-http-extra-headers contains an assoc-list of
195 ;; header/value pairs that we need to put into the request. 197 ;; header/value pairs that we need to put into the request.
196 (setq extra-headers (mapconcat 198 (setq extra-headers (mapconcat
197 (lambda (x) 199 (lambda (x)
198 (concat (car x) ": " (cdr x))) 200 (concat (car x) ": " (cdr x)))
199 url-request-extra-headers "\r\n")) 201 url-http-extra-headers "\r\n"))
200 (if (not (equal extra-headers "")) 202 (if (not (equal extra-headers ""))
201 (setq extra-headers (concat extra-headers "\r\n"))) 203 (setq extra-headers (concat extra-headers "\r\n")))
202 204
203 ;; This was done with a call to `format'. Concatting parts has 205 ;; This was done with a call to `format'. Concatting parts has
204 ;; the advantage of keeping the parts of each header together and 206 ;; the advantage of keeping the parts of each header together and
217 ;; of the strings contains a multibyte char. 219 ;; of the strings contains a multibyte char.
218 'string-as-unibyte 220 'string-as-unibyte
219 (delq nil 221 (delq nil
220 (list 222 (list
221 ;; The request 223 ;; The request
222 (or url-request-method "GET") " " 224 (or url-http-method "GET") " "
223 (if proxy-obj (url-recreate-url proxy-obj) real-fname) 225 (if proxy-obj (url-recreate-url proxy-obj) real-fname)
224 " HTTP/" url-http-version "\r\n" 226 " HTTP/" url-http-version "\r\n"
225 ;; Version of MIME we speak 227 ;; Version of MIME we speak
226 "MIME-Version: 1.0\r\n" 228 "MIME-Version: 1.0\r\n"
227 ;; (maybe) Try to keep the connection open 229 ;; (maybe) Try to keep the connection open
265 ;; Cookies 267 ;; Cookies
266 (url-cookie-generate-header-lines host real-fname 268 (url-cookie-generate-header-lines host real-fname
267 (equal "https" (url-type url))) 269 (equal "https" (url-type url)))
268 ;; If-modified-since 270 ;; If-modified-since
269 (if (and (not no-cache) 271 (if (and (not no-cache)
270 (member url-request-method '("GET" nil))) 272 (member url-http-method '("GET" nil)))
271 (let ((tm (url-is-cached (or proxy-obj url)))) 273 (let ((tm (url-is-cached (or proxy-obj url))))
272 (if tm 274 (if tm
273 (concat "If-modified-since: " 275 (concat "If-modified-since: "
274 (url-get-normalized-date tm) "\r\n")))) 276 (url-get-normalized-date tm) "\r\n"))))
275 ;; Whence we came 277 ;; Whence we came
276 (if ref-url (concat 278 (if ref-url (concat
277 "Referer: " ref-url "\r\n")) 279 "Referer: " ref-url "\r\n"))
278 extra-headers 280 extra-headers
279 ;; Length of data 281 ;; Length of data
280 (if url-request-data 282 (if url-http-data
281 (concat 283 (concat
282 "Content-length: " (number-to-string 284 "Content-length: " (number-to-string
283 (length url-request-data)) 285 (length url-http-data))
284 "\r\n")) 286 "\r\n"))
285 ;; End request 287 ;; End request
286 "\r\n" 288 "\r\n"
287 ;; Any data 289 ;; Any data
288 url-request-data)) 290 url-http-data))
289 "")) 291 ""))
290 (url-http-debug "Request is: \n%s" request) 292 (url-http-debug "Request is: \n%s" request)
291 request)) 293 request))
292 294
293 ;; Parsing routines 295 ;; Parsing routines