Copy of github.com/askrobots/network-computer (MIT): a desk you reach from anything. The original lives on GitHub.

2 downloads

Download zip
Clone
Clone with git
git clone https://gitstable.com/git/demo/network-computer.git
HTTPS
https://gitstable.com/git/demo/network-computer.git
SSH
ssh://git@gitstable.com:2222/demo/network-computer.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

GitStable demo README: say this is a copy and where the original is cde82c2 13 hours, 39 minutes ago History
sites.go · 1.6 KB · 49 lines
1package main
2
3import (
4 "net/http"
5 "net/http/httputil"
6 "net/url"
7 "strings"
8)
9
10// sitesProxy serves the object server's published sites (/s/<name>/...) on
11// the desk's public address, so a site made in Webmaster is at
12// https://<desk>/s/<name>. Only /s/, only reading (GET, HEAD); the desk's
13// login cookie and any credentials are removed first, so a site published as
14// not public stays private, and nothing else of the object server is reached.
15// The object server sends the pages sandboxed (CSP), which passes through.
16func sitesProxy(target string) (http.Handler, error) {
17 u, err := url.Parse(target)
18 if err != nil {
19 return nil, err
20 }
21 p := httputil.NewSingleHostReverseProxy(u)
22 base := p.Director
23 p.Director = func(r *http.Request) {
24 base(r)
25 r.Header.Del("Cookie")
26 r.Header.Del("Authorization")
27 r.Header.Del("X-Forwarded-For") // the object server is not told to trust anyone
28 r.Host = u.Host
29 }
30 p.ModifyResponse = func(res *http.Response) error {
31 // a redirect to the object server's own address becomes a path here
32 if loc := res.Header.Get("Location"); strings.HasPrefix(loc, target) {
33 res.Header.Set("Location", strings.TrimPrefix(loc, strings.TrimRight(target, "/")))
34 }
35 res.Header.Del("Set-Cookie")
36 return nil
37 }
38 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
39 if r.Method != http.MethodGet && r.Method != http.MethodHead {
40 http.Error(w, "read only", http.StatusMethodNotAllowed)
41 return
42 }
43 if !strings.HasPrefix(r.URL.Path, "/s/") || strings.Contains(r.URL.Path, "..") {
44 http.NotFound(w, r)
45 return
46 }
47 p.ServeHTTP(w, r)
48 }), nil
49}