Skip to content

Feat(http): accept all standard HTTP methods in the http providers - #340

Open
wesomitsu wants to merge 4 commits into
kubevela:mainfrom
wesomitsu:http-provider-all-methods
Open

wesomitsu wants to merge 4 commits into
kubevela:mainfrom
wesomitsu:http-provider-all-methods

Conversation

@wesomitsu

@wesomitsu wesomitsu commented Nov 22, 2026 •

Copy link
Copy Markdown

Description of your changes

#HTTPDo only allowed GET/POST/PUT/DELETE, so PATCH, HEAD and OPTIONS requests failed CUE validation even though the provider passes the method straight through to the Go client. This widens method to GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE and PATCH (default still GET) in the http provider, the legacy op.#HTTPDo provider and the request step definition in the chart, and adds #HTTPPatch, #HTTPHead and #HTTPOptions to both providers. No Go changes were needed outside tests.

The request step always ran json.Unmarshal on the response body, so a successful HEAD request (or any empty response, such as a 204) would fail the step. It now decodes only a non-empty body, and response is left unset otherwise.

Fixes #295

I have:

  • Read and followed KubeVela's contribution process.
  • Related Docs updated properly.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

The method tests for both providers send each method definition's request to an httptest.Server and check the method the server received. They now cover PATCH, HEAD and OPTIONS, and the server records r.Method instead of echoing it in the body, since a HEAD response has no body.

TestRequestStepResponseBody evaluates the chart's request template with stubbed vela imports for HEAD, 204, an empty 200 and a JSON body. The empty-body cases fail without the guard and pass with it. go test ./pkg/providers/http/... ./pkg/providers/legacy/http/..., go vet on those packages and gofmt pass. I did not run make reviewable or the envtest-based kube suites, which need etcd locally.

Special notes for your reviewer

The legacy test reads the method from each CUE definition and sends it with Do(), because calling the legacy provider directly from an uncompiled template trips over the empty response field.

🤖 Generated with Claude Code


Summary by cubic

The HTTP providers and request step now accept all standard HTTP methods, so PATCH, HEAD, OPTIONS, CONNECT, and TRACE requests no longer fail CUE validation. Adds #HTTPPatch, #HTTPHead, and #HTTPOptions definitions to both the http and legacy providers; method defaults to GET as before. Fixes #295.

The request step no longer decodes an empty response body, so HEAD requests and empty responses such as 204 no longer fail the step. response is left unset when there is no body to decode.

Written for commit 90691de. Summary will update on new commits.

View guided diff

#HTTPDo only allowed GET, POST, PUT and DELETE, so a PATCH, HEAD or
OPTIONS request failed CUE validation although the provider passes the
method straight to the Go client.

The method field of the http provider, the legacy op.#HTTPDo provider
and the request step definition now accepts GET, HEAD, POST, PUT,
DELETE, CONNECT, OPTIONS, TRACE and PATCH, still defaulting to GET.
#HTTPPatch, #HTTPHead and #HTTPOptions join the existing method
definitions in both providers. No Go change is needed.

The method tests now record the method the server receives, since a
HEAD response has no body, and cover the new definitions for both
providers.

Fixes kubevela#295

Signed-off-by: wesomitsu <24356639+wesomitsu@users.noreply.github.com>
Now that the request step accepts HEAD, a successful HEAD response would
fail in json.Unmarshal because it has no body. The same applies to 204
and other empty responses. Only decode a non-empty body, and cover
empty and JSON responses with tests.

Signed-off-by: wesomitsu <24356639+wesomitsu@users.noreply.github.com>
Signed-off-by: wesomitsu <24356639+wesomitsu@users.noreply.github.com>
Signed-off-by: wesomitsu <24356639+wesomitsu@users.noreply.github.com>
@codecov

codecov Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.64%. Comparing base (d7db9c4) to head (90691de).
⚠️ Report is 55 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #340       +/-   ##
===========================================
+ Coverage   62.49%   80.64%   +18.15%     
===========================================
  Files          62       88       +26     
  Lines        4415     7053     +2638     
===========================================
+ Hits         2759     5688     +2929     
- Misses       1324     1365       +41     
+ Partials      332        0      -332     
Flag Coverage Δ
e2etests 37.46% <ø> (?)
unit-test 75.04% <ø> (+12.55%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 6 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="pkg/providers/http/method_cue_test.go">

<violation number="1" location="pkg/providers/http/method_cue_test.go:59">
P3: This change removes the only assertion of `$returns.body` propagation through the CUE provider adapter, and the new handler returns an empty body for every method. Retain the body assertion for non-HEAD methods while using the recorded method for HEAD, so a regression in the adapter's response conversion is still detected.</violation>
</file>

<file name="pkg/providers/http/request_definition_test.go">

<violation number="1" location="pkg/providers/http/request_definition_test.go:57">
P2: The request-step method matrix omits `CONNECT`, `TRACE`, and `PATCH`, so the chart’s newly expanded union could drop any of these while this test still passes. Add cases for all three methods.</violation>

<violation number="2" location="pkg/providers/http/request_definition_test.go:81">
P2: This test never verifies the waiting contract: a broken `wait.continue` value would still pass because it checks only `response` absence. Assert that `wait.continue` evaluates to false.</violation>
</file>

Reply to a comment to ask cubic a question or push back. It learns from your replies.
Click Fix with cubic on a comment, or reply @cubic-dev-ai fix this, and cubic writes the fix.

View guided diff | Re-trigger cubic

status int
wantResponse bool
}{
"HEAD has no body": {method: "HEAD", status: 200},

@cubic-dev-ai cubic-dev-ai Bot Nov 22, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The request-step method matrix omits CONNECT, TRACE, and PATCH, so the chart’s newly expanded union could drop any of these while this test still passes. Add cases for all three methods.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At pkg/providers/http/request_definition_test.go, line 57:

<comment>The request-step method matrix omits `CONNECT`, `TRACE`, and `PATCH`, so the chart’s newly expanded union could drop any of these while this test still passes. Add cases for all three methods.</comment>

<file context>
@@ -0,0 +1,82 @@
+		status       int
+		wantResponse bool
+	}{
+		"HEAD has no body":   {method: "HEAD", status: 200},
+		"204 has no body":    {method: "DELETE", status: 204},
+		"empty 200":          {method: "OPTIONS", status: 200},
</file context>
Fix with cubic

func TestRequestStepBeforeResponse(t *testing.T) {
v := cuecontext.New().CompileString(requestStepTemplate(t) + "\nparameter: {url: \"http://x\", method: \"HEAD\"}\n")
require.NoError(t, v.Err())
require.False(t, v.LookupPath(cue.ParsePath("response")).Exists())

@cubic-dev-ai cubic-dev-ai Bot Nov 22, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: This test never verifies the waiting contract: a broken wait.continue value would still pass because it checks only response absence. Assert that wait.continue evaluates to false.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At pkg/providers/http/request_definition_test.go, line 81:

<comment>This test never verifies the waiting contract: a broken `wait.continue` value would still pass because it checks only `response` absence. Assert that `wait.continue` evaluates to false.</comment>

<file context>
@@ -0,0 +1,82 @@
+func TestRequestStepBeforeResponse(t *testing.T) {
+	v := cuecontext.New().CompileString(requestStepTemplate(t) + "\nparameter: {url: \"http://x\", method: \"HEAD\"}\n")
+	require.NoError(t, v.Err())
+	require.False(t, v.LookupPath(cue.ParsePath("response")).Exists())
+}
</file context>
Fix with cubic

require.NoError(t, v.Err())
out, err := GetProviders()["do"].Call(ctx, v.LookupPath(cue.ParsePath("call")))
got = ""
_, err := GetProviders()["do"].Call(ctx, v.LookupPath(cue.ParsePath("call")))

@cubic-dev-ai cubic-dev-ai Bot Nov 22, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: This change removes the only assertion of $returns.body propagation through the CUE provider adapter, and the new handler returns an empty body for every method. Retain the body assertion for non-HEAD methods while using the recorded method for HEAD, so a regression in the adapter's response conversion is still detected.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At pkg/providers/http/method_cue_test.go, line 59:

<comment>This change removes the only assertion of `$returns.body` propagation through the CUE provider adapter, and the new handler returns an empty body for every method. Retain the body assertion for non-HEAD methods while using the recorded method for HEAD, so a regression in the adapter's response conversion is still detected.</comment>

<file context>
@@ -34,27 +34,31 @@ import (
 			require.NoError(t, v.Err())
-			out, err := GetProviders()["do"].Call(ctx, v.LookupPath(cue.ParsePath("call")))
+			got = ""
+			_, err := GetProviders()["do"].Call(ctx, v.LookupPath(cue.ParsePath("call")))
 			require.NoError(t, err)
-			body, err := out.LookupPath(cue.ParsePath("$returns.body")).String()
</file context>
Fix with cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP provider: accept all standard HTTP methods, not just GET/POST/PUT/DELETE

1 participant