Browse Source

Fix falcore benchmark (#2270)

fixes #2269
INADA Naoki 9 years ago
parent
commit
d1780c03e6
1 changed files with 7 additions and 9 deletions
  1. 7 9
      frameworks/Go/falcore/src/framework_benchmarks/falcore.go

+ 7 - 9
frameworks/Go/falcore/src/framework_benchmarks/falcore.go

@@ -148,14 +148,10 @@ var requiredHeaders = falcore.NewResponseFilter(func(req *falcore.Request, res *
 	res.Header.Set("Date", time.Now().Format(time.RFC1123))
 })
 
-var applicationJson = http.Header{"Content-Type": []string{"application/json"}}
-var textPlain = http.Header{"Content-Type": []string{"text/plain"}}
-var textHtml = http.Header{"Content-Type": []string{"text/html"}}
-
 // Test 1: JSON serialization
 var jsonFilter = falcore.NewRequestFilter(func(req *falcore.Request) *http.Response {
 	if req.HttpRequest.URL.Path == "/json" {
-		resp, _ := responder.JSONResponse(req.HttpRequest, 200, applicationJson, &Message{helloWorldString})
+		resp, _ := responder.JSONResponse(req.HttpRequest, 200, nil, &Message{helloWorldString})
 		return resp
 	}
 	return nil
@@ -170,7 +166,7 @@ var dbFilter = falcore.NewRequestFilter(func(req *falcore.Request) *http.Respons
 			log.Fatalf("Error scanning world row: %s", err.Error())
 		}
 
-		resp, _ := responder.JSONResponse(req.HttpRequest, 200, applicationJson, &world)
+		resp, _ := responder.JSONResponse(req.HttpRequest, 200, nil, &world)
 		return resp
 	}
 	return nil
@@ -204,7 +200,7 @@ var queriesFilter = falcore.NewRequestFilter(func(req *falcore.Request) *http.Re
 				log.Fatalf("Error scanning world row: %s", err.Error())
 			}
 		}
-		resp, _ := responder.JSONResponse(req.HttpRequest, 200, applicationJson, &world)
+		resp, _ := responder.JSONResponse(req.HttpRequest, 200, nil, &world)
 		return resp
 	}
 	return nil
@@ -236,6 +232,7 @@ var fortuneFilter = falcore.NewRequestFilter(func(req *falcore.Request) *http.Re
 			pipeWriter.Close()
 		}()
 
+		textHtml := http.Header{"Content-Type": []string{"text/html"}}
 		return falcore.SimpleResponse(req.HttpRequest, 200, textHtml, -1, pipeReader)
 	}
 	return nil
@@ -254,7 +251,7 @@ var updateFilter = falcore.NewRequestFilter(func(req *falcore.Request) *http.Res
 			worldStatement.QueryRow(rand.Intn(worldRowCount)+1).Scan(&world.Id, &world.RandomNumber)
 			world.RandomNumber = uint16(rand.Intn(worldRowCount) + 1)
 			updateStatement.Exec(world.RandomNumber, world.Id)
-			resp, _ := responder.JSONResponse(req.HttpRequest, 200, applicationJson, &world)
+			resp, _ := responder.JSONResponse(req.HttpRequest, 200, nil, &world)
 			return resp
 		} else {
 			world := make([]World, n)
@@ -267,7 +264,7 @@ var updateFilter = falcore.NewRequestFilter(func(req *falcore.Request) *http.Res
 					log.Fatalf("Error updating world row: %s", err.Error())
 				}
 			}
-			resp, _ := responder.JSONResponse(req.HttpRequest, 200, applicationJson, world)
+			resp, _ := responder.JSONResponse(req.HttpRequest, 200, nil, world)
 			return resp
 		}
 
@@ -278,6 +275,7 @@ var updateFilter = falcore.NewRequestFilter(func(req *falcore.Request) *http.Res
 // Test 6: Plaintext
 var plaintextFilter = falcore.NewRequestFilter(func(req *falcore.Request) *http.Response {
 	if req.HttpRequest.URL.Path == "/plaintext" {
+		textPlain := http.Header{"Content-Type": []string{"text/plain"}}
 		return falcore.ByteResponse(req.HttpRequest, 200, textPlain, helloWorldBytes)
 	}
 	return nil