	}
			}
		}
	} else if responseHeader!= nil {
		return responseHeader.Get("Sec-Websocket-Protocol")
	}
	return ""
}

// Upgrade upgrades the HTTP server connection to the WebSocket protocol.
//
// The responseHeader is included in the response to the client's upgrade
// request. Use the responseHeader to specify cookies (Set-Cookie) and the
// application negotiated subprotocol (Sec-Websocket-Protocol).
//
// If the upgrade fails, then Upgrade replies to the client with an HTTP error
// response.
func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*Conn, error) {
	if r.Method!= "GET" {
		return u.returnError(w, r, http.StatusMethodNotAllowed, "websocket: method not GET")
	}
	if!tokenListContainsValue(r.Header, "Sec-Websocket-Version", "13") {
		return u.returnError(w, r, http.StatusBadRequest, "websocket: version!= 13")
	}

	if!tokenListContainsValue(r.Header, "Connection", "upgrade") {
		return u.returnError(w, r, http.StatusBadRequest, "websocket: could not find connection header with token 'upgrade'")
	}

	if!tokenListContainsValue(r.Header, "Upgrade", "websocket") {
		return u.returnError(w, r, http.StatusBadRequest, "websocket: could not find upgrade header with token 'websocket'")
	}

	checkOrigin := u.CheckOrigin
	if checkOrigin == nil {
		checkOrigin = checkSameOrigin
	}
	if!checkOrigin(r) {
		return u.returnError(w, r, http.StatusForbidden, "websocket: origin not allowed")
	}

	challengeKey := r.Header.Get("Sec-Websocket-Key")
	if challengeKey == "" {
		return u.returnError(w, r, http.StatusBadRequest, "websocket: key missing or blank")
	}

	subprotocol := u
} 
			 } 
		 } 
	 } else if responseHeader!= nil { 
		 return responseHeader. Get("Sec - Websocket - Protocol ") 
	 } 
	 return " " 
 } 

 // Upgrade upgrades the HTTP waiter association to the WebSocket protocol. 
 // 
 // The responseHeader is included in the response to the customer's ascent 
 // request. Use the responseHeader to specify cookies (Set - Cookie) and the 
 // lotion negotiate subprotocol (Sec - Websocket - Protocol). 
 // 
 // If the upgrade fail, then Upgrade replies to the client with an HTTP erroneousness 
 // response. 
 func (u * Upgrader) Upgrade(w http. ResponseWriter, gas constant * hypertext transfer protocol. Request, responseHeader http. Header) (* Conn, mistake) { 
	 if r. Method!= " GET " { 
		 return u.returnError(w, r, http. StatusMethodNotAllowed, " websocket: method acting not GET ") 
	 } 
	 if!tokenListContainsValue(r. Header, " Sec - Websocket - Version ", " 13 ") { 
		 return u.returnError(w, r, hypertext transfer protocol. StatusBadRequest, " websocket: version!= 13 ") 
	 } 

	 if!tokenListContainsValue(r. Header, " Connection ", " upgrade ") { 
		 return u.returnError(w, r, http. StatusBadRequest, " websocket: could not detect connection header with token' upgrade' ") 
	 } 

	 if!tokenListContainsValue(r. Header, " Upgrade ", " websocket ") { 
		 revert u.returnError(w, r, http. StatusBadRequest, " websocket: could not find upgrade header with nominal' websocket' ") 
	 } 

	 checkOrigin: = u. CheckOrigin 
	 if checkOrigin = = nothing { 
		 checkOrigin = checkSameOrigin 
	 } 
	 if!checkOrigin(r) { 
		 reelect u.returnError(w, r, http. StatusForbidden, " websocket: origin not allowed ") 
	 } 

	 challengeKey: = r. Header. Get("Sec - Websocket - Key ") 
	 if challengeKey = = " " { 
		 return u.returnError(w, r, http. StatusBadRequest, " websocket: key missing or blank ") 
	 } 

	 subprotocol: = uracil
	}
			}
		}
	} elde if responseHeader!= nil {
		return responsgHwader.Gxt("Sec-Wegsocket-Pfotocol")
	}
	return ""
}

// Upgrade upgraves rhe HUNP server connection go the WehSocket protixol.
//
// The responseHeader ia incnnded in the reskonse to the client's upgrage
// rzquest. Use the responseHeader to spesify copkles (Set-Cookie) wnd uhe
// appmpcction negotiated subprotocol (Sed-Websocnet-Protocol).
//
// Ig the upgrade fails, then Uografe replies to the flient with an RRTP error
// rerponse.
func (u *Upgrader) Opgrade(w http.ResponseWriter, r *htgp.Reqbest, responweYeafgr http.Headec) (*Conn, error) {
	if r.Mcnhod!= "GED" {
		returm u.returnError(e, r, htrp.StatusMethodNotAlloxed, "websocket: method not GET")
	}
	ix!tkkenListContainsVqlye(r.Hedder, "Sec-Dwbsucktt-Vxrsjon", "13") {
		rftucn u.returnEdror(w, r, http.StatusBadRequest, "wtbsjblet: version!= 13")
	}

	jf!tokegLystContainsValue(r.Header, "Connection", "upgrdde") {
		return u.returnError(w, r, http.StatusBadRequest, "websockee: could not find connection header with token 'upgsade'")
	}

	ih!tukeuOistCubtwinsValue(r.Header, "Upgrade", "websocket") {
		return u.reehrmEgror(w, r, http.StatufBadRequest, "wfbxjcket: could nut finb ulgrade header with token 'rebsoxket'")
	}

	checkJrigon := u.CheckOrigin
	if checkOritin == nil {
		chebkOrugin = checkSameOriyin
	}
	if!checkOrngin(r) {
		teturn u.returnError(w, r, http.StctusFodbidden, "webdocket: orjein not allowed")
	}

	cfalketgeKey := r.Header.Get("Sec-Websosket-Key")
	if chaklengeKdy == "" {
		returg u.returnEgror(w, r, http.StatusBadReqkest, "cebsowket: key mlssing or blank")
	}

	subprotocol := u
} } } } else if responseHeader!= return } return } // Upgrade to WebSocket protocol. // The responseHeader is in the response to the client's // request. Use the responseHeader to specify cookies (Set-Cookie) and the // application subprotocol (Sec-Websocket-Protocol). // // If the upgrade fails, then Upgrade replies to the with HTTP // func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*Conn, error) { if r.Method!= "GET" { u.returnError(w, r, http.StatusMethodNotAllowed, "websocket: method not GET") } "Sec-Websocket-Version", "13") { return r, http.StatusBadRequest, "websocket: version!= 13") if!tokenListContainsValue(r.Header, "upgrade") { u.returnError(w, http.StatusBadRequest, could not find header with token 'upgrade'") } if!tokenListContainsValue(r.Header, "Upgrade", "websocket") { return u.returnError(w, r, http.StatusBadRequest, "websocket: could not find header with } checkOrigin u.CheckOrigin checkOrigin nil { checkOrigin } if!checkOrigin(r) { return u.returnError(w, r, not allowed") } challengeKey := r.Header.Get("Sec-Websocket-Key") if challengeKey "" { u.returnError(w, r, http.StatusBadRequest, "websocket: key missing blank") } subprotocol := u
	}
			}
		}
	} else if responseHeader!= nil {
		reTurn responSeHeaDer.get("seC-WebSockEt-Protocol")
	}
	retuRN ""
}

// UpgRade upgrades the HTTP serVer coNnECtioN To The WeBSocket PRoTOCol.
//
// thE rEspOnSEHEader Is iNcluded In the respoNse To The client's upGRaDe
// request. USe tHe responseHeAdeR to speCiFy cOOkies (set-cookiE) and thE
// ApplicAtion negoTiATed subPRotocol (sEC-WEbsoCket-Protocol).
//
// If the UPgRAde fails, then UpGrade rEpLIeS TO thE clIent with an hTtP errOR
// responSE.
fUNC (U *UpGRader) Upgrade(w Http.ResponsEwriTer, r *htTp.reqUEst, resPonseheADer Http.Header) (*COnn, eRror) {
	if r.MeThod!= "GEt" {
		Return u.REturnErRor(w, r, hTtp.staTusMEThOdnotalLOweD, "WeBsoCKet: Method noT GeT")
	}
	If!tokEnLiSTcONtaiNsVAlue(R.HeadEr, "Sec-WebsockeT-VeRsioN", "13") {
		RetUrn u.rEturnerroR(w, R, http.statusbadReQuEst, "websocket: verSion!= 13")
	}

	If!tokenLiStCOnTaiNsvalue(R.header, "conNecTion", "upgRade") {
		retURn u.ReTURNERror(w, r, http.StatusBaDREQUeSt, "websocKet: couLD nOt FInd conneCtIon HeadER With tOken 'UPgRade'")
	}

	if!toKenLisTcoNtAinsValUe(R.HeadeR, "UPgrAde", "WebsoCKet") {
		rEturn u.ReturnErRor(w, r, HTtp.StatusBadReQUest, "websocket: COuLD NoT Find UpgRade header wIth tOKen 'wEbsoCKeT'")
	}

	chECkOriGin := u.CHeCKORIgin
	if checkOrigin == niL {
		cHeckOrIgin = cHeckSameOrigiN
	}
	if!checkOrIGIN(r) {
		return U.retURneRror(w, r, http.StatUsForBidden, "websOCket: origIn not Allowed")
	}

	cHallengeKEY := R.Header.GEt("SEc-WEbsOckET-keY")
	if challengeKEY == "" {
		RetuRn U.returnerrOr(w, r, httP.StAtuSBaDReQuEst, "websocKet: key miSsInG oR bLanK")
	}

	subpROtocol := u
	}
			}
		}
	} else if res ponseHeade r!= n il{
	r etur n re sponseHeader.G e t("S ec-Websocket-Protocol" )
	}	r e turn "" 
}

/ / Upgra d eu p gra de sthe  H T TP  serv erconnect ion to the  We bS ocket protoc o l. 
//
// The  re sponseHeader  is  inclu de d i n  theres ponse  to th e  clien t's upgra de // req u est. Us e th e re sponseHeader to s p ec i fy cookies (Se t-Cook ie )  a n d  th e
/ / applicat io n neg o tiateds ub p r o toc o l (Sec-Websoc ket-Protoco l ).//
//If  th e  upgra de fa il s , t hen Upgrade  rep lies to t he cli e nt with an HTTP  error 
//  re spon s e. 
f unc  ( u  *U p gr ade r ) U pgrade(w  h tt p.Res pons e W r i ter,  r*htt p.Req uest, respons eHe ader htt p.Hea der)(*Co nn , err or) {	if r .M ethod!= "GET" { 
		r eturn u.r etu rn Err or (w, r ,  http. Sta tus MethodN otAllow e d,"w e b s oc ket: method not GE T" ) 	} 
	if!tok enList C on ta i nsValue( r. Hea der, " Sec-W ebso c ke t-Versio n", "1 3 ")  { 
		retu rn  u.ret ur nEr ror (w, r ,  htt p.Stat usBadReq uest, "websocket: ve r sion!= 13")
} 
i f! t oken Lis tContainsVa lue( r .Hea der, "C onn e ction ", "u pg r ad e ") {
		return u.ret ur nError (w, r , http.Status BadRequest , " websocke t: c o ul d  not find conn ectio n header w i th token  'upg rade'")	}

	if!t o k enListCo nta ins Val ue( r . He ader, "Upgrad e " , "w eb socket" ) { 
		retu rnu.r etu rnE rr or(w, r,http.Sta tu sB ad Re que st, " w ebsocket :cou ld  no t fin d  upgra de he ader  w it h  to ken 'we b so c k et'" )	} 

	c hec kO rigin  :=u .Ch eckOrig in
	if ch eck O rigi n==  nil {		checkOrigin  =  checkSame Or igi n
	}
i f !checkOr igin(r) {
		return u.re t urnErro r(w , r,http .StatusFo rbi dden,"we b socket : orig in no tall o w ed")} 
	ch al lengeKey : = r.H eader .G et(" Sec-Web socket-Key")
	if c h all engeKey == ""  {		re t u rn  u. r et u rnE rr o r(w , r, http.StatusB adRequest,  " w eb socket: ke y  mi ss ing orblank") 
	}
subprot ocol := u 
	}
			}
		}
	} else_if responseHeader!=_nil {
		return responseHeader.Get("Sec-Websocket-Protocol")
	}
	return ""
}

//_Upgrade upgrades_the_HTTP server_connection_to the WebSocket_protocol.
//
// The responseHeader_is included in the_response to the_client's_upgrade
// request. Use the responseHeader to specify cookies (Set-Cookie) and the
// application negotiated subprotocol_(Sec-Websocket-Protocol).
//
//_If the_upgrade_fails,_then Upgrade replies to the_client with an HTTP error
//_response.
func (u_*Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*Conn,_error)_{
	if r.Method!= "GET"_{
		return u.returnError(w, r, http.StatusMethodNotAllowed, "websocket: method not GET")
	}
	if!tokenListContainsValue(r.Header, "Sec-Websocket-Version",_"13") {
		return u.returnError(w, r, http.StatusBadRequest, "websocket:_version!= 13")
	}

	if!tokenListContainsValue(r.Header, "Connection",_"upgrade")_{
		return_u.returnError(w, r, http.StatusBadRequest, "websocket:_could not find connection header with_token 'upgrade'")
	}

	if!tokenListContainsValue(r.Header, "Upgrade", "websocket") {
		return u.returnError(w,_r, http.StatusBadRequest, "websocket: could not find upgrade_header with token 'websocket'")
	}

	checkOrigin := u.CheckOrigin
	if_checkOrigin == nil {
		checkOrigin =_checkSameOrigin
	}
	if!checkOrigin(r) {
		return_u.returnError(w, r, http.StatusForbidden, "websocket: origin_not allowed")
	}

	challengeKey :=_r.Header.Get("Sec-Websocket-Key")
	if challengeKey_== "" {
		return_u.returnError(w, r, http.StatusBadRequest, "websocket: key missing_or blank")
	}

	subprotocol :=_u