Permalink
Browse files

Hardened the headers write

  • Loading branch information...
1 parent 3794ac2 commit f33bc1288464aa2e9ca5102070428ef5737de300 @davglass committed Sep 14, 2011
Showing with 15 additions and 2 deletions.
  1. +15 −2 lib/repl.js
View
@@ -172,14 +172,21 @@ exports.startPrompt = function(Y, YUI) {
on: {
complete: function(id, e) {
self.outputStream.write(' [done]\n'.white);
- self.outputStream.write(' (' + (e.status + '').green + ' ' + e.statusText + '): Content-Type: "' + e.headers['content-type'].green + '"\n\n'.white);
+ var ct = e.headers['content-type'];
+ if (ct) {
+ ct = 'Content-Type: "' + ct.green + '"';
+ } else {
+ ct = '';
+ }
+ self.outputStream.write(' (' + (e.status + '').green + ' ' + e.statusText + '): ' + ct + '\n\n'.white);
var str;
try {
var data = JSON.parse(e.responseText);
self.context.result = data;
str = util.inspect(data, false, Infinity, true);
} catch (e) {
str = e.responseText;
+ self.context.result = str;
}
if (str) {
self.outputStream.write(str);
@@ -204,7 +211,13 @@ exports.startPrompt = function(Y, YUI) {
on: {
complete: function(id, e) {
self.outputStream.write(' [done]\n'.white);
- self.outputStream.write(' (' + (e.status + '').green + ' ' + e.statusText + '): Content-Type: "' + e.headers['content-type'].green + '"\n\n'.white);
+ var ct = e.headers['content-type'];
+ if (ct) {
+ ct = 'Content-Type: "' + ct.green + '"';
+ } else {
+ ct = '';
+ }
+ self.outputStream.write(' (' + (e.status + '').green + ' ' + e.statusText + '): ' + ct + '\n\n'.white);
var str = util.inspect(e.headers, false, Infinity, true);
self.context.result = e.headers;
self.outputStream.write(str);

0 comments on commit f33bc12

Please sign in to comment.