Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C# et al] Default user-agent violates RFC #8376

Open
marhel opened this issue Jul 2, 2018 · 0 comments
Open

[C# et al] Default user-agent violates RFC #8376

marhel opened this issue Jul 2, 2018 · 0 comments

Comments

@marhel
Copy link

marhel commented Jul 2, 2018

Description

Supporting code generated for C# (but also many other languages) default to an invalid User-Agent string according to RFC 7231 HTTP/1.1 Semantics and Content. We noticed this because Akka HTTP Server issues a warning about the incorrect format. It doesn't seem to cause any other ill effects beside the warning, however, apart from the feeling one gets around RFC violations.

For example C# sets UserAgent = "Swagger-Codegen/1.0.0/csharp";

Replacing the actual user-agent (RestSharp in this case) not only defeats the fields purpose, but in this case also violates the specification.

RFC 7231 says the format of the User-Agent string should be:

User-Agent      = product *( RWS ( product / comment ) )
product         = token ["/" product-version]
product-version = token

where 'token' does not allow '/'. Comment is basically "something in parentesis".

Swagger-codegen version

I'm using 2.3.1, but incorrectly formatted user-agent strings can be found in the codebase going back at least two years.

For C# this User-Agent default is present in the templates here and here

However, User-Agent is prevalent in the code base (try git log -G "[Aa]gent.*[Ss]wagger-[Cc]odegen"). At least the template resources and sample code for Android, C#, Eiffel, Go, Java, Perl, PHP, Python, R, Ruby and Rust contains (defaults) to the Swagger-Codegen/version/language format.

Swagger declaration file content or url

Any declaration will probably do, the problem is in the supporting code.

Command line used for generation
swagger-codegen generate --lang csharp --model-package Models -DtargetFramework=v5.0 -DpackageName=Some.Export -i some/schema.yaml -o some-csharp
Steps to reproduce

Generate code, then search for "agent" in ./some-csharp/src/Some.Export/Client/Configuration.cs.

Related issues/PRs

Tried a few searches, couldn't find a similar issue reporting this as a problem. However, #2376 and several issues linked from there, encourages the use of Swagger-Codegen/{version}/{language} as a User-Agent.

Suggest a fix/enhancement

Replacing the actual user-agent defeats the fields purpose:

... often used by servers to help identify the scope of reported
interoperability problems, to work around or tailor responses to avoid
particular user agent limitations, and for analytics regarding browser or
operating system use.

So if self-promotion is desired, it would be more appropriate to append Swagger-Codegen as a less significant part of the User-Agent, and include the language used as a comment. For example using C# and RestSharp v105.2.3, the User-Agent could be;

User-Agent: RestSharp/105.2.3 Swagger-Codegen/1.0.0 (csharp)

This way, any workarounds necessary for RestSharp can still be applied, self-promotion still there, and the format is RFC 7231-compliant.

As for the annoying warning in Akka HTTP server logs, there's an Akka configuration option to turn that off. I can also explicitly set User-Agent using --http-user-agent=Something/1.0 when calling swagger-codegen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant