Skip to content

Commit

Permalink
Added "User-Agent" header to requests made to the Lambda Runtime API.
Browse files Browse the repository at this point in the history
The value of the header will be in the format "quarkus/%s-%s" where the first position will be a description of the Java version and the second being the version of Quarkus.
  • Loading branch information
msailes committed Sep 12, 2022
1 parent 0f9413c commit 4068138
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 4068138

Please sign in to comment.