| 349 | } |
| 350 | |
| 351 | func (s *Service) sendUsageReport(ctx context.Context) error { |
| 352 | d, err := s.ReportData(ctx) |
| 353 | if err != nil { |
| 354 | return err |
| 355 | } |
| 356 | var b bytes.Buffer |
| 357 | if err := json.NewEncoder(&b).Encode(d); err != nil { |
| 358 | return err |
| 359 | } |
| 360 | |
| 361 | client := &http.Client{ |
| 362 | Transport: &http.Transport{ |
| 363 | DialContext: dialer.DialContext, |
| 364 | Proxy: http.ProxyFromEnvironment, |
| 365 | TLSClientConfig: &tls.Config{ |
| 366 | InsecureSkipVerify: s.cfg.Options().URPostInsecurely, |
| 367 | MinVersion: tls.VersionTLS12, |
| 368 | ClientSessionCache: tls.NewLRUClientSessionCache(0), |
| 369 | }, |
| 370 | }, |
| 371 | } |
| 372 | req, err := http.NewRequestWithContext(ctx, http.MethodPost, s.cfg.Options().URURL, &b) |
| 373 | if err != nil { |
| 374 | return err |
| 375 | } |
| 376 | req.Header.Set("Content-Type", "application/json") |
| 377 | resp, err := client.Do(req) |
| 378 | if err != nil { |
| 379 | return err |
| 380 | } |
| 381 | resp.Body.Close() |
| 382 | return nil |
| 383 | } |
| 384 | |
| 385 | func (s *Service) Serve(ctx context.Context) error { |
| 386 | s.cfg.Subscribe(s) |