Repository: gohugoio/hugo (language: go)

Issue:
LiveReload doesn't work in GitHub Codespace
<!-- Please answer these questions before submitting your issue. Thanks! -->

### What version of Hugo are you using (`hugo version`)?

<pre>
$ hugo version
hugo v0.99.1-d524067382e60ce2a2248c3133a1b3af206b6ef1+extended linux/amd64 BuildDate=2022-05-18T11:18:14Z VendorInfo=gohugoio
</pre>

### Does this issue reproduce with the latest release?
Yes

## General Problem description
LiveReload doesn't seem to work in GitHub Codespaces. This seems to be due to the port being appended to the url even when `--appendPort=false` is passed to the cli

<img width="1018" alt="image" src="https://user-images.githubusercontent.com/9759954/170590176-ff7de088-d866-4507-9270-d1978f8ad324.png">




Discussion / hints:
Hmm... I'm pretty sure I have been using in similar settings before ... But "someone" may have broken it.
Never mind, I see it now (at least what the plan was).

* appendPort=false is for `baseURL` only
* Set liveReloadPort=443 (or something) if you're doing some proxy setup.

Let me know if that works for you.
that doesn't work either, here is the repository I'm using: https://github.com/ideacrew/sbm-docs

here are the options I've tried and the errors that I'm getting in the console

`hugo server` => `livereload.js?mindelay=10&v=2&port=1313&path=livereload:1 WebSocket connection to 'wss://markgoho-ideacrew-sbm-docs-779rj57j3pv95-1313.githubpreview.dev:1313/livereload' failed:`

`hugo server --liveReloadPort 443` => `livereload.js?mindelay=10&v=2&port=443&path=livereload:1 WebSocket connection to 'wss://markgoho-ideacrew-sbm-docs-779rj57j3pv95-1313.githubpreview.dev/livereload' failed:`

`hugo server --liveReloadPort 80` => `livereload.js?mindelay=10&v=2&port=80&path=livereload:1 WebSocket connection to 'wss://markgoho-ideacrew-sbm-docs-779rj57j3pv95-1313.githubpreview.dev:80/livereload' failed:`
OK, I don't understand the GitHub Codespaces good enough to tell what/why.
Yeah, I guess there's some similarities with a technology called [GitPod](https://www.gitpod.io/) where folks have found a similar issue but have resolved it with `--bind=0.0.0.0`

It's entirely possible that:
1. there's some combination of server flags that might work, no code change required anywhere
2. however livereload works in Hugo, it won't work in codespaces and a change might be required either in Hugo, codespaces, or livereload (😬)

In either case, I don't think enough people use codespaces (yet!) for this to matter much

thanks for the time you've already put in -- maybe someone else will find this issue and come up with  solution

Fix patch:
diff --git a/livereload/livereload.go b/livereload/livereload.go
index 145cc25ea60..246a7393cea 100644
--- a/livereload/livereload.go
+++ b/livereload/livereload.go
@@ -62,7 +62,13 @@ var upgrader = &websocket.Upgrader{
 			return false
 		}
 
-		if u.Host == r.Host {
+		rHost := r.Host
+		// For Github codespace in browser #9936
+		if forwardedHost := r.Header.Get("X-Forwarded-Host"); forwardedHost != "" {
+			rHost = forwardedHost
+		}
+
+		if u.Host == rHost {
 			return true
 		}
 


Test patch: