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
Configurable user agent #1163
Comments
It will probably be changed with #1162 |
@pecko You changes give the ability to dynamically specify Jcabi version, build, and date using properties file, but UA string would still be built using a fixed template. What i meant instead was to give the ability to specify entire UA string. The logic behind this is that GitHub would probably like to have to ability to identify an application based on UA, and not the library used by application. It more likely that the abusive or other invalid behaviour lays within the application itself, not the library. If your PR gets merged, I would probably follow with a PR based on your work, to allow totally custom UA strings too. |
@cezarykluczynski
or what ever you want. |
@pecko Wouldn't the resulting string be "jcabi-github Cezary Kluczyński & Friends "? I'm looking at pecko@14dbcb0#diff-bba83786024a91e3e967174c102169e8R111 I'm thinking of something like this: if (valid) {
if (prop.getProperty("JCabi-User-Agent-String")) {
USER_AGENT = prop.getProperty("JCabi-User-Agent-String");
} else {
USER_AGENT = JCABI_GITHUB + BLANK
+ prop.getProperty("JCabi-Version") + BLANK
+ prop.getProperty("JCabi-Build") + BLANK
+ prop.getProperty("JCabi-Date");
}
} else {
USER_AGENT = JCABI_GITHUB + BLANK
+ "? "
+ new Date().toString();
} |
You are right. What you mean that is better:
|
@pecko It would be great if you could add those changes to your PR. I would have create by PR based on yours, so there's no point in waiting. |
@cezarykluczynski |
I have added pecko@4ecb4ba It still uses more properties (client, build number, version and date), but you can use only one. |
@pecko Thank you. Joining string with null value can be tricky, so I would tweak it further, to both avoid converting null values to "null" string, and to avoid having multiple or untrimmed spaces: private buildUserAgentFromProperties(Properties properties) {
ArrayList<String> keys = new ArrayList<String>() {{
add("JCabi-User-Agent")
add("JCabi-Version")
add("JCabi-Build")
add("JCabi-Date")
}};
String ua = "";
for(String key : keys) {
String value = properties.getProperty(key);
if (null != value) {
ua += BLANK + value;
}
}
return ua.length() ? ua.substring(1) : ua;
} And then call it like this: if (value) {
USER_AGENT = buildUserAgentFromProperties(prop);
} |
The PR is ready to merge. |
@cezarykluczynski
|
@yegor256 please dispatch this issue |
@cezarykluczynski thanks for the ticket, I totally understand that problem. But you can solve it without any modifications to the library: Github github = new RtGithub(
new RtGithub().entry()
.reset("User-Agent")
.header("User-Agent", "something else")
) Make sense? |
@yegor256 This doesn't do the trick. Whenever BaseRequest.reset() or BaseRequest.header() is called, a new instance of BaseRequest is created with the updated data, and this new instance is no longed bound to RtGithub.REQUEST. |
@cezarykluczynski why should it be "bound" to |
@yegor256 Sorry for the confusion. That's right, it's working fine. It seems a little excesive to create two instances, but it's works fine. |
@cezarykluczynski please close the ticket if it's solved, thanks for using the lib! |
Hi,
it seems UA string is hardcoded here:
jcabi-github/src/main/java/com/jcabi/github/RtGithub.java
Line 83 in 361bb23
Would you consider making it configurable?
It seems, per documentation, that it should be an application user agent, rather than a user agent of client used by application.
https://developer.github.com/v3/#user-agent-required
The text was updated successfully, but these errors were encountered: