From fa1f48129b059ed870e89f549973c25754969e23 Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Thu, 5 Jan 2017 18:37:05 -0800 Subject: [PATCH 1/2] Add echo backend. --- test/backend/echo/echo.js | 84 ++++++++++++++++++++++++++++++++++ test/backend/echo/package.json | 24 ++++++++++ 2 files changed, 108 insertions(+) create mode 100644 test/backend/echo/echo.js create mode 100644 test/backend/echo/package.json diff --git a/test/backend/echo/echo.js b/test/backend/echo/echo.js new file mode 100644 index 00000000000..542d89ed174 --- /dev/null +++ b/test/backend/echo/echo.js @@ -0,0 +1,84 @@ +// Copyright (C) Endpoints Server Proxy Authors +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. +// +//////////////////////////////////////////////////////////////////////////////// +// +// A Google Cloud Endpoints example implementation of a simple bookstore API. + +"use strict"; + +var http = require('http'); +var server = http.createServer(); + +var totalReceived = 0; +var totalData = 0; + +server.on('request', function(req, res) { + totalReceived += 1; + var method = req.method; + var url = req.url; + if (method == 'GET' && url == '/version') { + res.writeHead(200, {"Content-Type": "application/json"}); + res.write('{"version":"${VERSION}"}'); + res.end(); + return; + } + req.on('data', function(chunk) { + totalData += chunk.length; + res.write(chunk); + }) + req.on('end', function() { + res.end(); + }); + + var cl = req.headers['content-length']; + var ct = req.headers['content-type']; + + var headers = {}; + if (cl !== undefined) { + headers['Content-Length'] = cl; + } + if (ct !== undefined) { + headers['Content-Type'] = ct; + } + + res.writeHead(200, headers); + req.resume(); +}); + +var totalConnection = 0; + +server.on('connection', function(socket) { + totalConnection += 1; +}); + +setInterval(function() { + console.log("Requests received:", totalReceived, " Data: ", totalData, " Connection: ", totalConnection); +}, 1000); + +var port = process.env.PORT || 8080; + +server.listen(port, function() { + console.log('Listening on port', port); +}); diff --git a/test/backend/echo/package.json b/test/backend/echo/package.json new file mode 100644 index 00000000000..4eab536a2d9 --- /dev/null +++ b/test/backend/echo/package.json @@ -0,0 +1,24 @@ +{ + "name": "echo", + "version": "8.8.1", + "description": "An echo server.", + "main": "echo.js", + "readme": "README.md", + "scripts": { + "start": "node echo.js" + }, + "repository": { + "type": "git", + "url": "https://github.com/cloudendpoints/esp" + }, + "license": "Apache-2.0", + "engines" : { + "node" : ">=4.1.2" + }, + "files": [ + "README.md", + "echo.js", + "ec.js", + "echo.json" + ] +} From 1cd9e77d66ff8b7a38e3631b328ecd8b17d48d64 Mon Sep 17 00:00:00 2001 From: Wayne Zhang Date: Thu, 5 Jan 2017 18:45:19 -0800 Subject: [PATCH 2/2] Update copyright header. --- test/backend/echo/README.md | 3 +++ test/backend/echo/echo.js | 34 ++++++++++++---------------------- test/backend/echo/package.json | 6 ++---- 3 files changed, 17 insertions(+), 26 deletions(-) create mode 100644 test/backend/echo/README.md diff --git a/test/backend/echo/README.md b/test/backend/echo/README.md new file mode 100644 index 00000000000..b3d4ee11032 --- /dev/null +++ b/test/backend/echo/README.md @@ -0,0 +1,3 @@ +# Simple echo server for esp testing. + +Node.js implementation of echo server. diff --git a/test/backend/echo/echo.js b/test/backend/echo/echo.js index 542d89ed174..b1d0028f1c8 100644 --- a/test/backend/echo/echo.js +++ b/test/backend/echo/echo.js @@ -1,30 +1,20 @@ -// Copyright (C) Endpoints Server Proxy Authors -// All rights reserved. +// Copyright 2016 Google Inc. All Rights Reserved. // -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at // -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -// SUCH DAMAGE. +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. // //////////////////////////////////////////////////////////////////////////////// // -// A Google Cloud Endpoints example implementation of a simple bookstore API. +// An example implementation of Echo backend. "use strict"; diff --git a/test/backend/echo/package.json b/test/backend/echo/package.json index 4eab536a2d9..38bf8b4d3a3 100644 --- a/test/backend/echo/package.json +++ b/test/backend/echo/package.json @@ -9,7 +9,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/cloudendpoints/esp" + "url": "https://github.com/istio/proxy" }, "license": "Apache-2.0", "engines" : { @@ -17,8 +17,6 @@ }, "files": [ "README.md", - "echo.js", - "ec.js", - "echo.json" + "echo.js" ] }