-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.go
42 lines (32 loc) · 1.06 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2022 Fastly, Inc.
package main
import (
"context"
"io"
"github.com/fastly/compute-sdk-go/fsthttp"
)
func main() {
fsthttp.ServeFunc(func(ctx context.Context, w fsthttp.ResponseWriter, r *fsthttp.Request) {
// Reset the URI and Host header, so the request is
// recognized and routed correctly at the origin.
r.URL.Scheme, r.URL.Host = "https", "http-me.glitch.me"
r.Header.Set("host", "http-me.glitch.me")
// Determine the framing headers (Content-Length/Transfer-Encoding)
// based on the message body (default)
r.ManualFramingMode = false
// Make sure the response isn't cached.
r.CacheOptions.Pass = true
// This requires your service to be configured with a backend
// named "httpme" and pointing to "https://http-me.glitch.me".
resp, err := r.Send(ctx, "httpme")
if err != nil {
fsthttp.Error(w, err.Error(), fsthttp.StatusBadGateway)
return
}
w.Header().Reset(resp.Header)
// Use the framing headers set in the message.
w.SetManualFramingMode(true)
w.WriteHeader(resp.StatusCode)
io.Copy(w, resp.Body)
})
}