Skip to content

Add default set of headers to be white listed for logging#5893

Merged
samvaity merged 3 commits into
Azure:masterfrom
samvaity:whitelist-headers
Oct 17, 2019
Merged

Add default set of headers to be white listed for logging#5893
samvaity merged 3 commits into
Azure:masterfrom
samvaity:whitelist-headers

Conversation

@samvaity

Copy link
Copy Markdown
Member

Reference: #5890

*/
public HttpLogOptions setAllowedHeaderNames(final Set<String> allowedHeaderNames) {
this.allowedHeaderNames = allowedHeaderNames;
this.allowedHeaderNames = allowedHeaderNames == null ? this.allowedHeaderNames : allowedHeaderNames;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If they pass in null, just have that clear out the whitelist.

*/
public HttpLogOptions setAllowedHeaderNames(final Set<String> allowedHeaderNames) {
this.allowedHeaderNames = allowedHeaderNames;
this.allowedHeaderNames = allowedHeaderNames == null ? this.allowedHeaderNames : allowedHeaderNames;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should there be a convenience API to remove headers too? Because in most cases, users just want to redact one or two headers from the default set that may contain sensitive info.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be done via getAllowedHeaderNames().remove(..), so we don't need a convenience API.

*/
public HttpLogOptions setAllowedHeaderNames(final Set<String> allowedHeaderNames) {
this.allowedHeaderNames = allowedHeaderNames;
this.allowedHeaderNames = allowedHeaderNames == null ? this.allowedHeaderNames : allowedHeaderNames;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On line 75 and 114: Should we return an immutable copy of the HashSet instead of returning the reference to the HashSet this class uses? If we return the reference, then user can add/delete to the original set outside of this class.

public HttpLogOptions() {
logLevel = HttpLogDetailLevel.NONE;
allowedHeaderNames = new HashSet<>();
allowedHeaderNames = new HashSet<>(Arrays.asList(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Extract the Arrays.asList() into a static field and reuse. Don't have to create a list and a hashset each time an instance of HttpLogOptions is created.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I partially agree. The Arrays.asList(...) call can be a private static final field, but there should be a new set per instance, so that it can be modified via the API.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated

if (!allowedHeaderNames.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (HttpHeader header : requestResponseHeaders) {
sb.append(header.getName()).append(":");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be case insensitive

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

openapi-bot-ppe Bot pushed a commit to test-repo-billy/azure-sdk-for-java that referenced this pull request Oct 18, 2019
openapi-bot-ppe Bot pushed a commit to test-repo-billy/azure-sdk-for-java that referenced this pull request Oct 18, 2019
openapi-bot-ppe Bot pushed a commit to test-repo-billy/azure-sdk-for-java that referenced this pull request Oct 18, 2019
openapi-bot-ppe Bot pushed a commit to test-repo-billy/azure-sdk-for-java that referenced this pull request Oct 18, 2019
openapi-bot-ppe Bot pushed a commit to test-repo-billy/azure-sdk-for-java that referenced this pull request Oct 18, 2019
@samvaity
samvaity deleted the whitelist-headers branch September 17, 2020 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants