Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/backend/echo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Simple echo server for esp testing.

Node.js implementation of echo server.
74 changes: 74 additions & 0 deletions test/backend/echo/echo.js
Original file line number Diff line number Diff line change
@@ -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);
});
22 changes: 22 additions & 0 deletions test/backend/echo/package.json
Original file line number Diff line number Diff line change
@@ -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"
]
}