Skip to content

Commit

Permalink
Merge pull request #1259 from amihaiemil/1258
Browse files Browse the repository at this point in the history
#1258 set User-Agent header properly
  • Loading branch information
amihaiemil committed Oct 16, 2021
2 parents 6a52ec7 + 816d3db commit 91f78db
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ private HttpRequest request(
String.join(",", header.getValue())
);
}
requestBuilder = requestBuilder.setHeader(
"User-Agent",
"Self XDSD; https://self-xdsd.com; "
+ "https://github.com/self-xdsd"
);
return requestBuilder.build();
}

Expand Down
63 changes: 63 additions & 0 deletions self-core-impl/src/test/java/com/selfxdsd/core/JdkHttpITCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,13 @@ public void getJsonObjectOkNoAuthWithOtherHeaders() throws IOException {
request.headers().get("My-Header-2").get(0),
Matchers.equalTo("hello2")
);
MatcherAssert.assertThat(
request.headers().get("User-Agent").get(0),
Matchers.equalTo(
"Self XDSD; https://self-xdsd.com; "
+ "https://github.com/self-xdsd"
)
);
}
}

Expand Down Expand Up @@ -283,6 +290,13 @@ public void postJsonObjectWithAuth() throws IOException {
request.headers().get("Authorization").get(0),
Matchers.equalTo("token 123token456")
);
MatcherAssert.assertThat(
request.headers().get("User-Agent").get(0),
Matchers.equalTo(
"Self XDSD; https://self-xdsd.com; "
+ "https://github.com/self-xdsd"
)
);
}
}

Expand Down Expand Up @@ -339,6 +353,13 @@ public void postJsonObjectWithAuthAndOtherHeaders() throws IOException {
request.headers().get("My-Header-2").get(0),
Matchers.equalTo("hello2")
);
MatcherAssert.assertThat(
request.headers().get("User-Agent").get(0),
Matchers.equalTo(
"Self XDSD; https://self-xdsd.com; "
+ "https://github.com/self-xdsd"
)
);
}
}

Expand Down Expand Up @@ -382,6 +403,13 @@ public void patchJsonObjectWithAuth() throws IOException {
request.headers().get("Authorization").get(0),
Matchers.equalTo("token 123token456")
);
MatcherAssert.assertThat(
request.headers().get("User-Agent").get(0),
Matchers.equalTo(
"Self XDSD; https://self-xdsd.com; "
+ "https://github.com/self-xdsd"
)
);
}
}

Expand Down Expand Up @@ -434,6 +462,13 @@ public void patchJsonObjectWithAuthAndOtherHeaders() throws IOException {
request.headers().get("My-Header-2").get(0),
Matchers.equalTo("hello2")
);
MatcherAssert.assertThat(
request.headers().get("User-Agent").get(0),
Matchers.equalTo(
"Self XDSD; https://self-xdsd.com; "
+ "https://github.com/self-xdsd"
)
);
}
}

Expand Down Expand Up @@ -477,6 +512,13 @@ public void putJsonObjectWithAuth() throws IOException {
request.headers().get("Authorization").get(0),
Matchers.equalTo("token 123token456")
);
MatcherAssert.assertThat(
request.headers().get("User-Agent").get(0),
Matchers.equalTo(
"Self XDSD; https://self-xdsd.com; "
+ "https://github.com/self-xdsd"
)
);
}
}

Expand Down Expand Up @@ -529,6 +571,13 @@ public void putJsonObjectWithAuthAndOtherHeaders() throws IOException {
request.headers().get("My-Header-2").get(0),
Matchers.equalTo("hello2")
);
MatcherAssert.assertThat(
request.headers().get("User-Agent").get(0),
Matchers.equalTo(
"Self XDSD; https://self-xdsd.com; "
+ "https://github.com/self-xdsd"
)
);
}
}

Expand Down Expand Up @@ -572,6 +621,13 @@ public void deleteJsonObjectWithAuth() throws IOException {
request.headers().get("Authorization").get(0),
Matchers.equalTo("token 123token456")
);
MatcherAssert.assertThat(
request.headers().get("User-Agent").get(0),
Matchers.equalTo(
"Self XDSD; https://self-xdsd.com; "
+ "https://github.com/self-xdsd"
)
);
}
}

Expand Down Expand Up @@ -628,6 +684,13 @@ public void deleteJsonObjectWithAuthAndOtherHeaders() throws IOException {
request.headers().get("My-Header-2").get(0),
Matchers.equalTo("hello2")
);
MatcherAssert.assertThat(
request.headers().get("User-Agent").get(0),
Matchers.equalTo(
"Self XDSD; https://self-xdsd.com; "
+ "https://github.com/self-xdsd"
)
);
}
}
}

0 comments on commit 91f78db

Please sign in to comment.