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

fix: Populate AWSProxyResponse headers with multi #1338

Open
wants to merge 8 commits into
base: 5.0.x
Choose a base branch
from

Conversation

sdelamo
Copy link
Contributor

@sdelamo sdelamo commented Apr 4, 2022

Fixes: #1330

@sonarcloud
Copy link

sonarcloud bot commented Apr 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

86.7% 86.7% Coverage
0.0% 0.0% Duplication

@sdelamo sdelamo marked this pull request as ready for review September 6, 2022 11:26
@sdelamo sdelamo marked this pull request as draft September 6, 2022 11:26
@sdelamo sdelamo marked this pull request as ready for review November 17, 2022 05:32
@sonarcloud
Copy link

sonarcloud bot commented Nov 17, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

86.7% 86.7% Coverage
0.0% 0.0% Duplication


private static Map<String, String> getHeaders(AwsProxyResponse awsProxyResponse) {
Headers multiValueHeaders = awsProxyResponse.getMultiValueHeaders();
Map<String, String> headers = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a linked hash map to retain order

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved via 0f624cb

Map<String, String> headers = new HashMap<>();
for (Map.Entry<String, List<String>> entry : multiValueHeaders.entrySet()) {
List<String> headerValues = entry.getValue();
if (headerValues != null && headerValues.size() == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use iterator.hasNext() and iterator.next() instead of calling size() and get(0) which is less efficient

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check: No headers will be added if the size > 1, is this intended?

suggestion: Try this instead headerValues.stream().first().ifPresent(value -> headers.put(entry.getKey(), value));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved via 52b852e

@sdelamo sdelamo changed the base branch from master to 3.16.x April 5, 2023 16:25
@sdelamo sdelamo changed the base branch from 3.16.x to master April 5, 2023 16:25
…/proxy/MicronautResponseWriter.java

Co-authored-by: Thobias Karlsson <thobias.karlsson@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Lamba Proxy does not populate response headers correctly
3 participants