diff --git a/exercises/http_json_api_server/problem.md b/exercises/http_json_api_server/problem.md index e87a2376..dd36b757 100644 --- a/exercises/http_json_api_server/problem.md +++ b/exercises/http_json_api_server/problem.md @@ -14,7 +14,7 @@ The JSON response should contain only 'hour', 'minute' and 'second' properties. } ``` -Add second endpoint for the path '/api/unixtime' which accepts the same query string but returns UNIX epoch time in milliseconds (the number of milliseconds since 1 Jan 1970 00:00:00 UTC) under the property 'unixtime'. For example: +Add a second endpoint for the path '/api/unixtime' which accepts the same query string, but returns UNIX epoch time in milliseconds (the number of milliseconds since 1 Jan 1970 00:00:00 UTC) under the property 'unixtime'. For example: ```json { "unixtime": 1376136615474 } @@ -27,7 +27,8 @@ Your server should listen on the port provided by the first argument to your pro The `request` object from an HTTP server has a `url` property that you will need to use to *"route"* your requests for the two endpoints. -You can parse the URL and query string using the Node core 'url' module. `url.parse(request.url, true)` will parse content of request.url and provide you with an object with helpful properties. +You can parse the URL and query string using the Node core 'url' module. +`url.parse(request.url, true)` will parse content of `request.url` and provide you with an object with helpful properties. For example, on the command prompt, type: diff --git a/exercises/http_uppercaserer/exercise.js b/exercises/http_uppercaserer/exercise.js index 69dfc567..151d4d6a 100644 --- a/exercises/http_uppercaserer/exercise.js +++ b/exercises/http_uppercaserer/exercise.js @@ -54,34 +54,43 @@ function query (mode) { function connect (port, stream) { var input = through2() - var count = 0 - var iv var url = 'http://localhost:' + port - var req - - // TODO: test GET requests for #fail - req = input.pipe(hyperquest.post(url) - .on('error', function (err) { - exercise.emit( - 'fail' - , exercise.__('fail.connection', {address: url, message: err.message}) - ) - })) - - req.pipe(stream) - setTimeout(function () { - stream.unpipe(req) - stream.end() - }, 5000) - - iv = setInterval(function () { - input.write(words[count].trim() + '\n') - - if (++count === words.length) { - clearInterval(iv) - input.end() - } - }, 50) + var methods = ['post', 'get'] + + var mi = 0 + var miv = setInterval(function () { + var count = 0 + // test POST request for #success + // or GET request for #fail + var req = input.pipe(hyperquest[methods[mi]](url) + .on('error', function (err) { + exercise.emit( + 'fail' + , exercise.__('fail.connection', {address: url, message: err.message}) + ) + })) + + req.pipe(stream) + setTimeout(function () { + stream.unpipe(req) + if (++mi === methods.length) { + stream.end() + } + }, 3000) + + var iv = setInterval(function () { + input.write(words[count].trim() + '\n') + + if (++count === words.length) { + clearInterval(iv) + + if (++mi === methods.length) { + clearInterval(miv) + input.end() + } + } + }, 50) + }, 600) } connect(this.submissionPort, this.submissionStdout) diff --git a/exercises/http_uppercaserer/problem.es.md b/exercises/http_uppercaserer/problem.es.md index c98a92f4..7959a0f2 100644 --- a/exercises/http_uppercaserer/problem.es.md +++ b/exercises/http_uppercaserer/problem.es.md @@ -1,5 +1,7 @@ Escribe un **servidor** HTTP que reciba sólo peticiones POST y convierta los caracteres del cuerpo de la petición a mayúsculas y lo devuelva al cliente. +Peticiones GET hay que dar les una respuesta vacia. + El servidor deberá escuchar en un puerto cuyo número será el primer argumento del programa. ---------------------------------------------------------------------- diff --git a/exercises/http_uppercaserer/problem.md b/exercises/http_uppercaserer/problem.md index 5e627d1b..364860a3 100644 --- a/exercises/http_uppercaserer/problem.md +++ b/exercises/http_uppercaserer/problem.md @@ -1,5 +1,7 @@ Write an HTTP **server** that receives only POST requests and converts incoming POST body characters to upper-case and returns it to the client. +GET requests have to be answered with an empty response. + Your server should listen on the port provided by the first argument to your program. ---------------------------------------------------------------------- diff --git a/exercises/http_uppercaserer/solution/solution.js b/exercises/http_uppercaserer/solution/solution.js index 02243efa..bb40df93 100644 --- a/exercises/http_uppercaserer/solution/solution.js +++ b/exercises/http_uppercaserer/solution/solution.js @@ -3,7 +3,7 @@ const map = require('through2-map') const server = http.createServer(function (req, res) { if (req.method !== 'POST') { - return res.end('send me a POST\n') + return res.end() } req.pipe(map(function (chunk) { diff --git a/package.json b/package.json index a4104671..f1712ff9 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "through": "^2.3.8", "through2": "^2.0.1", "through2-map": "^3.0.0", - "workshopper-adventure": "^6.0.2", + "workshopper-adventure": "^6.0.3", "workshopper-exercise": "^3.0.1", "workshopper-wrappedexec": "~0.1.1" }, diff --git a/test/http_uppercaserer/valid_01.js b/test/http_uppercaserer/valid_01.js index d8e081f6..f23d4274 100644 --- a/test/http_uppercaserer/valid_01.js +++ b/test/http_uppercaserer/valid_01.js @@ -1,6 +1,6 @@ require('http').createServer(function (req, res) { if (req.method !== 'POST') { - return res.end('POST only!\n') + return res.end() } req.pipe(require('through2-map')(function (chunk) {