window7下karma 報 The header content contains invalid characters BUG

打開你的依賴node_modules\karma\node_modules\connect\lib\patch.jshtml

將裏面的setHeader方法改爲下面這樣,幹掉序列化日期時出現的中文node

  res.setHeader = function(field, val){
    var key = field.toLowerCase()
      , prev;

    // special-case Set-Cookie
    if (key === 'set-cookie') {
      // detect code doing getHeader -> setHeader
      if (Array.isArray(val) && val.length > 1) {
        prev = [].concat(this.getHeader(field) || []);
        val = unique(prev, val);
      }

      return this.appendHeader(field, val);
    }

    // charset
    if ('content-type' == key && this.charset) {
      val = utils.setCharset(val, this.charset, true);
    }
    try{
        if(typeof  val === 'string'){
          val =  val.replace(/中國標準時間/,'')
        }
        return setHeader.call(this, field, val);
    }catch(e){
      console.log(e, val,field)
    }
  };

 

出處:https://www.cnblogs.com/rubylouvre/p/6127190.html?utm_source=tuicool&utm_medium=referralruby

相關文章
相關標籤/搜索