window7下karma 報 nodejs request TypeError: The header content contains invalid characters BUG


這個BUG 估計只有中國人才 遇到

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

將里面的setHeader方法改成下面這樣,干掉序列化日期時出現的中文

  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)
    }
  };


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM