Skip to content
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

Added "User-Agent" header to requests made to the Lambda Runtime API #21458

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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