Commit d09ade8
[csharp] fix: stop percent-encoding the User-Agent (#24923)
Configuration.mustache wraps the user agent in WebUtility.UrlEncode, so the
"/" that separates product from version reaches the server as %2F and a
space reaches it as "+": the default agent goes out as
OpenAPI-Generator%2F1.0.0%2Fcsharp, and httpUserAgent=my-client/1.2.3 goes
out as my-client%2F1.2.3. A User-Agent is not a URL component and nothing
downstream decodes it.
The encoding arrived with the RestSharp v108 upgrade in #12789 for a "user
agent bug" the PR does not describe. RestSharp 112 accepts the unencoded
value: pointed at a raw socket, RestClientOptions.UserAgent = "OpenAPI-
Generator/1.0.0/csharp" puts exactly that on the wire. The other two
libraries sharing this template never validated it either - httpclient uses
TryAddWithoutValidation, unityWebRequest SetRequestHeader - and the sibling
csharp-functions generator has always assigned the value unencoded.
Drop the call in both restsharp Configuration templates. using System.Net
stays for WebProxy. Every csharp sample changes by exactly this one line.
Claude-Session: https://claude.ai/code/session_016AMTM9KKdWLnfdCCiN32pM
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent a7678ef commit d09ade8
26 files changed
Lines changed: 54 additions & 25 deletions
File tree
- modules/openapi-generator/src
- main/resources/csharp
- test/java/org/openapitools/codegen/csharpnetcore
- samples/client
- echo_api/csharp/restsharp/net8/EchoApi/src/Org.OpenAPITools/Client
- others/csharp-complex-files/src/Org.OpenAPITools/Client
- petstore/csharp
- httpclient
- net10
- Petstore-nonPublicApi/src/Org.OpenAPITools/Client
- Petstore/src/Org.OpenAPITools/Client
- net9
- Petstore-nonPublicApi/src/Org.OpenAPITools/Client
- Petstore/src/Org.OpenAPITools/Client
- standard2.0/Petstore/src/Org.OpenAPITools/Client
- restsharp
- net10
- EnumMappings/src/Org.OpenAPITools/Client
- Petstore/src/Org.OpenAPITools/Client
- net4.7
- MultipleFrameworks/src/Org.OpenAPITools/Client
- Petstore/src/Org.OpenAPITools/Client
- net4.8/Petstore/src/Org.OpenAPITools/Client
- net8
- EnumMappings/src/Org.OpenAPITools/Client
- ParameterMappings/src/Org.OpenAPITools/Client
- Petstore/src/Org.OpenAPITools/Client
- UseDateTimeForDate/src/Org.OpenAPITools/Client
- useVirtualForHooks/src/Org.OpenAPITools/Client
- net9/EnumMappings/src/Org.OpenAPITools/Client
- standard2.0
- ConditionalSerialization/src/Org.OpenAPITools/Client
- Petstore/src/Org.OpenAPITools/Client
- unityWebRequest
- net10/Petstore/src/Org.OpenAPITools/Client
- net9/Petstore/src/Org.OpenAPITools/Client
- standard2.0/Petstore/src/Org.OpenAPITools/Client
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| |||
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
206 | 235 | | |
207 | 236 | | |
208 | 237 | | |
| |||
samples/client/echo_api/csharp/restsharp/net8/EchoApi/src/Org.OpenAPITools/Client/Configuration.cs
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
120 | | - | |
| 120 | + | |
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| |||
0 commit comments