Function: verb--request-spec-send

verb--request-spec-send is a byte-compiled function defined in verb.el.

Signature

(verb--request-spec-send &rest ARGS)

Implementations

(verb--request-spec-send (RS verb-request-spec) WHERE) in `verb.el'.

Send the HTTP request described by RS. Show the results according to argument WHERE (see `verb-send-request-on-point'). Return the buffer the response will be loaded into.

Source Code

;; Defined in /nix/store/8jnfn8w2mxcxbr2crbklcnija9m0zlkq-emacs-packages-deps/share/emacs/site-lisp/elpa/verb-20260818.1921/verb.el
(cl-defmethod verb--request-spec-send ((rs verb-request-spec) where)
  "Send the HTTP request described by RS.
Show the results according to argument WHERE (see
`verb-send-request-on-point').  Return the buffer the response will be
loaded into."
  ;; If auto kill buffers is enabled, kill all previous response
  ;; buffers now.
  (when verb-auto-kill-response-buffers
    (verb-kill-all-response-buffers t))

  (let* ((url (oref rs url))
         (url-string (verb-request-spec-url-to-string rs))
         (url-request-method (verb--to-ascii (oref rs method)))
         (url-mime-accept-string (verb--get-accept-header (oref rs headers)))
         (url-request-extra-headers (verb--prepare-http-headers
                                     (oref rs headers)))
         (content-type (verb--headers-content-type
                        url-request-extra-headers))
         (url-request-data (verb--encode-http-body (oref rs body)
                                                   (cdr content-type)))
         (num (setq verb--requests-count (1+ verb--requests-count)))
         (start-time (time-to-seconds))
         (response-buf (verb--generate-response-buffer num))
         timeout-timer)
    ;; Start the timeout warning timer.
    (when verb-show-timeout-warning
      (setq timeout-timer (run-with-timer verb-show-timeout-warning nil
                                          #'verb--timeout-warn
                                          response-buf rs num)))

    (verb--setup-request-environment rs)

    ;; Look for headers that might get duplicated by url.el.
    (dolist (h verb--url-pre-defined-headers)
      (when (assoc-string h url-request-extra-headers t)
        (verb-util--log num 'W (concat "Header \"%s\" will appear duplicated "
                                       "in the request, as url.el adds its "
                                       "own version of it")
                        h)))

    ;; Maybe log a warning if body is present but method usually
    ;; doesn't take one (like GET).
    (when (and (member url-request-method verb--bodyless-http-methods)
               url-request-data)
      (verb-util--log num 'W "Body is present but request method is %s"
                      url-request-method))

    ;; Send the request!
    (condition-case err
        (url-retrieve url
                      #'verb--request-spec-callback
                      (list rs
                            response-buf
                            start-time
                            timeout-timer
                            where
                            num)
                      t verb-inhibit-cookies)
      (error (progn
               ;; Cancel timer.
               (when timeout-timer
                 (cancel-timer timeout-timer)
                 (setq timeout-timer nil))
               ;; Kill response buffer.
               (kill-buffer response-buf)

               (verb--teardown-request-environment rs)

               (let ((msg (format "Error sending request: %s" (cadr err))))
                 ;; Log the error.
                 (verb-util--log num 'E msg)
                 ;; Signal it.
                 (user-error "%s" msg)))))

    ;; Show user some quick information.
    (message "%s request sent to %s"
             (oref rs method)
             url-string)

    ;; Log the request.
    (verb-util--log num 'I "%s %s" (oref rs method) url-string)

    (pcase where
      ('other-window (switch-to-buffer-other-window response-buf))
      ('stay-window (save-selected-window
                      (switch-to-buffer-other-window response-buf)))
      ('this-window (switch-to-buffer response-buf)))

    ;; Return the response buffer.
    response-buf))