Repository navigation
Send a default User-Agent, as the JDK does - #40
Merged
Merged
Conversation
A request whose caller set no User-Agent went out with none. The JDK always names itself: HttpURLConnection as Java/<version> (after the http.agent property when set) and java.net.http as Java-http-client/<version>. Sending nothing isn't neutral: a CDN in front of an API commonly answers a request with no User-Agent with a 403 challenge page. Nous Research's inference API does, so an OpenAI-style client that works on the JVM got an HTML 403 under jolt. Both shims now name jolt the same way, with jolt's version since this isn't the JDK: Jolt/<version> through HttpURLConnection (so jolt.http-client and clj-http-lite), after http.agent when set, and Jolt-http-client/<version> through java.net.http. A User-Agent the caller sets, in any case, is sent instead. It is added where the request is written, so getRequestProperty still answers null for it, as on the JDK. core-test pins the defaults and that a caller's own wins; user-agent-test checks what the server receives through both shims, via a /user-agent echo route on the test server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A request whose caller sets no
User-Agentgoes out with none. The JDK always names itself:HttpURLConnectionsendsJava/<version>, after thehttp.agentproperty when that is set.java.net.httpsendsJava-http-client/<version>.Sending nothing isn't neutral. A CDN in front of an API commonly answers a request without a User-Agent with a 403 challenge page. Nous Research's inference API does this, so an OpenAI-style client that works on the JVM got an HTML 403 under jolt. I checked with curl: no User-Agent gets 403, and any User-Agent at all gets 200.
Change
Both shims now name jolt the same way, using jolt's version (from
jolt.host/jolt-version) since this isn't the JDK:Jolt/<version>throughHttpURLConnection, and so throughjolt.http-clientand clj-http-lite. It comes afterhttp.agentwhen that is set, as on the JDK.Jolt-http-client/<version>throughjava.net.http.A
User-Agentthe caller sets, in any letter case, is sent instead. The header is added incore/with-user-agentat the point the request is written. SogetRequestProperty("User-Agent")still answers null when unset, as on the JDK, and babashka.http-client's ownUser-Agentis untouched.Tests
core-test: the two defaults, and that a caller's own wins whatever its case.user-agent-test: what the server receives through both shims, via a/user-agentecho route on the test server.Local runs, all passing: