Browse Source

fix: wrangle mtypes for conditional HTML hacking

See https://git.vvvvvvaria.org/decentral1se/mist-connections/issues/4.
main
decentral1se 2 months ago
parent
commit
6757c8e828
No known key found for this signature in database GPG Key ID: 3789458B3D0C410
  1. 7
      go.mod
  2. 9
      go.sum
  3. 17
      mist-connections.go

7
go.mod

@ -2,4 +2,9 @@ module varia.zone/mist-connections
go 1.18
require github.com/elazarl/go-bindata-assetfs v1.0.1
require (
github.com/elazarl/go-bindata-assetfs v1.0.1
github.com/gabriel-vasile/mimetype v1.4.0
)
require golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 // indirect

9
go.sum

@ -1,2 +1,11 @@
github.com/elazarl/go-bindata-assetfs v1.0.1 h1:m0kkaHRKEu7tUIUFVwhGGGYClXvyl4RE03qmvRTNfbw=
github.com/elazarl/go-bindata-assetfs v1.0.1/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/gabriel-vasile/mimetype v1.4.0 h1:Cn9dkdYsMIu56tGho+fqzh7XmvY2YyGU0FnbhiOsEro=
github.com/gabriel-vasile/mimetype v1.4.0/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmxRtOJlERCzSmRvr8=
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125 h1:Ugb8sMTWuWRC3+sz5WeN/4kejDx9BvIwnPUiJBjJE+8=
golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

17
mist-connections.go

@ -18,6 +18,7 @@ import (
"sync"
"time"
"github.com/gabriel-vasile/mimetype"
"varia.zone/mist-connections/assets"
)
@ -289,9 +290,21 @@ func fileServe(conf *config) {
var handler http.HandlerFunc
handler = func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(topHTML))
r.Header.Del("If-Modified-Since") // squash cache
fpath := filepath.Join(conf.SharePath, r.RequestURI)
mtype, _ := mimetype.DetectFile(fpath)
renderHTML := mtype.String() == "application/octet-stream"
if renderHTML {
w.Write([]byte(topHTML))
}
fs.ServeHTTP(w, r)
w.Write([]byte(bottomHTML))
if renderHTML {
w.Write([]byte(bottomHTML))
}
}
address := fmt.Sprintf("0.0.0.0:%v", conf.IndexPagePort)

Loading…
Cancel
Save