Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Go Httpbin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Nix
Go Httpbin
Commits
fb210c57
Commit
fb210c57
authored
Sep 6, 2016
by
Will McCutchen
Browse files
Options
Downloads
Patches
Plain Diff
Add /encoding/utf8 handler
parent
acd2f0f9
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
handlers.go
+11
-0
11 additions, 0 deletions
handlers.go
handlers_test.go
+13
-0
13 additions, 0 deletions
handlers_test.go
main.go
+1
-0
1 addition, 0 deletions
main.go
templates/utf8.html
+220
-0
220 additions, 0 deletions
templates/utf8.html
with
245 additions
and
0 deletions
handlers.go
+
11
−
0
View file @
fb210c57
...
@@ -28,6 +28,17 @@ func formsPost(w http.ResponseWriter, r *http.Request, t *template.Template) {
...
@@ -28,6 +28,17 @@ func formsPost(w http.ResponseWriter, r *http.Request, t *template.Template) {
t
.
Execute
(
w
,
nil
)
t
.
Execute
(
w
,
nil
)
}
}
// utf8 must be wrapped by withTemplates middleware before it can be used
func
utf8
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
t
*
template
.
Template
)
{
t
=
t
.
Lookup
(
"utf8.html"
)
if
t
==
nil
{
http
.
Error
(
w
,
fmt
.
Sprintf
(
"error looking up index.html"
),
http
.
StatusInternalServerError
)
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
t
.
Execute
(
w
,
nil
)
}
func
get
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
get
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
args
,
err
:=
url
.
ParseQuery
(
r
.
URL
.
RawQuery
)
args
,
err
:=
url
.
ParseQuery
(
r
.
URL
.
RawQuery
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
handlers_test.go
+
13
−
0
View file @
fb210c57
...
@@ -31,6 +31,19 @@ func TestFormsPost(t *testing.T) {
...
@@ -31,6 +31,19 @@ func TestFormsPost(t *testing.T) {
}
}
}
}
func
TestUTF8
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/encoding/utf8"
,
nil
)
w
:=
httptest
.
NewRecorder
()
app
()
.
ServeHTTP
(
w
,
r
)
if
w
.
Header
()
.
Get
(
"Content-Type"
)
!=
"text/html; charset=utf-8"
{
t
.
Fatalf
(
"expected 'text/html; charset=utf-8' content type"
)
}
if
!
strings
.
Contains
(
w
.
Body
.
String
(),
`Hello world, Καλημέρα κόσμε, コンニチハ`
)
{
t
.
Fatalf
(
"expected utf8 text in body"
)
}
}
func
TestGet__Basic
(
t
*
testing
.
T
)
{
func
TestGet__Basic
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/get"
,
nil
)
r
,
_
:=
http
.
NewRequest
(
"GET"
,
"/get"
,
nil
)
r
.
Host
=
"localhost"
r
.
Host
=
"localhost"
...
...
This diff is collapsed.
Click to expand it.
main.go
+
1
−
0
View file @
fb210c57
...
@@ -14,6 +14,7 @@ func app() http.Handler {
...
@@ -14,6 +14,7 @@ func app() http.Handler {
h
.
HandleFunc
(
"/"
,
methods
(
templateWrapper
(
index
),
"GET"
))
h
.
HandleFunc
(
"/"
,
methods
(
templateWrapper
(
index
),
"GET"
))
h
.
HandleFunc
(
"/forms/post"
,
methods
(
templateWrapper
(
formsPost
),
"GET"
))
h
.
HandleFunc
(
"/forms/post"
,
methods
(
templateWrapper
(
formsPost
),
"GET"
))
h
.
HandleFunc
(
"/encoding/utf8"
,
methods
(
templateWrapper
(
utf8
),
"GET"
))
h
.
HandleFunc
(
"/get"
,
methods
(
get
,
"GET"
))
h
.
HandleFunc
(
"/get"
,
methods
(
get
,
"GET"
))
h
.
HandleFunc
(
"/post"
,
methods
(
requestWithBody
,
"POST"
))
h
.
HandleFunc
(
"/post"
,
methods
(
requestWithBody
,
"POST"
))
...
...
This diff is collapsed.
Click to expand it.
templates/utf8.html
0 → 100644
+
220
−
0
View file @
fb210c57
<h1>
Unicode Demo
</h1>
<p>
Taken from
<a
href=
"http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt"
>
http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt
</a></p>
<pre>
UTF-8 encoded sample plain-text file
‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
Markus Kuhn [ˈmaʳkʊs kuːn]
<http:
//
www.cl.cam.ac.uk
/~
mgk25
/>
— 2002-07-25
The ASCII compatible UTF-8 encoding used in this plain-text file
is defined in Unicode, ISO 10646-1, and RFC 2279.
Using Unicode/UTF-8, you can write in emails and source code things such as
Mathematics and sciences:
∮ E⋅da = Q, n → ∞, ∑ f(i) = ∏ g(i), ⎧⎡⎛┌─────┐⎞⎤⎫
⎪⎢⎜│a²+b³ ⎟⎥⎪
∀x∈ℝ: ⌈x⌉ = −⌊−x⌋, α ∧ ¬β = ¬(¬α ∨ β), ⎪⎢⎜│───── ⎟⎥⎪
⎪⎢⎜⎷ c₈ ⎟⎥⎪
ℕ ⊆ ℕ₀ ⊂ ℤ ⊂ ℚ ⊂ ℝ ⊂ ℂ, ⎨⎢⎜ ⎟⎥⎬
⎪⎢⎜ ∞ ⎟⎥⎪
⊥
<
a
≠
b
≡
c
≤
d
≪
⊤
⇒
(⟦
A
⟧
⇔
⟪
B
⟫),
⎪⎢⎜
⎲
⎟⎥⎪
⎪⎢⎜
⎳
aⁱ-bⁱ
⎟⎥⎪
2
H
₂
+
O
₂
⇌
2
H
₂
O
,
R =
4.7
kΩ
,
⌀
200
mm
⎩⎣⎝
i=
1
⎠⎦⎭
Linguistics
and
dictionaries:
ði
ıntəˈnæʃənəl
fəˈnɛtık
əsoʊsiˈeıʃn
Y
[
ˈʏpsilɔn
],
Yen
[
jɛn
],
Yoga
[
ˈjoːgɑ
]
APL:
((
V
⍳
V)=
⍳⍴V)/V←,V
⌷←⍳→⍴∆∇⊃‾⍎⍕⌈
Nicer
typography
in
plain
text
files:
╔══════════════════════════════════════════╗
║
║
║
•
‘
single
’
and
“
double
”
quotes
║
║
║
║
•
Curly
apostrophes:
“
We
’
ve
been
here
”
║
║
║
║
•
Latin-1
apostrophe
and
accents:
'´`
║
║
║
║
•
‚
deutsche
‘
„
Anführungszeichen
“
║
║
║
║
•
†,
‡,
‰,
•,
3–4,
—,
−5/+5,
™,
…
║
║
║
║
•
ASCII
safety
test:
1
lI
|,
0
OD
,
8
B
║
║
╭─────────╮
║
║
•
the
euro
symbol:
│
14.95
€
│
║
║
╰─────────╯
║
╚══════════════════════════════════════════╝
Combining
characters:
STARGΛ̊TE
SG-1
,
a =
v̇
=
r̈
,
a⃑
⊥
b⃑
Greek
(
in
Polytonic
)
:
The
Greek
anthem:
Σὲ
γνωρίζω
ἀπὸ
τὴν
κόψη
τοῦ
σπαθιοῦ
τὴν
τρομερή
,
σὲ
γνωρίζω
ἀπὸ
τὴν
ὄψη
ποὺ
μὲ
βία
μετράει
τὴ
γῆ.
᾿
Απ
᾿
τὰ
κόκκαλα
βγαλμένη
τῶν
῾
Ελλήνων
τὰ
ἱερά
καὶ
σὰν
πρῶτα
ἀνδρειωμένη
χαῖρε
,
ὦ
χαῖρε
,
᾿
Ελευθεριά
!
From
a
speech
of
Demosthenes
in
the
4
th
century
BC:
Οὐχὶ
ταὐτὰ
παρίσταταί
μοι
γιγνώσκειν
,
ὦ
ἄνδρες
᾿
Αθηναῖοι
,
ὅταν
τ
᾿
εἰς
τὰ
πράγματα
ἀποβλέψω
καὶ
ὅταν
πρὸς
τοὺς
λόγους
οὓς
ἀκούω
·
τοὺς
μὲν
γὰρ
λόγους
περὶ
τοῦ
τιμωρήσασθαι
Φίλιππον
ὁρῶ
γιγνομένους
,
τὰ
δὲ
πράγματ
᾿
εἰς
τοῦτο
προήκοντα
,
ὥσθ
᾿
ὅπως
μὴ
πεισόμεθ
᾿
αὐτοὶ
πρότερον
κακῶς
σκέψασθαι
δέον.
οὐδέν
οὖν
ἄλλο
μοι
δοκοῦσιν
οἱ
τὰ
τοιαῦτα
λέγοντες
ἢ
τὴν
ὑπόθεσιν
,
περὶ
ἧς
βουλεύεσθαι
,
οὐχὶ
τὴν
οὖσαν
παριστάντες
ὑμῖν
ἁμαρτάνειν.
ἐγὼ
δέ
,
ὅτι
μέν
ποτ
᾿
ἐξῆν
τῇ
πόλει
καὶ
τὰ
αὑτῆς
ἔχειν
ἀσφαλῶς
καὶ
Φίλιππον
τιμωρήσασθαι
,
καὶ
μάλ
᾿
ἀκριβῶς
οἶδα
·
ἐπ
᾿
ἐμοῦ
γάρ
,
οὐ
πάλαι
γέγονεν
ταῦτ
᾿
ἀμφότερα
·
νῦν
μέντοι
πέπεισμαι
τοῦθ
᾿
ἱκανὸν
προλαβεῖν
ἡμῖν
εἶναι
τὴν
πρώτην
,
ὅπως
τοὺς
συμμάχους
σώσομεν.
ἐὰν
γὰρ
τοῦτο
βεβαίως
ὑπάρξῃ
,
τότε
καὶ
περὶ
τοῦ
τίνα
τιμωρήσεταί
τις
καὶ
ὃν
τρόπον
ἐξέσται
σκοπεῖν
·
πρὶν
δὲ
τὴν
ἀρχὴν
ὀρθῶς
ὑποθέσθαι
,
μάταιον
ἡγοῦμαι
περὶ
τῆς
τελευτῆς
ὁντινοῦν
ποιεῖσθαι
λόγον.
Δημοσθένους
,
Γ
´
᾿
Ολυνθιακὸς
Georgian:
From
a
Unicode
conference
invitation:
გთხოვთ
ახლავე
გაიაროთ
რეგისტრაცია
Unicode-ის
მეათე
საერთაშორისო
კონფერენციაზე
დასასწრებად
,
რომელიც
გაიმართება
10
-12
მარტს
,
ქ.
მაინცში
,
გერმანიაში.
კონფერენცია
შეჰკრებს
ერთად
მსოფლიოს
ექსპერტებს
ისეთ
დარგებში
როგორიცაა
ინტერნეტი
და
Unicode-ი
,
ინტერნაციონალიზაცია
და
ლოკალიზაცია
,
Unicode-ის
გამოყენება
ოპერაციულ
სისტემებსა
,
და
გამოყენებით
პროგრამებში
,
შრიფტებში
,
ტექსტების
დამუშავებასა
და
მრავალენოვან
კომპიუტერულ
სისტემებში.
Russian:
From
a
Unicode
conference
invitation:
Зарегистрируйтесь
сейчас
на
Десятую
Международную
Конференцию
по
Unicode
,
которая
состоится
10
-12
марта
1997
года
в
Майнце
в
Германии.
Конференция
соберет
широкий
круг
экспертов
по
вопросам
глобального
Интернета
и
Unicode
,
локализации
и
интернационализации
,
воплощению
и
применению
Unicode
в
различных
операционных
системах
и
программных
приложениях
,
шрифтах
,
верстке
и
многоязычных
компьютерных
системах.
Thai
(
UCS
Level
2)
:
Excerpt
from
a
poetry
on
The
Romance
of
The
Three
Kingdoms
(
a
Chinese
classic
'
San
Gua
')
:
[
----------------------------
|
------------------------
]
๏
แผ่นดินฮั่นเสื่อมโทรมแสนสังเวช
พระปกเกศกองบู๊กู้ขึ้นใหม่
สิบสองกษัตริย์ก่อนหน้าแลถัดไป
สององค์ไซร้โง่เขลาเบาปัญญา
ทรงนับถือขันทีเป็นที่พึ่ง
บ้านเมืองจึงวิปริตเป็นนักหนา
โฮจิ๋นเรียกทัพทั่วหัวเมืองมา
หมายจะฆ่ามดชั่วตัวสำคัญ
เหมือนขับไสไล่เสือจากเคหา
รับหมาป่าเข้ามาเลยอาสัญ
ฝ่ายอ้องอุ้นยุแยกให้แตกกัน
ใช้สาวนั้นเป็นชนวนชื่นชวนใจ
พลันลิฉุยกุยกีกลับก่อเหตุ
ช่างอาเพศจริงหนาฟ้าร้องไห้
ต้องรบราฆ่าฟันจนบรรลัย
ฤๅหาใครค้ำชูกู้บรรลังก์
ฯ
(
The
above
is
a
two-column
text.
If
combining
characters
are
handled
correctly
,
the
lines
of
the
second
column
should
be
aligned
with
the
|
character
above.
)
Ethiopian:
Proverbs
in
the
Amharic
language:
ሰማይ
አይታረስ
ንጉሥ
አይከሰስ
።
ብላ
ካለኝ
እንደአባቴ
በቆመጠኝ
።
ጌጥ
ያለቤቱ
ቁምጥና
ነው
።
ደሀ
በሕልሙ
ቅቤ
ባይጠጣ
ንጣት
በገደለው
።
የአፍ
ወለምታ
በቅቤ
አይታሽም
።
አይጥ
በበላ
ዳዋ
ተመታ
።
ሲተረጉሙ
ይደረግሙ
።
ቀስ
በቀስ
፥
ዕንቁላል
በእግሩ
ይሄዳል
።
ድር
ቢያብር
አንበሳ
ያስር
።
ሰው
እንደቤቱ
እንጅ
እንደ
ጉረቤቱ
አይተዳደርም
።
እግዜር
የከፈተውን
ጉሮሮ
ሳይዘጋው
አይድርም
።
የጎረቤት
ሌባ
፥
ቢያዩት
ይስቅ
ባያዩት
ያጠልቅ
።
ሥራ
ከመፍታት
ልጄን
ላፋታት
።
ዓባይ
ማደሪያ
የለው
፥
ግንድ
ይዞ
ይዞራል
።
የእስላም
አገሩ
መካ
የአሞራ
አገሩ
ዋርካ
።
ተንጋሎ
ቢተፉ
ተመልሶ
ባፉ
።
ወዳጅህ
ማር
ቢሆን
ጨርስህ
አትላሰው
።
እግርህን
በፍራሽህ
ልክ
ዘርጋ
።
Runes:
ᚻᛖ
ᚳᚹᚫᚦ
ᚦᚫᛏ
ᚻᛖ
ᛒᚢᛞᛖ
ᚩᚾ
ᚦᚫᛗ
ᛚᚪᚾᛞᛖ
ᚾᚩᚱᚦᚹᛖᚪᚱᛞᚢᛗ
ᚹᛁᚦ
ᚦᚪ
ᚹᛖᛥᚫ
(
Old
English
,
which
transcribed
into
Latin
reads
'
He
cwaeth
that
he
bude
thaem
lande
northweardum
with
tha
Westsae.
'
and
means
'
He
said
that
he
lived
in
the
northern
land
near
the
Western
Sea.
')
Braille:
⡌⠁⠧⠑
⠼⠁⠒
⡍⠜⠇⠑⠹⠰⠎
⡣⠕⠌
⡍⠜⠇⠑⠹
⠺⠁⠎
⠙⠑⠁⠙⠒
⠞⠕
⠃⠑⠛⠔
⠺⠊⠹⠲
⡹⠻⠑
⠊⠎
⠝⠕
⠙⠳⠃⠞
⠱⠁⠞⠑⠧⠻
⠁⠃⠳⠞
⠹⠁⠞⠲
⡹⠑
⠗⠑⠛⠊⠌⠻
⠕⠋
⠙⠊⠎
⠃⠥⠗⠊⠁⠇
⠺⠁⠎
⠎⠊⠛⠝⠫
⠃⠹
⠹⠑
⠊⠇⠻⠛⠹⠍⠁⠝⠂
⠹⠑
⠊⠇⠻⠅⠂
⠹⠑
⠥⠝⠙⠻⠞⠁⠅⠻⠂
⠁⠝⠙
⠹⠑
⠡⠊⠑⠋
⠍⠳⠗⠝⠻⠲
⡎⠊⠗⠕⠕⠛⠑
⠎⠊⠛⠝⠫
⠊⠞⠲
⡁⠝⠙
⡎⠊⠗⠕⠕⠛⠑⠰⠎
⠝⠁⠍⠑
⠺⠁⠎
⠛⠕⠕⠙
⠥⠏⠕⠝
⠰⡡⠁⠝⠛⠑⠂
⠋⠕⠗
⠁⠝⠹⠹⠔⠛
⠙⠑
⠡⠕⠎⠑
⠞⠕
⠏⠥⠞
⠙⠊⠎
⠙⠁⠝⠙
⠞⠕⠲
⡕⠇⠙
⡍⠜⠇⠑⠹
⠺⠁⠎
⠁⠎
⠙⠑⠁⠙
⠁⠎
⠁
⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲
⡍⠔⠙⠖
⡊
⠙⠕⠝⠰⠞
⠍⠑⠁⠝
⠞⠕
⠎⠁⠹
⠹⠁⠞
⡊
⠅⠝⠪⠂
⠕⠋
⠍⠹
⠪⠝
⠅⠝⠪⠇⠫⠛⠑⠂
⠱⠁⠞
⠹⠻⠑
⠊⠎
⠏⠜⠞⠊⠊⠥⠇⠜⠇⠹
⠙⠑⠁⠙
⠁⠃⠳⠞
⠁
⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲
⡊
⠍⠊⠣⠞
⠙⠁⠧⠑
⠃⠑⠲
⠔⠊⠇⠔⠫⠂
⠍⠹⠎⠑⠇⠋⠂
⠞⠕
⠗⠑⠛⠜⠙
⠁
⠊⠕⠋⠋⠔⠤⠝⠁⠊⠇
⠁⠎
⠹⠑
⠙⠑⠁⠙⠑⠌
⠏⠊⠑⠊⠑
⠕⠋
⠊⠗⠕⠝⠍⠕⠝⠛⠻⠹
⠔
⠹⠑
⠞⠗⠁⠙⠑⠲
⡃⠥⠞
⠹⠑
⠺⠊⠎⠙⠕⠍
⠕⠋
⠳⠗
⠁⠝⠊⠑⠌⠕⠗⠎
⠊⠎
⠔
⠹⠑
⠎⠊⠍⠊⠇⠑⠆
⠁⠝⠙
⠍⠹
⠥⠝⠙⠁⠇⠇⠪⠫
⠙⠁⠝⠙⠎
⠩⠁⠇⠇
⠝⠕⠞
⠙⠊⠌⠥⠗⠃
⠊⠞⠂
⠕⠗
⠹⠑
⡊⠳⠝⠞⠗⠹⠰⠎
⠙⠕⠝⠑
⠋⠕⠗⠲
⡹⠳
⠺⠊⠇⠇
⠹⠻⠑⠋⠕⠗⠑
⠏⠻⠍⠊⠞
⠍⠑
⠞⠕
⠗⠑⠏⠑⠁⠞⠂
⠑⠍⠏⠙⠁⠞⠊⠊⠁⠇⠇⠹⠂
⠹⠁⠞
⡍⠜⠇⠑⠹
⠺⠁⠎
⠁⠎
⠙⠑⠁⠙
⠁⠎
⠁
⠙⠕⠕⠗⠤⠝⠁⠊⠇⠲
(
The
first
couple
of
paragraphs
of
"
A
Christmas
Carol
"
by
Dickens
)
Compact
font
selection
example
text:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
/0123456789
abcdefghijklmnopqrstuvwxyz
£©
µÀÆÖÞßéöÿ
–—‘“”„†•…‰™
œŠŸž
€
ΑΒΓΔΩαβγδω
АБВГДабвгд
∀∂∈
ℝ
∧∪≡∞
↑↗↨↻⇣
┐┼╔╘░►☺♀
fi
�⑀₂
ἠḂӥẄɐː
⍎
אԱა
Greetings
in
various
languages:
Hello
world
,
Καλημέρα
κόσμε
,
コンニチハ
Box
drawing
alignment
tests:
█
▉
╔══╦══╗
┌──┬──┐
╭──┬──╮
╭──┬──╮
┏━━┳━━┓
┎┒┏┑
╷
╻
┏┯┓
┌┰┐
▊
╱╲╱╲╳╳╳
║┌─╨─┐║
│╔═╧═╗│
│╒═╪═╕│
│╓─╁─╖│
┃┌─╂─┐┃
┗╃╄┙
╶┼╴╺╋╸┠┼┨
┝╋┥
▋
╲╱╲╱╳╳╳
║│╲
╱│║
│║
║│
││
│
││
│║
┃
║│
┃│
╿
│┃
┍╅╆┓
╵
╹
┗┷┛
└┸┘
▌
╱╲╱╲╳╳╳
╠╡
╳
╞╣
├╢
╟┤
├┼─┼─┼┤
├╫─╂─╫┤
┣┿╾┼╼┿┫
┕┛┖┚
┌┄┄┐
╎
┏┅┅┓
┋
▍
╲╱╲╱╳╳╳
║│╱
╲│║
│║
║│
││
│
││
│║
┃
║│
┃│
╽
│┃
░░▒▒▓▓██
┊
┆
╎
╏
┇
┋
▎
║└─╥─┘║
│╚═╤═╝│
│╘═╪═╛│
│╙─╀─╜│
┃└─╂─┘┃
░░▒▒▓▓██
┊
┆
╎
╏
┇
┋
▏
╚══╩══╝
└──┴──┘
╰──┴──╯
╰──┴──╯
┗━━┻━━┛
▗▄▖▛▀▜
└╌╌┘
╎
┗╍╍┛
┋
▁▂▃▄▅▆▇█
▝▀▘▙▄▟
</
pre
>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment