(w http.ResponseWriter, req *tailcfg.MapRequest, res *tailcfg.MapResponse)
| 570 | } |
| 571 | |
| 572 | func writeMapResponse(w http.ResponseWriter, req *tailcfg.MapRequest, res *tailcfg.MapResponse) error { |
| 573 | jsonBody, err := json.Marshal(res) |
| 574 | if err != nil { |
| 575 | return fmt.Errorf("marshal map response: %w", err) |
| 576 | } |
| 577 | |
| 578 | var respBody []byte |
| 579 | if req.Compress == "zstd" { |
| 580 | respBody = zstdEncode(jsonBody) |
| 581 | } else { |
| 582 | respBody = jsonBody |
| 583 | } |
| 584 | |
| 585 | data := make([]byte, 4) |
| 586 | binary.LittleEndian.PutUint32(data, uint32(len(respBody))) |
| 587 | data = append(data, respBody...) |
| 588 | |
| 589 | _, err = w.Write(data) |
| 590 | if err != nil { |
| 591 | return fmt.Errorf("write map response: %w", err) |
| 592 | } |
| 593 | return nil |
| 594 | } |
| 595 | |
| 596 | func zstdEncode(in []byte) []byte { |
| 597 | encoder, ok := zstdEncoderPool.Get().(*zstd.Encoder) |
no test coverage detected