-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
std_collect.go
65 lines (57 loc) · 2.26 KB
/
std_collect.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Code generated by __generator__/interpreter.go at once
package builtin
import (
"github.com/ysugimoto/falco/interpreter/context"
"github.com/ysugimoto/falco/interpreter/function/errors"
"github.com/ysugimoto/falco/interpreter/value"
)
const Std_collect_Name = "std.collect"
var Std_collect_ArgumentTypes = []value.Type{value.IdentType, value.StringType}
func Std_collect_Validate(args []value.Value) error {
if len(args) < 1 || len(args) > 2 {
return errors.ArgumentNotInRange(Std_collect_Name, 1, 2, args)
}
for i := range args {
if args[i].Type() != Std_collect_ArgumentTypes[i] {
return errors.TypeMismatch(Std_collect_Name, i+1, Std_collect_ArgumentTypes[i], args[i].Type())
}
}
return nil
}
// Fastly built-in function implementation of std.collect
// Arguments may be:
// - ID
// - ID, STRING
// Reference: https://developer.fastly.com/reference/vcl/functions/miscellaneous/std-collect/
func Std_collect(ctx *context.Context, args ...value.Value) (value.Value, error) {
// Argument validations
if err := Std_collect_Validate(args); err != nil {
return value.Null, err
}
// TODO: std.collection has no effect because Golang's HTTP header is automatically collected
// ident := value.Unwrap[*value.Ident](args[0])
// sep := ","
// if len(args) > 1 {
// sep = value.Unwrap[*value.String](args[1]).Value
// }
//
// switch {
// case strings.HasPrefix(ident.Value, "req.http."):
// name := strings.TrimPrefix(ident.Value, "req.http.")
// value := ctx.Request.Header.Values(name)
// ctx.Request.Header.Set(name, strings.Join(value, sep))
// case strings.HasPrefix(ident.Value, "bereq.http"):
// name := strings.TrimPrefix(ident.Value, "bereq.http.")
// value := ctx.BackendRequest.Header.Values(name)
// ctx.BackendRequest.Header.Set(name, strings.Join(value, sep))
// case strings.HasPrefix(ident.Value, "beresp.http"):
// name := strings.TrimPrefix(ident.Value, "beresp.http.")
// value := ctx.BackendResponse.Header.Values(name)
// ctx.Request.Header.Set(name, strings.Join(value, sep))
// case strings.HasPrefix(ident.Value, "resp.http"):
// name := strings.TrimPrefix(ident.Value, "resp.http.")
// value := ctx.BackendResponse.Header.Values(name)
// ctx.BackendResponse.Header.Set(name, strings.Join(value, sep))
// }
return value.Null, nil
}