MCPcopy
hub / github.com/nats-io/nats.go / TestHeaderMultiLine

Function TestHeaderMultiLine

nats_test.go:1625–1669  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1623}
1624
1625func TestHeaderMultiLine(t *testing.T) {
1626 m := NewMsg("foo")
1627 m.Header = Header{
1628 "CorrelationID": []string{"123"},
1629 "Msg-ID": []string{"456"},
1630 "X-NATS-Keys": []string{"A", "B", "C"},
1631 "X-Test-Keys": []string{"D", "E", "F"},
1632 }
1633 // Users can opt-in to canonicalize like http.Header does
1634 // by using http.Header#Set or http.Header#Add.
1635 http.Header(m.Header).Set("accept-encoding", "json")
1636 http.Header(m.Header).Add("AUTHORIZATION", "s3cr3t")
1637
1638 // Multi Value Header becomes represented as multi-lines in the wire
1639 // since internally using same Write from http stdlib.
1640 m.Header.Set("X-Test", "First")
1641 m.Header.Add("X-Test", "Second")
1642 m.Header.Add("X-Test", "Third")
1643
1644 b, err := m.headerBytes()
1645 if err != nil {
1646 t.Fatal(err)
1647 }
1648 result := string(b)
1649
1650 expectedHeader := `NATS/1.0
1651Accept-Encoding: json
1652Authorization: s3cr3t
1653CorrelationID: 123
1654Msg-ID: 456
1655X-NATS-Keys: A
1656X-NATS-Keys: B
1657X-NATS-Keys: C
1658X-Test: First
1659X-Test: Second
1660X-Test: Third
1661X-Test-Keys: D
1662X-Test-Keys: E
1663X-Test-Keys: F
1664
1665`
1666 if strings.Replace(expectedHeader, "\n", "\r\n", -1) != result {
1667 t.Fatalf("Expected: %q, got: %q", expectedHeader, result)
1668 }
1669}
1670
1671func TestLameDuckMode(t *testing.T) {
1672 l, err := net.Listen("tcp", "127.0.0.1:0")

Callers

nothing calls this directly

Calls 5

headerBytesMethod · 0.95
NewMsgFunction · 0.85
FatalfMethod · 0.80
SetMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected