"use strict";var NodeHTTPParser=require("http-parser-js").HTTPParser,VERSION=process.version.match(/[0-9]+/g).map(function(e){return parseInt(e,10)}),TYPES={request:NodeHTTPParser.REQUEST||"request",response:NodeHTTPParser.RESPONSE||"response"},HttpParser=function(e){this._type=e,this._parser=new NodeHTTPParser(TYPES[e]),this._complete=!1,this.headers={};var r=null,t=this;this._parser.onHeaderField=function(e,t,s){r=e.toString("utf8",t,t+s).toLowerCase()},this._parser.onHeaderValue=function(e,s,a){var o=e.toString("utf8",s,s+a);t.headers.hasOwnProperty(r)?t.headers[r]+=", "+o:t.headers[r]=o},this._parser.onHeadersComplete=this._parser[NodeHTTPParser.kOnHeadersComplete]=function(e,r,s,a,o,E){var p=arguments[0];if("object"==typeof p&&(a=p.method,o=p.url,E=p.statusCode,s=p.headers),t.method="number"==typeof a?HttpParser.METHODS[a]:a,t.statusCode=E,t.url=o,s){for(var P,H,T=0,O=s.length;T<O;T+=2)P=s[T].toLowerCase(),H=s[T+1],t.headers.hasOwnProperty(P)?t.headers[P]+=", "+H:t.headers[P]=H;t._complete=!0}}};HttpParser.METHODS={0:"DELETE",1:"GET",2:"HEAD",3:"POST",4:"PUT",5:"CONNECT",6:"OPTIONS",7:"TRACE",8:"COPY",9:"LOCK",10:"MKCOL",11:"MOVE",12:"PROPFIND",13:"PROPPATCH",14:"SEARCH",15:"UNLOCK",16:"BIND",17:"REBIND",18:"UNBIND",19:"ACL",20:"REPORT",21:"MKACTIVITY",22:"CHECKOUT",23:"MERGE",24:"M-SEARCH",25:"NOTIFY",26:"SUBSCRIBE",27:"UNSUBSCRIBE",28:"PATCH",29:"PURGE",30:"MKCALENDAR",31:"LINK",32:"UNLINK"},0===VERSION[0]&&12===VERSION[1]&&(HttpParser.METHODS[16]="REPORT",HttpParser.METHODS[17]="MKACTIVITY",HttpParser.METHODS[18]="CHECKOUT",HttpParser.METHODS[19]="MERGE",HttpParser.METHODS[20]="M-SEARCH",HttpParser.METHODS[21]="NOTIFY",HttpParser.METHODS[22]="SUBSCRIBE",HttpParser.METHODS[23]="UNSUBSCRIBE",HttpParser.METHODS[24]="PATCH",HttpParser.METHODS[25]="PURGE"),HttpParser.prototype.isComplete=function(){return this._complete},HttpParser.prototype.parse=function(e){var r=this._parser.execute(e,0,e.length);if("number"!=typeof r)return this.error=r,void(this._complete=!0);0===VERSION[0]&&VERSION[1]<6&&(r+=1),this._complete&&(this.body=r<e.length?e.slice(r):new Buffer(0))},module.exports=HttpParser;