summaryrefslogtreecommitdiff
path: root/lisp/url/url-util.el
diff options
context:
space:
mode:
authorPeder O. Klingenberg <peder@klingenberg.no>2018-04-13 15:08:18 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2018-04-13 15:08:18 +0200
commit9822a6a5708227897432f47d3f676c646b7bd4b2 (patch)
tree1d7a79656a69a35b1ec3a5165e66dcecbab69066 /lisp/url/url-util.el
parentfa416937997a113d84ab4e4910d730ce5d77613d (diff)
downloademacs-9822a6a5708227897432f47d3f676c646b7bd4b2.tar.gz
Change gnutls-verify-error to be first-match
* doc/misc/url.texi (Customization): Describe the new user option url-lastloc-privacy-level. * lisp/net/eww.el (eww-render): Set url-current-lastloc to the url we are rendering, to get the referer header right on subsequent requests. * lisp/url/url-http.el (url-http--get-referer): New function to determine which referer to send, if any, considering the users privacy settings and the target url we are visiting. (url-http-referer): New variable keeping track of the referer computed by url-http--get-referer (url-http-create-request): Use url-http-referer instead of the optional argument to set up the referer header. Leave checking of privacy settings to url-http--get-referer. (url-http): Set up url-http-referer by using url-http--get-referer. * lisp/url/url-queue.el (url-queue): New struct member context-buffer for keeping track of the context a queued job started from. (url-queue-retrieve): Store the current buffer in the queue object. (url-queue-start-retrieve): Make sure url-retrieve is called in the context of the original buffer, if available. * lisp/url/url-util.el (url-domain): New function to determine the domain of a given URL. * lisp/url/url-vars.el (url-current-lastloc): New variable to keep track of the desired "last location" (referer header). (url-lastloc-privacy-level): New custom setting for more fine-grained control over how lastloc (referer) is sent to servers (Bug#27012).
Diffstat (limited to 'lisp/url/url-util.el')
-rw-r--r--lisp/url/url-util.el29
1 files changed, 29 insertions, 0 deletions
diff --git a/lisp/url/url-util.el b/lisp/url/url-util.el
index 85bfb65cb68..77e015068a3 100644
--- a/lisp/url/url-util.el
+++ b/lisp/url/url-util.el
@@ -627,6 +627,35 @@ Creates FILE and its parent directories if they do not exist."
(error "Danger: `%s' is a symbolic link" file))
(set-file-modes file #o0600))))
+(autoload 'dns-query "dns")
+
+(defvar url--domain-cache (make-hash-table :test 'equal :size 17)
+ "Cache to minimize dns lookups.")
+
+;;;###autoload
+(defun url-domain (url)
+ "Return the domain of the host of the url, or nil if url does
+not contain a registered name."
+ ;; Determining the domain of a name can not be done with simple
+ ;; textual manipulations. a.b.c is either host a in domain b.c
+ ;; (www.google.com), or domain a.b.c with no separate host
+ ;; (bbc.co.uk). Instead of guessing based on tld (which in any case
+ ;; may be inaccurate in the face of subdelegations), we look for
+ ;; domain delegations in DNS.
+ ;;
+ ;; Domain delegations change rarely enough that we won't bother with
+ ;; cache invalidation, I think.
+ (let* ((host-parts (split-string (url-host url) "\\."))
+ (result (gethash host-parts url--domain-cache 'not-found)))
+ (when (eq result 'not-found)
+ (setq result
+ (cl-loop for parts on host-parts
+ for dom = (mapconcat #'identity parts ".")
+ when (dns-query dom 'SOA)
+ return dom))
+ (puthash host-parts result url--domain-cache))
+ result))
+
(provide 'url-util)
;;; url-util.el ends here