-
Notifications
You must be signed in to change notification settings - Fork 177
/
url.go
85 lines (71 loc) · 2.47 KB
/
url.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright 2018 The Trickster Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package irondb
import (
"fmt"
"net/http"
tkerr "github.com/trickstercache/trickster/v2/pkg/errors"
terr "github.com/trickstercache/trickster/v2/pkg/proxy/errors"
"github.com/trickstercache/trickster/v2/pkg/proxy/request"
"github.com/trickstercache/trickster/v2/pkg/timeseries"
)
// SetExtent will change the upstream request query to use the provided Extent.
func (c *Client) SetExtent(r *http.Request, trq *timeseries.TimeRangeQuery, extent *timeseries.Extent) {
rsc := request.GetResources(r)
if rsc == nil || rsc.PathConfig == nil {
return
}
if f, ok := c.extentSetters[rsc.PathConfig.HandlerName]; ok {
f(r, trq, extent)
}
}
// FastForwardRequest returns an *http.Request crafted to collect Fast Forward
// data from the Origin, based on the provided HTTP Request
func (c *Client) FastForwardRequest(r *http.Request) (*http.Request, error) {
rsc := request.GetResources(r)
if rsc == nil || rsc.PathConfig == nil {
return nil, tkerr.ErrMissingPathconfig
}
switch rsc.PathConfig.HandlerName {
case "RollupHandler":
return c.rollupHandlerFastForwardRequest(r)
case "HistogramHandler":
return c.histogramHandlerFastForwardRequest(r)
case "CAQLHandler":
return c.caqlHandlerFastForwardRequest(r)
}
return nil, fmt.Errorf("unknown handler name: %s", rsc.PathConfig.HandlerName)
}
// ParseTimeRangeQuery parses the key parts of a TimeRangeQuery from the
// inbound HTTP Request.
func (c *Client) ParseTimeRangeQuery(
r *http.Request) (*timeseries.TimeRangeQuery, *timeseries.RequestOptions,
bool, error) {
rsc := request.GetResources(r)
if rsc == nil || rsc.PathConfig == nil {
return nil, nil, false, tkerr.ErrMissingPathconfig
}
var trq *timeseries.TimeRangeQuery
var err error
if f, ok := c.trqParsers[rsc.PathConfig.HandlerName]; ok {
trq, err = f(r)
} else {
trq = nil
err = terr.ErrNotTimeRangeQuery
}
rsc.TimeRangeQuery = trq
return trq, nil, true, err
}