Overview
| Comment: | Move http module related code to http directory |
|---|---|
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
a9718f9d0e7ba7d6979a0b474763dd43 |
| User & Date: | w96k on 2025-08-03 12:37:31 |
| Other Links: | manifest | tags | edit |
Context
|
2025-08-03
| ||
| 12:40 | Move http module related code to http directory check-in: 6b29a7ff19 user: w96k tags: trunk | |
| 12:37 | Move http module related code to http directory check-in: a9718f9d0e user: w96k tags: trunk | |
| 12:34 | Fix newlines in README check-in: 78426e9593 user: w96k tags: trunk | |
Changes
Added http/elisp-http-make-content.el version [5d2c78ee84].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
;;(load "~/glibc/dark_c/emacs-symfony-cli/http-content.el")
;;;(global-set-key (kbd "M-m") #'(lambda () (interactive) (elisp-http-login-content)))
(setq http-token "")
(defun elisp-http-get-header ()
(if-let* ((auth-header (unless (or (null http-token)
(string= http-token ""))
(list (cons "Authorization" (concat "Bearer " http-token)))))
(headers (append
'(("Host" . "localhost:8080")
("Accept" . "*/*")
("Content-Type" . "application/json"))
auth-header)))
headers
))
(setq my-headers
(or (elisp-http-get-header)
'(("Host" . "localhost:8080")
("Accept" . "*/*")
("Content-Type" . "application/json"))))
(defun elisp-http-register-line ()
(let* ((_path (elisp-http-prompt-api))
(path (format "POST /%s HTTP/1.1" _path)))
path))
(defun elisp-http-get-line ()
(let* ((_path (elisp-http-prompt-api))
(path (format "GET /%s HTTP/1.1" _path)))
path))
;;;(elisp-http-register-line)
(defun elisp-http-make-content ()
(let ((request-line (elisp-http-set-request-line)))
(concat
request-line "\n"
(mapconcat (lambda (x)
(format "%s: %s" (car x) (cdr x)))
my-headers
"\n"))))
;;;(elisp-http-make-content)
(defun elisp-http-register-content ()
"Generate HTTP request content for registration with JSON payload."
(let* ((email (elisp-http-prompt-email))
(password (elisp-http-prompt-password))
(request-line (elisp-http-register-line))
(json-body (json-encode `(("email" . ,email) ("password" . ,password))))
(headers (append my-headers
(list (cons "Content-Length"
(number-to-string (string-bytes json-body))))))
(header-block
(mapconcat (lambda (x) (format "%s: %s" (car x) (cdr x)))
headers
"\n")))
(concat request-line "\n"
header-block "\n\n"
json-body)))
;; Пример использования:
;;;(elisp-http-register-content)
(defun elisp-http-login-content ()
"Generate HTTP request content for login with JSON payload using 'email'."
(let* ((email (elisp-http-prompt-email))
(password (elisp-http-prompt-password))
(request-line (format "POST /%s HTTP/1.1" (elisp-http-prompt-api)))
(json-body (json-encode `(("email" . ,email) ("password" . ,password))))
(headers (append my-headers
(list (cons "Content-Length"
(number-to-string (string-bytes json-body))))))
(header-block
(mapconcat (lambda (x) (format "%s: %s" (car x) (cdr x)))
headers
"\n")))
(concat request-line "\n"
header-block "\n\n"
json-body)))
;;;(elisp-http-login-content)
;;;(setq youo (elisp-http-login-content))
;;; "email": "somex@gmail.com",
;;; "password": "test1234"
|
Added http/elisp-http-prompt.el version [3c51eb34e7].
> > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 |
(defun elisp-http-prompt-api ()
(let* ((prompt-api (propertize "апи: " 'face '(:foreground "cyan" :weight bold))))
(read-from-minibuffer prompt-api)))
(defun elisp-http-prompt-email ()
(let* ((prompt-register (propertize "email: " 'face '(:foreground "cyan" :weight bold))))
(read-from-minibuffer prompt-register)))
(defun elisp-http-prompt-password ()
(let* ((prompt-register (propertize "password: " 'face '(:foreground "red" :weight bold))))
(read-from-minibuffer prompt-register)))
|
Added http/elisp-http-style.el version [1f67a1e622].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
;;; styles.el --- Summary
;;; Commentary:
;; Brief description of the file.
;;; Code:
(defface tetramorf-style-face
;;;cosmic face
'((t (:foreground "purple"
:background "black"
:weight ultra-bold
:height 2.0
:slant italic
:underline nil
:box (:line-width 1 :color "blue violet")
:family "Courier New")))
"Инферно стиль с элементами темной эстетики.")
(defface aldebaran-metal-face
'((t (:foreground "silver"
:background "black"
:weight ultra-bold
:height 2.0
:slant normal
:underline t
:box (:line-width 2 :color "gray30" :style released-button)
:family "Consolas")))
"Металлический стиль с ощущением силы и мощи.")
(defface info-poetry-face
'((t (:foreground "lavender"
:background "midnight blue"
:weight light
:height 1.8
:slant italic
:underline t
:box (:line-width 1 :color "thistle4" :style released-button)
:family "Georgia")))
"Поэтический стиль с оттенками ночного неба и загадочности.")
(defface info-poetry-face-1
'((t (:foreground "lavender"
:background "midnight blue"
:weight light
:height 1.3
:slant italic
:underline t
:box (:line-width 1 :color "thistle4" :style released-button)
:family "Georgia")))
"Поэтический стиль с оттенками ночного неба и загадочности.")
(defface xxxface
'((((class color) (min-colors 88) (background light))
:background "darkseagreen2")
(((class color) (min-colors 88) (background dark))
:background "darkolivegreen")
(((class color) (min-colors 16) (background light))
:background "darkseagreen2")
(((class color) (min-colors 16) (background dark))
:background "darkolivegreen")
(((class color) (min-colors 8))
:background "green" :foreground "black")
(t :inverse-video t))
"Basic face for highlighting."
:group 'basic-faces)
(defface evil-error-face
'((t (:foreground "firebrick1"
:background "black"
:weight bold
:slant normal
:underline t
:inverse-video t
:box (:line-width 2 :color "dark red" :style released-button)
:height 2.0
:family "Monospace")))
"Зловещий стиль для отображения ошибок.")
(defface cyberpunk-success-face
'((t (:foreground "lime"
:background "black"
:weight bold
:slant normal
:underline t
:box (:line-width 2 :color "cyan" :style solid)
:height 2.5
:family "Courier New")))
"Киберпанковский стиль для успешных сообщений.")
(defface cyberpunk-unsuccess-face
'((t (:foreground "red"
:background "black"
:weight bold
:slant normal
:underline t
:box (:line-width 2 :color "cyan" :style solid)
:height 2.5
:family "Courier New")))
"Киберпанковский стиль для успешных сообщений.")
(defface cyberpunk-last-value-face
'((t (:foreground "lime"
:background "black"
:weight bold
:slant italic
:box (:line-width 3 :color "lime" :style released-button)
:height 2.4
:family "Courier New")))
"Cyberpunk style for displaying the last value.")
(provide 'styles)
;;; styles.el ends here
;;; styles.el --- Summary
|
Added http/elisp-http.el version [af6086a51c].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
(load "~/glibc/dark_c/emacs-symfony-cli/http-content.el")
(load "~/glibc/dark_c/emacs-symfony-cli/elisp-http-style.el")
(load "~/glibc/dark_c/emacs-symfony-cli/elisp-http-prompt.el")
;;;;(global-set-key (kbd "M-m") #'(lambda () (interactive) (elisp-http) (monitor-http-buffer)))
;;(setq http-content (elisp-http-register-content))
;;(setq http-content (elisp-http-make-content))
;;(setq http-content (elisp-http-login-content))
http-content
(defun elisp-http ()
(interactive)
(make-network-process
:name "elisp-post"
:host "localhost"
:service 8080
:buffer "*X*"
:nowait t
:filter (lambda (process-name output-data)
(with-current-buffer (process-buffer process-name)
(unless (bound-and-true-p already-scaled)
(setq-local already-scaled t)
(text-scale-increase 4))
(goto-char (point-max))
(insert output-data)))
:sentinel (lambda (proc event)
(when (string= event "open\n")
(process-send-string
proc
http-content
)))))
(defvar monitor-http-buffer--timer nil)
(defun monitor-http-buffer ()
(setq monitor-http-buffer--timer
(run-at-time 1 1
(lambda ()
(let ((buf (get-buffer "*X*")))
(when (and (buffer-live-p buf)
(> (buffer-size buf) 0))
(psysho-log "[ELISP-HTTP] Пришли данные. Смотрим...")
(display-buffer buf)
(when (timerp monitor-http-buffer--timer)
(cancel-timer monitor-http-buffer--timer))))))))
|
Added http/http-content.el version [58a24b869d].
> > | 1 2 | (defvar http-content "GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n" "содержание http") |
Added http/issue version [55775d9a02].
> > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | цель написать клиента наподобие постмана чтобы этот клиент мог забирать php bin/console debug:router --format=json > routes.json вот такой файл и сразу пользоваться. плюс из базы брать юзера. тут же консольно брать токен. и все чтобы очень удобно было | Событие `event` | Значение | | ------------------------------- | ------------------------------------------------- | | `"open\n"` | Успешное соединение (для клиента при `:nowait t`) | | `"failed with code N\n"` | Ошибка соединения, `N` — код errno | | `"connection broken by peer\n"` | Сервер внезапно закрыл соединение | | `"closed\n"` | Соединение закрыто (обычно после получения всего) | | `"deleted\n"` | Процесс был удалён | | `"exit N\n"` | Процесс завершился с кодом `N` | | `"signal SIG\n"` | Процесс получил сигнал | задача - передать токен пользователя в пост запрос проверить на авторизации пост запрос итак вся суть это формирование контента давай сначала зарегаюсь через кли просто |
Added http/scratch.el version [2566e4cda3].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
(defvar monitor-http-buffer--timer nil
"Таймер для мониторинга буфера *X*.")
(defun monitor-http-buffer ()
(setq monitor-http-buffer--timer
(run-at-time 1 1
(lambda ()
(let ((buf (get-buffer "*X*")))
(when (and (buffer-live-p buf)
(> (with-current-buffer buf
(- (point-max) (point-min)))
0))
(psysho-log "[MONITOR] Буфер *X* заполнен, открываю...")
(display-buffer buf)
(when monitor-http-buffer--timer
(cancel-timer monitor-http-buffer--timer)
(setq monitor-http-buffer--timer nil))))))))
(defun monitor-http-buffer ()
(run-at-time 1 1
(lambda ()
(let ((buf (get-buffer "*X*")))
(when (and (buffer-live-p buf)
(> (with-current-buffer buf
(- (point-max) (point-min)))
0))
(psysho-log "[MONITOR] Буфер *X* заполнен, открываю...")
(display-buffer buf)
(cancel-function-timers 'monitor-http-buffer))))))
psysho-log - это то же что и message но с моими шрифтами
я хочу monitor-http-buffer чтобы прекращалась после показа буффер - соообщение только один раз
выходило чтоб
в елисп емакс проверить что буффер - существует и что там есть контент
(with-current-buffer "*X*" (- (point-max) (point-min)))
где буффер X - это вывод http запроса - runtime-at - надо использовать и вот так мониторить буду
есть ли в емакс возможности реагировать на события кроме таймера?
;;(process-send-string "tcp-client" "GET / HTTP/1.1\r\nHost: gnu.org\r\n\r\n")
;;(start-process "x1" "*xxxxx*" "/root/glibc/dark_c/sfirot" "")
;;(get-process "x1")
;;(set-process-sentinel (get-process "x1")
;; (lambda (proc event)
;; (psysho-log "Process %s message: %s" proc event)))
;;(print (copy-sequence timer-list))
;;;(mapc #'cancel-timer timer-list)
(defun my-buffer-change-fn (beg end len)
(message "Buffer changed from %d to %d (replaced %d chars)" beg end len))
(add-hook 'after-change-functions #'my-buffer-change-fn)
(defun my-watch-buffer (beg end len)
(when (string= (buffer-name) "*X*")
(message "*X* was modified")))
(add-hook 'after-change-functions #'my-watch-buffer)
(defun my-monitor-buffer-change (beg end len)
(when (> (- (point-max) (point-min)) 0)
(psysho-log "[HOOK] Буфер *X* получил данные, открываю...")
(display-buffer (current-buffer))
;; Удаляем хук, чтобы сработал только один раз
(remove-hook 'after-change-functions #'my-monitor-buffer-change t)))
(with-current-buffer "*X*"
(add-hook 'after-change-functions #'my-monitor-buffer-change nil t))
|