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 new file mode 100644 index 00000000000..b1d0028f1c8 --- /dev/null +++ b/test/backend/echo/echo.js @@ -0,0 +1,74 @@ +// Copyright 2016 Google Inc. All Rights Reserved. +// +// 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 +// +// 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. +// +//////////////////////////////////////////////////////////////////////////////// +// +// An example implementation of Echo backend. + +"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..38bf8b4d3a3 --- /dev/null +++ b/test/backend/echo/package.json @@ -0,0 +1,22 @@ +{ + "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/istio/proxy" + }, + "license": "Apache-2.0", + "engines" : { + "node" : ">=4.1.2" + }, + "files": [ + "README.md", + "echo.js" + ] +}