Skip to content

Commit

Permalink
add default log options to TA and FR (Azure#20914)
Browse files Browse the repository at this point in the history
  • Loading branch information
mssfang authored Apr 23, 2021
1 parent 02b486c commit dc6726a
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.ai.formrecognizer;

import com.azure.ai.formrecognizer.implementation.Constants;
import com.azure.ai.formrecognizer.implementation.FormRecognizerClientImpl;
import com.azure.ai.formrecognizer.implementation.FormRecognizerClientImplBuilder;
import com.azure.core.annotation.ServiceClientBuilder;
Expand Down Expand Up @@ -205,6 +206,15 @@ public FormRecognizerClientBuilder httpLogOptions(HttpLogOptions logOptions) {
return this;
}

/**
* Gets the default Azure Form Recognizer headers and query parameters allow list.
*
* @return The default {@link HttpLogOptions} allow list.
*/
public static HttpLogOptions getDefaultLogOptions() {
return Constants.DEFAULT_LOG_OPTIONS_SUPPLIER.get();
}

/**
* Sets the client options such as application ID and custom headers to set on a request.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.ai.formrecognizer.implementation;

import com.azure.core.http.policy.HttpLogOptions;

import java.util.function.Supplier;

public class Constants {

public static final Supplier<HttpLogOptions> DEFAULT_LOG_OPTIONS_SUPPLIER = () -> {
HttpLogOptions logOptions = new HttpLogOptions();

logOptions.addAllowedHeaderName("Operation-Location");
logOptions.addAllowedHeaderName("Location");
logOptions.addAllowedHeaderName("x-envoy-upstream-service-time");
logOptions.addAllowedHeaderName("apim-request-id");
logOptions.addAllowedHeaderName("Strict-Transport-Security");
logOptions.addAllowedHeaderName("x-content-type-options");
logOptions.addAllowedHeaderName("ms-azure-ai-errorcode");
logOptions.addAllowedHeaderName("x-ms-cs-error-code");

logOptions.addAllowedQueryParamName("includeTextDetails");
logOptions.addAllowedQueryParamName("locale");
logOptions.addAllowedQueryParamName("language");
logOptions.addAllowedQueryParamName("includeKeys");
logOptions.addAllowedQueryParamName("op");
logOptions.addAllowedQueryParamName("pages");
logOptions.addAllowedQueryParamName("readingOrder");

return logOptions;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package com.azure.ai.textanalytics;

import com.azure.ai.textanalytics.implementation.Constants;
import com.azure.ai.textanalytics.implementation.TextAnalyticsClientImpl;
import com.azure.ai.textanalytics.implementation.TextAnalyticsClientImplBuilder;
import com.azure.core.annotation.ServiceClientBuilder;
Expand Down Expand Up @@ -301,6 +302,15 @@ public TextAnalyticsClientBuilder httpLogOptions(HttpLogOptions logOptions) {
return this;
}

/**
* Gets the default Azure Text Analytics headers and query parameters allow list.
*
* @return The default {@link HttpLogOptions} allow list.
*/
public static HttpLogOptions getDefaultLogOptions() {
return Constants.DEFAULT_LOG_OPTIONS_SUPPLIER.get();
}

/**
* Sets the client options such as application ID and custom headers to set on a request.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.ai.textanalytics.implementation;

import com.azure.core.http.policy.HttpLogOptions;

import java.util.function.Supplier;

public class Constants {

public static final Supplier<HttpLogOptions> DEFAULT_LOG_OPTIONS_SUPPLIER = () -> {
HttpLogOptions logOptions = new HttpLogOptions();

logOptions.addAllowedHeaderName("Operation-Location");
logOptions.addAllowedHeaderName("x-envoy-upstream-service-time");
logOptions.addAllowedHeaderName("apim-request-id");
logOptions.addAllowedHeaderName("Strict-Transport-Security");
logOptions.addAllowedHeaderName("x-content-type-options");

logOptions.addAllowedQueryParamName("jobId");
logOptions.addAllowedQueryParamName("$top");
logOptions.addAllowedQueryParamName("$skip");
logOptions.addAllowedQueryParamName("showStats");
logOptions.addAllowedQueryParamName("model-version");
logOptions.addAllowedQueryParamName("domain");
logOptions.addAllowedQueryParamName("stringIndexType");
logOptions.addAllowedQueryParamName("piiCategories");
logOptions.addAllowedQueryParamName("opinionMining");

return logOptions;
};
}

0 comments on commit dc6726a

Please sign in to comment.