var http=require('http');
var url=require('url');
var util=require('util');
var rssresult= require('./RSS');
var rssArr=[];

var FeedParser=require('feedparser')
	,request=require('request');
var rssPath='http://habrahabr.ru/rss/feed/posts/3579533107158215c7375135d25f59b2/';
var options ={feedurl:'http://habrahabr.ru/rss/feed/posts/3579533107158215c7375135d25f59b2/'};
var req=request(rssPath)
	,feedparser=new FeedParser([options]);
	
	req.on('error',function(error){
		
	}); 
	
req.on('response', function (res) {
  var stream = this;

  if (res.statusCode != 200) return this.emit('error', new Error('Bad status code'));

  stream.pipe(feedparser);
});
feedparser.on('error', function(error) {
  // always handle errors
  console.error(error.message+' '+error.stacktrace);
});
feedparser.on('readable', function() {
  // This is where the action is!
  var stream = this
    , meta = this.meta // **NOTE** the "meta" is always available in the context of the feedparser instance
    , item;
var i=0;
  while (item = stream.read()) {
	rssArr[i]=item;
	i=i+1;
  }
});




var server=new http.Server(function(req,res){
	console.log(req.method,req.url)
	
	var urlParsed=url.parse(req.url,true);
	console.log(urlParsed);
	if(urlParsed.pathname=='/echo' &&urlParsed.query.message)
	{
		res.end(urlParsed.query.message);
	}
	else if(urlParsed.pathname=='/rss' &&urlParsed.query.message)
	{
		options.feedurl=urlParsed.query.message;
		req=request(options.feedurl);		
		req.emit('response',options.feedurl);
		//res.end(util.format("%s",rssresult.title));
		var index;

for	(index = 0; index < rssArr.length; index++) {
   res.write(rssArr[index].title+" "+ rssArr[index].author+" "+rssArr[index].link+
   "<div><p>"+rssArr[index].description+"</p>/div>");
}
res.end();
	}
	else {
		res.statusCode=404;
		res.end("Page not found!")
	}
	
});
server.listen(1337,'127.0.0.1');

@@ -98,24 +98,52 @@
 e('./RSS');%0A
+var utf8 = require('utf8');%0A
 var rssArr=%5B
@@ -1650,16 +1650,28 @@
 s.write(
+utf8.encode(
 rssArr%5Bi
@@ -1685,14 +1685,30 @@
 itle
+)
 +%22 %22
-+ 
+%0A   +utf8.encode(
 rssA
@@ -1727,13 +1727,26 @@
 thor
+)
 +%22 %22+
+utf8.encode(
 rssA
@@ -1813,16 +1813,17 @@
 %3E/div%3E%22)
+)
 ;%0A%7D%0Ares.

include utf8 module