Pārlūkot izejas kodu

fasthttp: removed 'charset=utf-8' from plaintext response header, since it isn't required there

Aliaksandr Valialkin 9 gadi atpakaļ
vecāks
revīzija
1f8e4f0739

+ 4 - 9
frameworks/Go/fasthttp-mysql/server.go

@@ -40,14 +40,8 @@ var (
 	worldSelectStmt   *sql.Stmt
 	worldUpdateStmt   *sql.Stmt
 	fortuneSelectStmt *sql.Stmt
-)
-
-const helloWorldString = "Hello, World!"
 
-var (
 	db *sql.DB
-
-	helloWorldBytes = []byte(helloWorldString)
 )
 
 var (
@@ -80,7 +74,7 @@ func main() {
 
 	s := &fasthttp.Server{
 		Handler: mainHandler,
-		Name:    "fasthttp",
+		Name:    "go",
 	}
 	ln := getListener()
 	if err = s.Serve(ln); err != nil {
@@ -111,7 +105,7 @@ func mainHandler(ctx *fasthttp.RequestCtx) {
 // Test 1: JSON serialization
 func jsonHandler(ctx *fasthttp.RequestCtx) {
 	r := jsonResponsePool.Get().(*JSONResponse)
-	r.Message = helloWorldString
+	r.Message = "Hello, World!"
 	jsonMarshal(ctx, r)
 	jsonResponsePool.Put(r)
 }
@@ -198,7 +192,8 @@ func updateHandler(ctx *fasthttp.RequestCtx) {
 
 // Test 6: Plaintext
 func plaintextHandler(ctx *fasthttp.RequestCtx) {
-	ctx.Write(helloWorldBytes)
+	ctx.SetContentType("text/plain")
+	ctx.WriteString("Hello, World!")
 }
 
 func jsonMarshal(ctx *fasthttp.RequestCtx, v interface{}) {

+ 4 - 9
frameworks/Go/fasthttp-postgresql/server.go

@@ -39,14 +39,8 @@ var (
 	worldSelectStmt   *pgx.PreparedStatement
 	worldUpdateStmt   *pgx.PreparedStatement
 	fortuneSelectStmt *pgx.PreparedStatement
-)
-
-const helloWorldString = "Hello, World!"
 
-var (
 	db *pgx.ConnPool
-
-	helloWorldBytes = []byte(helloWorldString)
 )
 
 var (
@@ -71,7 +65,7 @@ func main() {
 
 	s := &fasthttp.Server{
 		Handler: mainHandler,
-		Name:    "fasthttp",
+		Name:    "go",
 	}
 	ln := getListener()
 	if err = s.Serve(ln); err != nil {
@@ -102,7 +96,7 @@ func mainHandler(ctx *fasthttp.RequestCtx) {
 // Test 1: JSON serialization
 func jsonHandler(ctx *fasthttp.RequestCtx) {
 	r := jsonResponsePool.Get().(*JSONResponse)
-	r.Message = helloWorldString
+	r.Message = "Hello, World!"
 	jsonMarshal(ctx, r)
 	jsonResponsePool.Put(r)
 }
@@ -189,7 +183,8 @@ func updateHandler(ctx *fasthttp.RequestCtx) {
 
 // Test 6: Plaintext
 func plaintextHandler(ctx *fasthttp.RequestCtx) {
-	ctx.Write(helloWorldBytes)
+	ctx.SetContentType("text/plain")
+	ctx.WriteString("Hello, World!")
 }
 
 func jsonMarshal(ctx *fasthttp.RequestCtx, v interface{}) {