mirror of
https://github.com/supleed2/go-chat.git
synced 2024-12-22 14:15:49 +00:00
Server redirects non-upgrade http requests
This commit is contained in:
parent
d703615f7f
commit
f4afdce578
|
@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Security
|
||||
|
||||
## [0.1.2] - 2024-01-14
|
||||
|
||||
### Changed
|
||||
|
||||
- Server redirects non-upgrade http requests
|
||||
|
||||
## [0.1.1] - 2024-01-14
|
||||
|
||||
### Changed
|
||||
|
@ -39,6 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## Links
|
||||
|
||||
[unreleased]: https://github.com/supleed2/omg-rs/compare/v0.1.1...HEAD
|
||||
[unreleased]: https://github.com/supleed2/omg-rs/compare/v0.1.2...HEAD
|
||||
[0.1.2]: https://github.com/supleed2/omg-rs/releases/tag/v0.1.2
|
||||
[0.1.1]: https://github.com/supleed2/omg-rs/releases/tag/v0.1.1
|
||||
[0.1.0]: https://github.com/supleed2/omg-rs/releases/tag/v0.1.0
|
||||
|
|
|
@ -106,6 +106,11 @@ func run(addr string, nickMap map[string]string, admin string, rhlen int, log *l
|
|||
}
|
||||
|
||||
func (s server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if r.ProtoAtLeast(1, 1) && !hasUpgradeHeader(r.Header) {
|
||||
http.Redirect(w, r, "https://github.com/supleed2/go-chat", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
conn, err := ws.Accept(w, r, nil)
|
||||
if err != nil {
|
||||
|
@ -357,3 +362,16 @@ func alphanumeric(s string) bool {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func hasUpgradeHeader(h http.Header) bool {
|
||||
for _, v := range h["Connection"] {
|
||||
v = strings.TrimSpace(v)
|
||||
for _, t := range strings.Split(v, ",") {
|
||||
t = strings.TrimSpace(t)
|
||||
if strings.EqualFold(t, "Upgrade") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue