consturl=require('url')module.exports=setWarningfunctionsetWarning(reqOrRes,code,message,replace){// Warning = "Warning" ":" 1#warning-value// warning-value = warn-code SP warn-agent SP warn-text [SP warn-date]// warn-code = 3DIGIT// warn-agent = ( host [ ":" port ] ) | pseudonym// ; the name or pseudonym of the server adding// ; the Warning header, for use in debugging// warn-text = quoted-string// warn-date = <"> HTTP-date <">// (https://tools.ietf.org/html/rfc2616#section-14.46)consthost=url.parse(reqOrRes.url).hostconstjsonMessage=JSON.stringify(message)constjsonDate=JSON.stringify(newDate().toUTCString())constheader=replace?'set':'append'reqOrRes.headers[header]('Warning',`${code}${host}${jsonMessage}${jsonDate}`)}