Skip to content

Commit b4a6bbb

Browse files
authored
Fixed ingress route redirect problem. Fixes #1394 (#1395)
1 parent b80d39e commit b4a6bbb

File tree

8 files changed

+21
-15
lines changed

8 files changed

+21
-15
lines changed

gateway/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM golang:1.13.5-alpine3.10
22
WORKDIR /build
33

44
# Take the current space cloud version as a argument
5-
ARG SC_VERSION=0.19.6
5+
ARG SC_VERSION=0.19.7
66

77
# Copy all the source files
88
COPY . .
@@ -16,7 +16,7 @@ RUN GOOS=linux CGO_ENABLED=0 go build -a -ldflags '-s -w -extldflags "-static"'
1616
RUN echo $SC_VERSION && wget https://storage.googleapis.com/space-cloud/mission-control/mission-control-v$SC_VERSION.zip && unzip mission-control-v$SC_VERSION.zip
1717

1818
FROM alpine:3.10
19-
ARG SC_VERSION=0.19.6
19+
ARG SC_VERSION=0.19.7
2020

2121
RUN apk --no-cache add ca-certificates
2222

gateway/modules/global/routing/http.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ type modulesInterface interface {
1919
Auth() *auth.Module
2020
}
2121

22+
var httpClient = http.Client{
23+
CheckRedirect: func(req *http.Request, via []*http.Request) error {
24+
return http.ErrUseLastResponse
25+
},
26+
}
27+
2228
// HandleRoutes handles incoming http requests and routes them according to the configured rules.
2329
func (r *Routing) HandleRoutes(modules modulesInterface) http.HandlerFunc {
2430
return func(writer http.ResponseWriter, request *http.Request) {
@@ -36,7 +42,7 @@ func (r *Routing) HandleRoutes(modules modulesInterface) http.HandlerFunc {
3642
return
3743
}
3844

39-
token, auth, status, err := r.modifyRequest(request.Context(), modules, route, request)
45+
token, claims, status, err := r.modifyRequest(request.Context(), modules, route, request)
4046
if err != nil {
4147
writer.WriteHeader(status)
4248
_ = json.NewEncoder(writer).Encode(map[string]string{"error": err.Error()})
@@ -59,7 +65,7 @@ func (r *Routing) HandleRoutes(modules modulesInterface) http.HandlerFunc {
5965
}
6066

6167
// TODO: Use http2 client if that was the incoming request protocol
62-
response, err := http.DefaultClient.Do(request)
68+
response, err := httpClient.Do(request)
6369
if err != nil {
6470
writer.WriteHeader(http.StatusInternalServerError)
6571
_ = json.NewEncoder(writer).Encode(map[string]string{"error": err.Error()})
@@ -68,7 +74,7 @@ func (r *Routing) HandleRoutes(modules modulesInterface) http.HandlerFunc {
6874
}
6975
defer utils.CloseTheCloser(response.Body)
7076

71-
if err := r.modifyResponse(request.Context(), response, route, token, auth); err != nil {
77+
if err := r.modifyResponse(request.Context(), response, route, token, claims); err != nil {
7278
writer.WriteHeader(http.StatusInternalServerError)
7379
_ = json.NewEncoder(writer).Encode(map[string]string{"error": err.Error()})
7480
return
@@ -128,7 +134,7 @@ func setRequest(ctx context.Context, request *http.Request, route *config.Route,
128134
return nil
129135
}
130136

131-
func prepareHeaders(ctx context.Context, headers config.Headers, state map[string]interface{}) config.Headers {
137+
func prepareHeaders(headers config.Headers, state map[string]interface{}) config.Headers {
132138
out := make([]config.Header, len(headers))
133139
for i, header := range headers {
134140
// First create a new header object

gateway/modules/global/routing/modify.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (r *Routing) modifyRequest(ctx context.Context, modules modulesInterface, r
4646
// Set the headers
4747
state := map[string]interface{}{"args": params, "auth": auth}
4848
headers := append(r.globalConfig.RequestHeaders, route.Modify.RequestHeaders...)
49-
prepareHeaders(ctx, headers, state).UpdateHeader(req.Header)
49+
prepareHeaders(headers, state).UpdateHeader(req.Header)
5050

5151
// Don't forget to reset the body
5252
if params != nil {
@@ -87,7 +87,7 @@ func (r *Routing) modifyResponse(ctx context.Context, res *http.Response, route
8787
// Set the headers
8888
state := map[string]interface{}{"args": params, "auth": auth}
8989
headers := append(r.globalConfig.ResponseHeaders, route.Modify.ResponseHeaders...)
90-
prepareHeaders(ctx, headers, state).UpdateHeader(res.Header)
90+
prepareHeaders(headers, state).UpdateHeader(res.Header)
9191

9292
// If params is not nil we need to template the response
9393
if params != nil {

gateway/utils/constants.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
// BuildVersion is the current version of Space Cloud
8-
const BuildVersion = "0.19.6"
8+
const BuildVersion = "0.19.7"
99

1010
// DLQEventTriggerPrefix used as suffix for DLQ event trigger
1111
const DLQEventTriggerPrefix = "dlq_"

install-manifests/kubernetes/local/space-cloud.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ spec:
200200
containers:
201201
- name: runner
202202
command: ["./app", "start"]
203-
image: spaceuptech/runner:0.19.6
203+
image: spaceuptech/runner:0.19.7
204204
imagePullPolicy: IfNotPresent # IfNotPresent | Always
205205
env:
206206
- name: "LOG_LEVEL"
@@ -368,7 +368,7 @@ spec:
368368
containers:
369369
- name: gateway
370370
command: ["./app", "run"]
371-
image: spaceuptech/gateway:0.19.6
371+
image: spaceuptech/gateway:0.19.7
372372
imagePullPolicy: IfNotPresent # IfNotPresent | Always
373373
env:
374374
- name: "NODE_ID"

install-manifests/kubernetes/prod/space-cloud.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ spec:
200200
containers:
201201
- name: runner
202202
command: ["./app", "start"]
203-
image: spaceuptech/runner:0.19.6
203+
image: spaceuptech/runner:0.19.7
204204
imagePullPolicy: IfNotPresent # IfNotPresent | Always
205205
env:
206206
- name: "LOG_LEVEL"
@@ -372,7 +372,7 @@ spec:
372372
containers:
373373
- name: gateway
374374
command: ["./app", "run"]
375-
image: spaceuptech/gateway:0.19.6
375+
image: spaceuptech/gateway:0.19.7
376376
imagePullPolicy: IfNotPresent # IfNotPresent | Always
377377
env:
378378
- name: "NODE_ID"

runner/model/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package model
22

33
// Version represents the current runner version
4-
const Version string = "v0.19.6"
4+
const Version string = "v0.19.7"

space-cli/cmd/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package cmd
22

3-
const version string = "0.19.6"
3+
const version string = "0.19.7"

0 commit comments

Comments
 (0)