超文本咖啡壶控制协议(英文:Hyper Text Coffee Pot Control Protocol,HTCPCP)是一种用于控制、监测和诊断咖啡壶的协议。
这个协议在文档RFC
2324[1](发布于1998年4月1日)中被定义。尽管互联网国际标准机构经常在4月1日发布一些恶搞之作,他们还是让这个协议看上去像是一个真的、
非虚构的协议(比如HTTP)。文本编辑器Emacs甚至完全兼容于这个协议,Mozilla也发布了数个补丁来扩展旗下产品的功能。Mosaic浏览器
可能支持此协议。[2]
HTCPCP是HTTP协议的扩展。HTCPCP请求通过URI架构coffee:来引用,并且还包含了若干种HTTP请求:
* BREW或POST:令HTCPCP服务器(咖啡壶)煮咖啡。
* GET:从服务器获取咖啡。
* PROPFIND:获取咖啡的元数据。
* WHEN:让服务器停止向咖啡中加入牛奶(如适用),即英文"say when"之意。
这个协议还定义了两种错误答复:
* 406 Not Acceptable(不能接受的):HTCPCP服务器由于某种原因而暂时不能煮咖啡。服务器在回复中应当包含一组可接受的咖啡类型列表。
* 418 I'm a teapot(我是茶壶):HTCPCP服务器是一个茶壶。這個錯誤答複可能是由一個又矮又胖的東西發出的。
emacs通过htcpcp协议煮咖啡的lisp:
;;; coffee.el --- Submit a BREW request to an RFC2324-compliant coffee device
;;;
;;; Author: Eric Marsden
;;; Version: 0.2
;;; Copyright: (C) 1999 Eric Marsden
;;; Keywords: coffee, brew, kitchen-sink, can't
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public
;; License along with this program; if not, write to the Free
;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.
;;
;; Please send suggestions and bug reports to .
;; The latest version of this package should be available at
;;
;;
;;; Commentary:
;;
;; This module provides an Emacs interface to RFC2324-compliant coffee
;; devices (Hyper Text Coffee Pot Control Protocol, or HTCPCP). It
;; prompts the user for the different additives, then issues a BREW
;; request to the coffee device.
;;
;; coffee.el requires a special BREW-capable version of Emacs/W3 to be
;; installed.
;;
;; Reference:
;;
;;
;; Thanks to Giacomo Boffi for some typos
;; and the addition of the "Brown-Coffee" sweetener type.
;;; Code:
(require 'cl)
(defvar coffee-host "coffee"
"*The host which provides the coffee service.")
(defvar coffee-pot-designator 1
"*On machines with multiple pots, the number of the pot to brew in")
(defvar coffee-brew-hook nil
"*Hook executed before issuing a BREW request")
(defconst coffee-milk-types
'("Cream" "Half-and-Half" "Whole-Milk" "Part-Skim" "Skim" "Non-Dairy"))
(defconst coffee-syrup-types '("Vanilla" "Almond" "Raspberry" "Chocolate"))
(defconst coffee-sweetener-types '("White-Sugar" "Brown-Sugar" "Artificial-Sweetener"))
(defconst coffee-alcohol-types '("Whiskey" "Rum" "Kahula" "Aquavit"))
(defconst coffee-addition-types
`(("Milk" . ,coffee-milk-types)
("Syrup" . ,coffee-syrup-types)
("Sweetener" . ,coffee-sweetener-types)
("Alcohol" . ,coffee-alcohol-types)))
;;;###autoload
(defun coffee ()
"Submit a BREW request to an RFC2324-compliant coffee device"
(interactive)
(require 'url)
(let* ((additions-list
(append coffee-milk-types
coffee-syrup-types
coffee-sweetener-types
coffee-alcohol-types))
(additions-string
(mapconcat #'identity additions-list ","))
(url (coffee-url))
(url-request-method "BREW")
(url-request-extra-headers
`(("Content-type" . "message-coffeepot")
("Accept-Additions" . ,additions-string)))
(url-request-data "START"))
(run-hooks 'coffee-brew-hook)
(url-retrieve url)))
(defun coffee-additions ()
(let* ((type-name
(completing-read "Coffee addition: " coffee-addition-types nil t))
(type (cdr (assoc type-name coffee-addition-types)))
(ingredients (mapcar #'(lambda (a) (cons a a)) type))
(ingredient
(completing-read "Addition type: " ingredients nil t)))
ingredient))
(defun coffee-url ()
(require 'w3-forms)
(concat "coffee://" coffee-host "/"
(int-to-string coffee-pot-designator)
"?" (w3-form-encode-xwfu (coffee-additions))))
(provide 'coffee)
;; coffee.el ends here
阅读(2087) | 评论(0) | 转发(0) |