Skip to content

Commit aaca78d

Browse files
Merge pull request #1109 from circleci/clean-up-httpclient
Remove GET with Body support now RT-724 is complete
2 parents ebc7ea5 + a4c07ef commit aaca78d

File tree

3 files changed

+14
-119
lines changed

3 files changed

+14
-119
lines changed

httpclient/httpclient.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,6 @@ type Request struct {
174174
query url.Values
175175
rawquery string
176176

177-
// We want to prevent HTTP GETs with body or rawBody due to incompatibilities with CloudFront WAF which API Infra
178-
// are introducing. In order to facilitate a migration for runner we need to be able to override this. This can be
179-
// removed once RT-724 is completed.
180-
allowGETWithBody bool
181-
182177
propagation bool
183178
flatten string
184179

@@ -218,14 +213,6 @@ func RouteParams(routeParams ...interface{}) func(*Request) {
218213
}
219214
}
220215

221-
// AllowGETWithBody will allow the client to send a GET request with a body, which we error on by default. We should
222-
// remove this once RT-724 is completed.
223-
func AllowGETWithBody() func(*Request) {
224-
return func(r *Request) {
225-
r.allowGETWithBody = true
226-
}
227-
}
228-
229216
// Decoder adds a response body decoder to some http status code
230217
// Note this will modify the original Request.
231218
//
@@ -793,7 +780,6 @@ func doneRetrying(err error) error {
793780
func (r Request) validate() error {
794781
// We do not allow GET requests with Body as they are not supported by CloudFront WAF, which requests are routed
795782
// through. - https://circleci.slack.com/archives/C03M4P0Q4GH/p1659566842825159
796-
// This can be overridden with httpclient.AllowGETWithBody() if required for legacy or third-party compatibility
797783
if !r.validateGetWithBody() {
798784
return errors.New("cannot have GET request with body or raw body")
799785
}
@@ -814,7 +800,7 @@ func (r Request) validateOnlyRawBodyOrBody() bool {
814800
}
815801

816802
func (r Request) validateGetWithBody() bool {
817-
if !r.allowGETWithBody && (r.method == "GET" && r.hasBody()) {
803+
if r.method == "GET" && r.hasBody() {
818804
return false
819805
}
820806

releases/release/handler.go

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,19 @@ func Handler(cfg HandlerConfig) func(c *gin.Context) {
3030
ctx := c.Request.Context()
3131
var req Requirements
3232

33-
bindAndValidate(c, &req)
33+
if err := c.BindQuery(&req); err != nil {
34+
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
35+
"message": fmt.Sprintf("bad request: %s", err),
36+
})
37+
return
38+
}
39+
40+
if err := req.Validate(); err != nil {
41+
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
42+
"message": fmt.Sprintf("bad request: %s", err),
43+
})
44+
return
45+
}
3446

3547
// if list is nil, client should never proceed to download
3648
if cfg.List == nil {
@@ -70,27 +82,3 @@ func Handler(cfg HandlerConfig) func(c *gin.Context) {
7082
}
7183
}
7284
}
73-
74-
func bindAndValidate(c *gin.Context, req *Requirements) {
75-
// To support a migration path from JSON body to query params we check the content length header. This can be
76-
// removed when RT-724 is done
77-
var err error
78-
if c.Request.ContentLength != 0 {
79-
err = c.BindJSON(&req)
80-
} else {
81-
err = c.BindQuery(&req)
82-
}
83-
if err != nil {
84-
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
85-
"message": fmt.Sprintf("bad request: %s", err),
86-
})
87-
return
88-
}
89-
90-
if err = req.Validate(); err != nil {
91-
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
92-
"message": fmt.Sprintf("bad request: %s", err),
93-
})
94-
return
95-
}
96-
}

releases/release/handler_test.go

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -19,81 +19,6 @@ import (
1919
"github.com/circleci/ex/testing/testcontext"
2020
)
2121

22-
func TestHandler_WithBody(t *testing.T) {
23-
ctx := testcontext.Background()
24-
25-
t.Run("Test success", func(t *testing.T) {
26-
fix := startAPI(ctx, t)
27-
28-
t.Run("Can get a release", func(t *testing.T) {
29-
agent, err := fix.DownloadWithBody(ctx, release.Requirements{
30-
Platform: "linux",
31-
Arch: "amd64",
32-
})
33-
34-
assert.Assert(t, err)
35-
assert.Check(t, cmp.DeepEqual(agent, &release.Release{
36-
URL: fix.S3URL + "/1.1.1-abcdef01/linux/amd64/circleci-agent",
37-
Checksum: "4a62f09b64873a20386cdbfaca87cc10d8352fab014ef0018f1abcce08a3d027",
38-
Version: "1.1.1-abcdef01",
39-
}))
40-
})
41-
})
42-
43-
t.Run("Test for unknown arch", func(t *testing.T) {
44-
fix := startAPI(ctx, t)
45-
46-
t.Run("Release not found", func(t *testing.T) {
47-
_, err := fix.DownloadWithBody(ctx, release.Requirements{
48-
Platform: "linux",
49-
Arch: "enemy",
50-
})
51-
assert.Check(t, httpclient.HasStatusCode(err, http.StatusNotFound))
52-
assert.Check(t, cmp.ErrorContains(err,
53-
`404 (Not Found) (1 attempts): no download found for version="1.1.1-abcdef01" os="linux" arch="enemy"`,
54-
))
55-
})
56-
})
57-
58-
t.Run("Test invalid requests", func(t *testing.T) {
59-
fix := startAPI(ctx, t)
60-
61-
t.Run("No platform", func(t *testing.T) {
62-
_, err := fix.DownloadWithBody(ctx, release.Requirements{
63-
Arch: "enemy",
64-
})
65-
assert.Check(t, httpclient.HasStatusCode(err, http.StatusBadRequest))
66-
assert.Check(t, cmp.ErrorContains(err,
67-
`400 (Bad Request) (1 attempts): bad request: platform is required`,
68-
))
69-
})
70-
t.Run("No arch", func(t *testing.T) {
71-
_, err := fix.DownloadWithBody(ctx, release.Requirements{
72-
Platform: "linux",
73-
})
74-
assert.Check(t, httpclient.HasStatusCode(err, http.StatusBadRequest))
75-
assert.Check(t, cmp.ErrorContains(err,
76-
`400 (Bad Request) (1 attempts): bad request: arch is required`,
77-
))
78-
})
79-
})
80-
81-
t.Run("Test no downloads", func(t *testing.T) {
82-
fix := startAPIWithDownloads(ctx, t, false)
83-
84-
t.Run("Should give 410", func(t *testing.T) {
85-
_, err := fix.DownloadWithBody(ctx, release.Requirements{
86-
Platform: "linux",
87-
Arch: "amd64",
88-
})
89-
assert.Check(t, httpclient.HasStatusCode(err, http.StatusGone))
90-
assert.Check(t, cmp.ErrorContains(err,
91-
`410 (Gone) (1 attempts): no more downloads possible`,
92-
))
93-
})
94-
})
95-
}
96-
9722
func TestHandler_WithQuery(t *testing.T) {
9823
ctx := testcontext.Background()
9924

@@ -169,10 +94,6 @@ func TestHandler_WithQuery(t *testing.T) {
16994
})
17095
}
17196

172-
func (f *fixture) DownloadWithBody(ctx context.Context, requirements release.Requirements) (*release.Release, error) {
173-
return f.download(ctx, httpclient.Body(requirements), httpclient.AllowGETWithBody())
174-
}
175-
17697
func (f *fixture) DownloadWithQuery(ctx context.Context, requirements release.Requirements) (*release.Release, error) {
17798
return f.download(ctx, httpclient.QueryParams(map[string]string{
17899
"arch": requirements.Arch,

0 commit comments

Comments
 (0)