Skip to content

Commit

Permalink
Merge pull request quarkusio#21458 from msailes/add-user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
cescoffier authored Sep 12, 2022
2 parents deec600 + 4068138 commit fc5d630
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
public abstract class AbstractLambdaPollLoop {
private static final Logger log = Logger.getLogger(AbstractLambdaPollLoop.class);

private static final String USER_AGENT = "User-Agent";
private static final String USER_AGENT_VALUE = String.format(
"quarkus/%s-%s",
System.getProperty("java.vendor.version"),
AbstractLambdaPollLoop.class.getPackage().getImplementationVersion());

private final ObjectMapper objectMapper;
private final ObjectReader cognitoIdReader;
private final ObjectReader clientCtxReader;
Expand Down Expand Up @@ -71,6 +77,7 @@ public void run() {

try {
requestConnection = (HttpURLConnection) requestUrl.openConnection();
requestConnection.setRequestProperty(USER_AGENT, USER_AGENT_VALUE);
} catch (IOException e) {
if (!running.get()) {
// just return gracefully as we were probably shut down by
Expand Down Expand Up @@ -232,6 +239,7 @@ private void checkQuarkusBootstrapped() {

protected void postResponse(URL url, Object response) throws IOException {
HttpURLConnection responseConnection = (HttpURLConnection) url.openConnection();
responseConnection.setRequestProperty(USER_AGENT, USER_AGENT_VALUE);
if (response != null) {
getOutputWriter().writeHeaders(responseConnection);
}
Expand All @@ -248,6 +256,7 @@ protected void postResponse(URL url, Object response) throws IOException {
protected void requeue(String baseUrl, String requestId) throws IOException {
URL url = AmazonLambdaApi.requeue(baseUrl, requestId);
HttpURLConnection responseConnection = (HttpURLConnection) url.openConnection();
responseConnection.setRequestProperty(USER_AGENT, USER_AGENT_VALUE);
responseConnection.setDoOutput(true);
responseConnection.setRequestMethod("POST");
while (responseConnection.getInputStream().read() != -1) {
Expand All @@ -257,6 +266,7 @@ protected void requeue(String baseUrl, String requestId) throws IOException {

protected void postError(URL url, Object response) throws IOException {
HttpURLConnection responseConnection = (HttpURLConnection) url.openConnection();
responseConnection.setRequestProperty(USER_AGENT, USER_AGENT_VALUE);
responseConnection.setRequestProperty("Content-Type", "application/json");
responseConnection.setDoOutput(true);
responseConnection.setRequestMethod("POST");
Expand All @@ -268,6 +278,7 @@ protected void postError(URL url, Object response) throws IOException {

protected HttpURLConnection responseStream(URL url) throws IOException {
HttpURLConnection responseConnection = (HttpURLConnection) url.openConnection();
responseConnection.setRequestProperty(USER_AGENT, USER_AGENT_VALUE);
responseConnection.setDoOutput(true);
responseConnection.setRequestMethod("POST");
return responseConnection;
Expand Down

0 comments on commit fc5d630

Please sign in to comment.