Skip to content

Commit

Permalink
don't try to upgrade if the request was made to check if server is av…
Browse files Browse the repository at this point in the history
…ailable, relative to kataras/neffos.js#2
  • Loading branch information
kataras committed Jun 26, 2019
1 parent 0c1fc30 commit 36316a0
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,26 @@ func (s *Server) Upgrade(w http.ResponseWriter, r *http.Request, socketWrapper f
return nil, errInvalidMethod
}

// This header key should match with that browser-client's `whenResourceOnline` uses.
if v := r.Header.Get("X-Websocket-Reconnect"); v != "" {
// If that header exists and it's not empty then it means that it tries to see if the GET resouce is online,
// let's make the error more useful so it can be checked from callers.
//
// Note that this request will fail at the end
// but the caller can ignore logging it as an actual error,
// see the `IsTryingToReconnect` package-level function for more.
err := errUpgradeOnGetRetry{v}
if s.OnUpgradeError != nil {
s.OnUpgradeError(err)
}

return nil, err
}

tryParseURLParamsToHeaders(r)

socket, err := s.upgrader(w, r)
if err != nil {
// This header key should match with that browser-client's `whenResourceOnline` uses.
if v := r.Header.Get("X-Websocket-Reconnect"); v != "" {
// If that header exists and it's not empty then it means that it tries to see if the GET resouce is online,
// let's make the error more useful so it can be checked from callers.
//
// Note that this request will fail at the end
// but the caller can ignore logging it as an actual error,
// see the `IsTryingToReconnect` package-level function for more.
err = errUpgradeOnGetRetry{v}
}

if s.OnUpgradeError != nil {
s.OnUpgradeError(err)
}
Expand Down

0 comments on commit 36316a0

Please sign in to comment.