Commit 52a6a5d
committed
feat(net-http): StringContent takes an Encoding and serialises through it (#2070)
Measured on the old code: StringContent("\xc3\xa9", "utf-16", "text/plain")
announced `charset=utf-16` and emitted the two UTF-8 bytes c3 a9. A conforming
server reads two octets under a utf-16 label as ONE UTF-16 code unit and gets
U+A9C3 -- a different character, silently, with no diagnostic anywhere. The charset
was a label; the bytes were always the string's storage bytes.
.NET DOES NOT VALIDATE AGAINST THAT. It makes the contradiction UNREPRESENTABLE:
its constructor takes an Encoding, serialises through it (GetContentByteArray,
StringContent.cs:90-98) and labels the header with that same object's WebName
(:73). One object is both the serialiser and the label, so there is no second
source of truth for them to disagree about.
That is why the repair is a SIGNATURE change and not a check. A check would still
let a caller name a charset the body was not encoded in, and would only refuse the
charsets this port happened to recognise. The second parameter is now a
std::shared_ptr<System::Text::Encoding>, and nullptr means UTF-8 -- .NET's
`encoding ??= DefaultStringEncoding` at :53.
StringContent("e") unchanged: c3 a9, charset=utf-8
StringContent("e", "utf-16") no longer compiles
StringContent("e", Encoding::Unicode()) e9 00, charset=utf-16
StringContent("e", nullptr, "text/plain") UTF-8
The web names are .NET's and were verified by probe before the change rather than
assumed: utf-8, utf-16, us-ascii, iso-8859-1, utf-32. The probe binary was deleted
afterwards, per the build-resource policy.
A PUBLIC SOURCE BREAK, landed under SA-2 with all five conditions discharged:
1. migration note -- docs/Migration-StringContentEncoding.md
2. negative consumer fixture --
test/consumer/net_http_stringcontent_encoding_negative.cpp, three sites,
including the two-argument StringContent(body, "utf-8") that is most likely to
survive a careless migration. Fixture set grows to 36 fixtures / 197 sites.
3. downstream ticket #2379
4. the full gate
5. measured impact -- neither cna nor mobile-eggbert references StringContent at
all, ZERO sites in both. Neither was modified.
ONE CHECK BECAME UNNECESSARY AND IS KEPT ANYWAY. #2063 rejects a CR/LF/NUL in the
charset because it is concatenated into a Content-Type field. The charset can no
longer carry one, since it now comes from an Encoding's own web name -- the state
is unrepresentable rather than rejected, which is the stronger of the two. The check
stays because it costs nothing and a future encoding is not obliged to have a
well-formed name.
A NEW COMPONENT EDGE. Net.Http now depends on Text: the graph goes 41 modules / 92
edges to 41 / 93, and docs/ComponentCatalog.md is regenerated. There is no
alternative that keeps the count -- the whole point is to encode through
System::Text::Encoding, and a private copy of even one encoder would be the
duplication #2354 has just finished removing six of.
One gated pin inverted, two cases added. Three mutations, all caught: store the raw
string instead of encoding it; label the header utf-8 regardless of the encoding; a
null encoding means UTF-16 rather than UTF-8.
Gate: 17,320 run, 17,320 passed, 0 failed, 0 skipped across 38 executables, GREEN.
Module boundaries valid (41 modules, 93 edges). Negative fixtures OK (36 fixtures,
197 sites).1 parent 933fde2 commit 52a6a5d
8 files changed
Lines changed: 297 additions & 46 deletions
File tree
- docs
- modules/net-http
- include/System/Net/Http
- tests/System/Net
- test/consumer
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
Lines changed: 49 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
14 | | - | |
15 | | - | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
21 | | - | |
22 | | - | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | | - | |
25 | | - | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | | - | |
28 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
29 | 44 | | |
30 | 45 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
38 | 49 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
44 | 57 | | |
| 58 | + | |
45 | 59 | | |
46 | 60 | | |
47 | | - | |
48 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
49 | 72 | | |
50 | | - | |
| 73 | + | |
51 | 74 | | |
52 | | - | |
| 75 | + | |
53 | 76 | | |
54 | 77 | | |
55 | 78 | | |
56 | 79 | | |
57 | | - | |
| 80 | + | |
58 | 81 | | |
59 | 82 | | |
60 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
150 | | - | |
| 151 | + | |
151 | 152 | | |
152 | 153 | | |
153 | 154 | | |
| |||
707 | 708 | | |
708 | 709 | | |
709 | 710 | | |
710 | | - | |
711 | | - | |
712 | | - | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
713 | 714 | | |
714 | 715 | | |
715 | 716 | | |
| |||
1712 | 1713 | | |
1713 | 1714 | | |
1714 | 1715 | | |
1715 | | - | |
1716 | | - | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
1717 | 1721 | | |
1718 | 1722 | | |
1719 | 1723 | | |
| |||
1728 | 1732 | | |
1729 | 1733 | | |
1730 | 1734 | | |
1731 | | - | |
| 1735 | + | |
1732 | 1736 | | |
1733 | 1737 | | |
1734 | 1738 | | |
| |||
2097 | 2101 | | |
2098 | 2102 | | |
2099 | 2103 | | |
2100 | | - | |
2101 | | - | |
2102 | | - | |
2103 | | - | |
2104 | | - | |
2105 | | - | |
2106 | | - | |
2107 | | - | |
2108 | | - | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
2109 | 2151 | | |
2110 | 2152 | | |
2111 | 2153 | | |
| |||
Binary file not shown.
0 commit comments