MCPcopy Index your code
hub / github.com/Shopify/toxiproxy / ProxyCreate

Method ProxyCreate

api.go:204–240  ·  view source on GitHub ↗
(response http.ResponseWriter, request *http.Request)

Source from the content-addressed store, hash-verified

202}
203
204func (server *ApiServer) ProxyCreate(response http.ResponseWriter, request *http.Request) {
205 // Default fields to enable the proxy right away
206 input := Proxy{Enabled: true}
207 err := json.NewDecoder(request.Body).Decode(&input)
208 if server.apiError(response, joinError(err, ErrBadRequestBody)) {
209 return
210 }
211
212 if len(input.Name) < 1 {
213 server.apiError(response, joinError(fmt.Errorf("name"), ErrMissingField))
214 return
215 }
216 if len(input.Upstream) < 1 {
217 server.apiError(response, joinError(fmt.Errorf("upstream"), ErrMissingField))
218 return
219 }
220
221 proxy := NewProxy(server, input.Name, input.Listen, input.Upstream)
222
223 err = server.Collection.Add(proxy, input.Enabled)
224 if server.apiError(response, err) {
225 return
226 }
227
228 data, err := json.Marshal(proxyWithToxics(proxy))
229 if server.apiError(response, err) {
230 return
231 }
232
233 response.Header().Set("Content-Type", "application/json")
234 response.WriteHeader(http.StatusCreated)
235 _, err = response.Write(data)
236 if err != nil {
237 log := zerolog.Ctx(request.Context())
238 log.Warn().Err(err).Msg("ProxyCreate: Failed to write response to client")
239 }
240}
241
242func (server *ApiServer) Populate(response http.ResponseWriter, request *http.Request) {
243 proxies, err := server.Collection.PopulateJson(server, request.Body)

Callers

nothing calls this directly

Calls 6

apiErrorMethod · 0.95
joinErrorFunction · 0.85
NewProxyFunction · 0.85
proxyWithToxicsFunction · 0.85
AddMethod · 0.80
WriteMethod · 0.80

Tested by

no test coverage detected