Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http server issue #87

Closed
xr opened this issue Oct 31, 2014 · 1 comment
Closed

http server issue #87

xr opened this issue Oct 31, 2014 · 1 comment

Comments

@xr
Copy link

xr commented Oct 31, 2014

The official answer is

var http = require('http');
var through = require('through');

var server = http.createServer(function (req, res) {
    if (req.method === 'POST') {
        req.pipe(through(function (buf) {
            this.queue(buf.toString().toUpperCase());
        })).pipe(res);
    }
    else res.end('send me a POST\n');
});
server.listen(parseInt(process.argv[2]));

which could pass the http server task. but if I separate the through function like:
var tr = through(write).. like the following code.

var http = require('http');
var through = require('through');
var tr = through(function (buf) {
    this.queue(buf.toString().toUpperCase());
});
var server = http.createServer(function (req, res) {
    if (req.method === 'POST') {
        req.pipe(tr).pipe(res);
    }
    else res.end('send me a POST\n');
});
server.listen(parseInt(process.argv[2]));

It failed, give me the error like:

ACTUAL                             EXPECTED
------                             --------
"ON"                               "ON"                          
"THEM"                             "THEM"                        
"ON"                           !== "BUT,"                        
"THEM"                         !== "MASTER"                      
"BUT,"                         !== "OF"                          
"MASTER"                       !== "BUT,"                        
"OF"                           !== "MASTER"                      
"BUT,"                         !== "OF"                          
"MASTER"                       !== "SNAKES,"                     
"OF"                           !== "WE"                          
"SNAKES,"                          "SNAKES,"                     
"WE"                           !== "CAN"                         
"SNAKES,"                      !== "WE"                          
"CAN"                              "CAN"                         
"WE"                           !== "SLOUGHCHANGE"                
"CAN"                          !== "IN"                          
"SLOUGHCHANGE"                     "SLOUGHCHANGE"                
"IN"                           !== "THE"                         
"SLOUGHCHANGE"                 !== "IN"                          
"THE"                          !== "NIP"                         
"IN"                           !== "THE"                         
"NIP"                          !== "OF"                          
"THE"                          !== "NIP"                         
"OF"                           !== "A"                           
"NIP"                          !== "OF"                          
"A"                            !== "NAPPLE"                      
"OF"                           !== "A"                           
"NAPPLE"                       !== "SOLONGAS"                    
"A"                            !== "NAPPLE"                      
"SOLONGAS"                     !== "WE"                          
"NAPPLE"                       !== "SOLONGAS"                    
"WE"                           !== "CAN"                         
"SOLONGAS"                     !== "WE"                          
"CAN"                          !== "ALLSEE"                      
"WE"                           !== "CAN"                         
"ALLSEE"                       !== "FOR"                         
"CAN"                          !== "ALLSEE"                      
"FOR"                          !== ""                            
""                             !== null                          
# FAIL

Could anybody tell me why?

@xr
Copy link
Author

xr commented Oct 31, 2014

I think the solution is here. no bother nodeschool/discussions#124 (comment)

@xr xr closed this as completed Oct 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant