Skip to content

Commit 4a561e9

Browse files
committed
Add encodingHTML
1 parent 412c76b commit 4a561e9

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

cmd/erised/serverUtil.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,9 @@ const (
1515
encodingJSON
1616
encodingXML
1717
encodingGZIP
18+
encodingHTML
1819
)
1920

20-
func encoding(code string) (int, string, string) {
21-
switch code {
22-
case "json":
23-
return encodingJSON, "application/json", "identity"
24-
case "xml":
25-
return encodingXML, "application/xml", "identity"
26-
case "gzip":
27-
return encodingGZIP, "application/octet-stream", "gzip"
28-
default:
29-
return encodingTEXT, "text/plain", "identity"
30-
}
31-
}
32-
3321
func httpStatusCode(code string) int {
3422
switch code {
3523
case "MultipleChoices", "300":
@@ -93,6 +81,21 @@ func httpStatusCode(code string) int {
9381
}
9482
}
9583

84+
func encoding(code string) (int, string, string) {
85+
switch code {
86+
case "json":
87+
return encodingJSON, "application/json", ""
88+
case "xml":
89+
return encodingXML, "application/xml", ""
90+
case "gzip":
91+
return encodingGZIP, "application/octet-stream", "gzip"
92+
case "html":
93+
return encodingHTML, "text/html", ""
94+
default:
95+
return encodingTEXT, "text/plain", ""
96+
}
97+
}
98+
9699
func (s *server) respond(res http.ResponseWriter, encoding int, delay time.Duration, data interface{}) {
97100
log.Debug().Msg("entering respond")
98101

@@ -106,7 +109,7 @@ func (s *server) respond(res http.ResponseWriter, encoding int, delay time.Durat
106109
}
107110

108111
switch encoding {
109-
case encodingTEXT, encodingJSON, encodingXML:
112+
case encodingTEXT, encodingJSON, encodingXML, encodingHTML:
110113
if _, err := io.WriteString(res, fmt.Sprintf("%v", data)); err != nil {
111114
log.Error().Msg(err.Error())
112115
}

0 commit comments

Comments
 (0)