| 368 | } |
| 369 | |
| 370 | func (f *BinaryFailpoints) SetupHTTP(ctx context.Context, failpoint, payload string) error { |
| 371 | host := fmt.Sprintf("127.0.0.1:%d", f.member.Config().GoFailPort) |
| 372 | failpointURL := url.URL{ |
| 373 | Scheme: "http", |
| 374 | Host: host, |
| 375 | Path: failpoint, |
| 376 | } |
| 377 | r, err := http.NewRequestWithContext(ctx, http.MethodPut, failpointURL.String(), bytes.NewBuffer([]byte(payload))) |
| 378 | if err != nil { |
| 379 | return err |
| 380 | } |
| 381 | httpClient := http.Client{ |
| 382 | Timeout: 1 * time.Second, |
| 383 | } |
| 384 | if f.clientTimeout != 0 { |
| 385 | httpClient.Timeout = f.clientTimeout |
| 386 | } |
| 387 | resp, err := httpClient.Do(r) |
| 388 | if err != nil { |
| 389 | return err |
| 390 | } |
| 391 | defer resp.Body.Close() |
| 392 | if resp.StatusCode != http.StatusNoContent { |
| 393 | errMsg, err := io.ReadAll(resp.Body) |
| 394 | if err != nil { |
| 395 | return fmt.Errorf("bad status code: %d, err: %w", resp.StatusCode, err) |
| 396 | } |
| 397 | return fmt.Errorf("bad status code: %d, err: %s", resp.StatusCode, errMsg) |
| 398 | } |
| 399 | return nil |
| 400 | } |
| 401 | |
| 402 | func (f *BinaryFailpoints) DeactivateHTTP(ctx context.Context, failpoint string) error { |
| 403 | host := fmt.Sprintf("127.0.0.1:%d", f.member.Config().GoFailPort) |