feat: support proxy request body amend in mock

This commit is contained in:
rick 2025-03-04 08:08:31 +00:00
parent b46114cb6f
commit 3532ef05ed
3 changed files with 46 additions and 31 deletions

View File

@ -17,6 +17,7 @@ const loadingStores = ref(true)
const tablesTree = ref([])
watch(store, (s) => {
kind.value = ''
stores.value.forEach((e: Store) => {
if (e.name === s) {
kind.value = e.kind.name
@ -39,7 +40,8 @@ watch(kind, (k) => {
queryTip.value = 'Enter SQL query'
executeQuery()
break;
case 'atest-store-etcd', 'atest-store-redis':
case 'atest-store-etcd':
case 'atest-store-redis':
sqlQuery.value = ''
queryTip.value = 'Enter key'
break;

View File

@ -120,7 +120,15 @@ func (s *inMemoryServer) Load() (err error) {
}
memLogger.Info("redirect to", "target", api)
targetReq, err := http.NewRequestWithContext(req.Context(), req.Method, api, req.Body)
var requestBody []byte
if requestBody, err = io.ReadAll(req.Body); err != nil {
w.WriteHeader(http.StatusInternalServerError)
}
if proxy.RequestAmend.BodyPatch != "" {
}
targetReq, err := http.NewRequestWithContext(req.Context(), req.Method, api, bytes.NewBuffer(requestBody))
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
memLogger.Error(err, "failed to create proxy request")

View File

@ -59,6 +59,11 @@ type Webhook struct {
type Proxy struct {
Path string `yaml:"path" json:"path"`
Target string `yaml:"target" json:"target"`
RequestAmend RequestAmend `yaml:"requestAmend" json:"requestAmend"`
}
type RequestAmend struct {
BodyPatch string `yaml:"bodyPatch" json:"bodyPatch"`
}
type Server struct {