-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaccept-specializer.lisp
53 lines (48 loc) · 1.58 KB
/
accept-specializer.lisp
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
;;;; accept-specializer.lisp --- accept specializer examples.
;;;;
;;;; Copyright (C) 2013, 2014 Christophe Rhodes,
;;;;
;;;; Author: Christophe Rhodes <[email protected]>
(cl:defpackage #:accept-specializer.example
(:use
#:cl
#:accept-specializer))
(cl:in-package #:accept-specializer.example)
(eval-when (:compile-toplevel :load-toplevel :execute)
(defgeneric respond (request)
(:generic-function-class accept-generic-function)
(:method-combination list)))
(defmethod respond list (request)
t)
(defmethod respond list ((s string))
'string)
(defmethod respond list ((s (accept "text/html")))
"text/html")
(defmethod respond list ((s (accept "audio/mp3")))
"audio/mp3")
(eval-when (:compile-toplevel :load-toplevel :execute)
(defgeneric cn-test (request)
(:generic-function-class accept-generic-function)
(:method-combination content-negotiation)))
(defmethod cn-test ((request (accept "text/html")))
'html)
(defmethod cn-test ((request (accept "text/plain")))
'plain)
(defmethod cn-test ((request (accept "image/webp")))
'webp)
(defmethod cn-test ((request (accept "audio/mp3")))
(call-next-method)
'mp3)
(defmethod cn-test :after (request)
(print 'after))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defgeneric cn/or-test (request)
(:generic-function-class accept-generic-function)
(:method-combination content-negotiation/or)))
(defmethod cn/or-test or ((request (accept "audio/mp3")))
'mp3)
(defmethod cn/or-test or ((request (accept "image/webp")))
'webp)
(defmethod cn/or-test :around ((request t))
(print :around)
(call-next-method))