Skip to content

Commit d16ed9d

Browse files
authored
chore: support more proxy http method (#859)
Co-authored-by: rick <[email protected]>
1 parent c3df540 commit d16ed9d

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

cmd/server.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {
367367
mux.HandlePath(http.MethodGet, "/favicon.ico", frontEndHandlerWithLocation(o.consolePath))
368368
mux.HandlePath(http.MethodGet, "/swagger.json", frontEndHandlerWithLocation(o.consolePath))
369369
mux.HandlePath(http.MethodGet, "/data/{data}", o.dataFromExtension(remoteServer.(server.UIExtensionServer)))
370-
mux.HandlePath(http.MethodPost, "/extensionProxy/{extension}", func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
370+
371+
proxyHandler := func(w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
371372
extServer := remoteServer.(server.UIExtensionServer)
372373

373374
ctx := r.Context()
@@ -388,8 +389,8 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {
388389
return
389390
}
390391

391-
fmt.Println("redirect to", resp.Message)
392-
req, err := http.NewRequestWithContext(ctx, http.MethodPost, resp.Message, r.Body)
392+
fmt.Println("redirect to", resp.Message, "method", r.Method)
393+
req, err := http.NewRequestWithContext(ctx, r.Method, resp.Message, r.Body)
393394
if err != nil {
394395
fmt.Println(err)
395396
return
@@ -416,14 +417,19 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {
416417
var count int
417418
for {
418419
count, err = rsp.Body.Read(data)
419-
if count == -1 || count == 0 || err != nil {
420+
if count == -1 || count == 0 || (err != nil && count <= 0) {
420421
fmt.Println("failed to read response body", err)
422+
w.WriteHeader(http.StatusInternalServerError)
423+
flusher.Flush()
421424
break
422425
}
423426
w.Write(data[:count])
424427
flusher.Flush()
425428
}
426-
})
429+
}
430+
mux.HandlePath(http.MethodPost, "/extensionProxy/{extension}", proxyHandler)
431+
mux.HandlePath(http.MethodGet, "/extensionProxy/{extension}", proxyHandler)
432+
mux.HandlePath(http.MethodDelete, "/extensionProxy/{extension}", proxyHandler)
427433
mux.HandlePath(http.MethodGet, "/get", o.getAtestBinary)
428434
mux.HandlePath(http.MethodPost, "/runner/{suite}/{case}", service.WebRunnerHandler)
429435
mux.HandlePath(http.MethodGet, "/api/v1/sbom", service.SBomHandler)

console/atest-ui/vite.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ export default defineConfig(({mode}) => {
7070
target: env.VITE_API_URL,
7171
changeOrigin: true,
7272
},
73-
'/extensionProxy': {
74-
target: 'http://127.0.0.1:8080',
75-
changeOrigin: true,
76-
},
73+
'/extensionProxy': {
74+
target: env.VITE_API_URL,
75+
changeOrigin: true,
76+
},
7777
'/data': {
7878
target: env.VITE_API_URL,
7979
changeOrigin: true,

0 commit comments

Comments
 (0)