-
Notifications
You must be signed in to change notification settings - Fork 0
/
teapot.go
78 lines (69 loc) · 2.58 KB
/
teapot.go
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
// teapot.go
// Package teapot HTCPCP-TEA implementation.
//
// by David Skinner.
//
// reference
// https://www.ietf.org/rfc/rfc2324.txt
// http://www.rfc-editor.org/rfc/rfc7168.txt
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
// https://en.wikipedia.org/wiki/Hyper_Text_Coffee_Pot_Control_Protocol#Protocol
package teapot
import (
// "bitbucket.org/ww/goautoneg"
"fmt"
"net/http"
)
// Handler reports status error for inappropriate HTCPCP Request.
func Handler(rw http.ResponseWriter, req *http.Request) {
// Implement HTTP/1.1 §14.4 Support.
// myLang := goautoneg.Negotiate(req.Header.Get("Accept-Language"), Langs)
// Implement HTCPCP/1.0 §2.3.2
if req.Header.Get("Content-type") != "message/teapot" {
rw.WriteHeader(http.StatusTeapot)
fmt.Fprintf(rw, "<h1>%s</h1><div>%s</div><e>I am short and stout.<span lang=zh-Hans>短而粗壮</span></e>", req.URL.Host, http.StatusText(http.StatusTeapot))
}
}
/*
the Accept-Additions header field defined in the base HTCPCP specification is updated to allow the following options:
addition-type = ( "*"
| milk-type
| syrup-type
| sweetener-type
| spice-type
| alcohol-type
| sugar-type
) *( ";" parameter )
sugar-type = ( "Sugar" | "Xylitol" | "Stevia" )
*/
// BUG([email protected]) Excessive use of the Sugar addition may cause the BREW request to exceed the segment size allowed by the transport layer, causing fragmentation and a delay in brewing.
var TeaBags = []string{
"/assam",
"/ceylon-tea",
"/darjeeling",
"/earl-grey",
"/lapsang-souchong",
"/peppermint",
"/yunnan",
}
var Langs = map[string]string{
"af": "Ek is kort en geset.",
"sq": "Unë jam i shkurtër dhe i shëndoshë.",
"ar": "أنا قصير وقوي البنية.",
"hy": "Ես կարճ եւ Գեր.",
"az": "Mən qısa və qalın edirəm.",
"eu": "Naiz labur eta Stout.",
"be": "Я коратка і тоўсты.",
"bn": "আমি ছোট এবং স্থুলকায় না.",
"bs": "Ja sam kratko i stout.",
"bg": "Аз съм кратък и як.",
"ca": "Jo sóc baix i robust.",
"ceb": "Ako mao mubo ug magahi.",
"zh": "我是短而粗壮。",
"hr": "Ja sam kratko i krupna.",
"cs": "Já jsem krátký a tlustý.",
"da": "Jeg er kort og stout.",
"nl": "Ik ben kort en stout.",
"en": "I am short and stout.",
}
// TODO Update the stakeholder requirements to resolve requirements that cannot be realized or are impractical to achieve.