Skip to content

Commit 762ed8a

Browse files
committed
Minor cleanup thingys
1 parent 0c754cd commit 762ed8a

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

firebase.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (mf FirebaseManifest) processRewrites(r *http.Request) error {
6565
return nil
6666
}
6767

68-
func (mf FirebaseManifest) processHosting(w http.ResponseWriter, r *http.Request) error {
68+
func (mf FirebaseManifest) processHeaders(w http.ResponseWriter, r *http.Request) error {
6969
for _, headerSet := range mf.Headers {
7070
pattern, err := CompileExtGlob(headerSet.Source)
7171
if err != nil {
@@ -78,17 +78,17 @@ func (mf FirebaseManifest) processHosting(w http.ResponseWriter, r *http.Request
7878
}
7979
}
8080
if mf.Hosting != nil {
81-
return mf.Hosting.processHosting(w, r)
81+
return mf.Hosting.processHeaders(w, r)
8282
}
8383
return nil
8484
}
8585

86-
func processWithConfig(w http.ResponseWriter, r *http.Request, config string) string {
86+
func processWithConfig(w http.ResponseWriter, r *http.Request, config string) (string, bool) {
8787
dir := "."
8888
mf, err := readManifest(config)
8989
if err != nil {
9090
log.Printf("Could read Firebase file %s: %s", config, err)
91-
return dir
91+
return dir, false
9292
}
9393
if mf.Public != "" {
9494
dir = mf.Public
@@ -100,28 +100,28 @@ func processWithConfig(w http.ResponseWriter, r *http.Request, config string) st
100100
done, err := mf.processRedirects(w, r)
101101
if err != nil {
102102
log.Printf("Processing redirects failed: %s", err)
103-
return dir
103+
return dir, false
104104
}
105105
if done {
106-
return dir
106+
return dir, true
107107
}
108108

109109
// Rewrites only happen if the target file does not exist
110110
if _, err = os.Stat(filepath.Join(dir, r.URL.Path)); err != nil {
111111
err = mf.processRewrites(r)
112112
if err != nil {
113113
log.Printf("Processing rewrites failed: %s", err)
114-
return dir
114+
return dir, false
115115
}
116116
}
117117

118-
err = mf.processHosting(w, r)
118+
err = mf.processHeaders(w, r)
119119
if err != nil {
120120
log.Printf("Processing rewrites failed: %s", err)
121-
return dir
121+
return dir, false
122122
}
123123

124-
return dir
124+
return dir, false
125125
}
126126

127127
func readManifest(path string) (FirebaseManifest, error) {

simplehttp2server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,12 @@ func main() {
5353
log.Printf("Request for %s (Accept-Encoding: %s)", r.URL.Path, r.Header.Get("Accept-Encoding"))
5454

5555
dir := "."
56+
redirected := false
5657
if *config != "" {
57-
dir = processWithConfig(w, r, *config)
58+
dir, redirected = processWithConfig(w, r, *config)
59+
}
60+
if redirected {
61+
return
5862
}
5963
if r.Header.Get(PushMarkerHeader) == "" {
6064
pushResources(w)
@@ -102,8 +106,10 @@ func pushResources(w http.ResponseWriter) {
102106
log.Printf("ResponseWriter is not a Pusher. Not pushing anything")
103107
return
104108
}
109+
newParts := []string{}
105110
for _, part := range parts {
106111
if !strings.Contains(part, "rel=preload") {
112+
newParts = append(newParts, part)
107113
continue
108114
}
109115
resource := extractResourceFromLinkHeader(part)
@@ -119,6 +125,7 @@ func pushResources(w http.ResponseWriter) {
119125
},
120126
})
121127
}
128+
w.Header().Set("Link", strings.Join(newParts, ","))
122129
}
123130

124131
var extractionRegexp = regexp.MustCompile("<([^>]+)>")

0 commit comments

Comments
 (0)