Skip to content

Commit

Permalink
- fixes indent
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
  • Loading branch information
baywet committed Aug 14, 2023
1 parent 36d2a8a commit f12e357
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@
* The middleware responsible for inspecting the request and response headers
*/
public class HeadersInspectionHandler implements Interceptor {
/**
* Create a new instance of the HeadersInspectionHandler class with the default options
*/
public HeadersInspectionHandler() {
this(new HeadersInspectionOption());
}
/**
* Create a new instance of the HeadersInspectionHandler class with the provided options
* @param options The options to use for the handler
*/
public HeadersInspectionHandler(@Nonnull final HeadersInspectionOption options) {
this.options = Objects.requireNonNull(options);
}
private final HeadersInspectionOption options;
/**
* Create a new instance of the HeadersInspectionHandler class with the default options
*/
public HeadersInspectionHandler() {
this(new HeadersInspectionOption());
}
/**
* Create a new instance of the HeadersInspectionHandler class with the provided options
* @param options The options to use for the handler
*/
public HeadersInspectionHandler(@Nonnull final HeadersInspectionOption options) {
this.options = Objects.requireNonNull(options);
}
private final HeadersInspectionOption options;

/** {@inheritDoc} */
@Nonnull
@Override
@SuppressWarnings("UnknownNullness")
public Response intercept(final Chain chain) throws IOException {
@Override
@SuppressWarnings("UnknownNullness")
public Response intercept(final Chain chain) throws IOException {
Objects.requireNonNull(chain, "parameter chain cannot be null");
Request request = chain.request();
HeadersInspectionOption inspectionOption = request.tag(HeadersInspectionOption.class);
if(inspectionOption == null) { inspectionOption = options; }
Request request = chain.request();
HeadersInspectionOption inspectionOption = request.tag(HeadersInspectionOption.class);
if(inspectionOption == null) { inspectionOption = options; }
final Span span = ObservabilityHelper.getSpanForRequest(request, "HeadersInspectionHandler_Intercept");
Scope scope = null;
if (span != null) {
Expand All @@ -54,18 +54,18 @@ public Response intercept(final Chain chain) throws IOException {
if (span != null) {
request = request.newBuilder().tag(Span.class, span).build();
}
if (inspectionOption.getInspectRequestHeaders()) {
for(final Pair<? extends String, ? extends String> header : request.headers()) {
inspectionOption.getRequestHeaders().put(header.getFirst(), Set.of(header.getSecond()));
}
}
if (inspectionOption.getInspectRequestHeaders()) {
for(final Pair<? extends String, ? extends String> header : request.headers()) {
inspectionOption.getRequestHeaders().put(header.getFirst(), Set.of(header.getSecond()));
}
}
final Response response = chain.proceed(request);
if (inspectionOption.getInspectResponseHeaders()) {
for(final Pair<? extends String, ? extends String> header : response.headers()) {
inspectionOption.getResponseHeaders().put(header.getFirst(), Set.of(header.getSecond()));
}
}
return response;
if (inspectionOption.getInspectResponseHeaders()) {
for(final Pair<? extends String, ? extends String> header : response.headers()) {
inspectionOption.getResponseHeaders().put(header.getFirst(), Set.of(header.getSecond()));
}
}
return response;
} finally {
if (scope != null) {
scope.close();
Expand All @@ -74,6 +74,6 @@ public Response intercept(final Chain chain) throws IOException {
span.end();
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,78 +10,78 @@
* The options to be passed to the headers inspection middleware.
*/
public class HeadersInspectionOption implements RequestOption {
private boolean inspectRequestHeaders;
/**
* Gets whether to inspect request headers
* @return Whether to inspect request headers
*/
public boolean getInspectRequestHeaders() {
return inspectRequestHeaders;
}
/**
* Sets whether to inspect request headers
* @param inspectRequestHeaders Whether to inspect request headers
*/
public void setInspectRequestHeaders(boolean inspectRequestHeaders) {
this.inspectRequestHeaders = inspectRequestHeaders;
}
private boolean inspectRequestHeaders;
/**
* Gets whether to inspect request headers
* @return Whether to inspect request headers
*/
public boolean getInspectRequestHeaders() {
return inspectRequestHeaders;
}
/**
* Sets whether to inspect request headers
* @param inspectRequestHeaders Whether to inspect request headers
*/
public void setInspectRequestHeaders(boolean inspectRequestHeaders) {
this.inspectRequestHeaders = inspectRequestHeaders;
}

private boolean inspectResponseHeaders;
/**
* Gets whether to inspect response headers
* @return Whether to inspect response headers
*/
public boolean getInspectResponseHeaders() {
return inspectResponseHeaders;
}
/**
* Sets whether to inspect response headers
* @param inspectResponseHeaders Whether to inspect response headers
*/
public void setInspectResponseHeaders(boolean inspectResponseHeaders) {
this.inspectResponseHeaders = inspectResponseHeaders;
}
private boolean inspectResponseHeaders;
/**
* Gets whether to inspect response headers
* @return Whether to inspect response headers
*/
public boolean getInspectResponseHeaders() {
return inspectResponseHeaders;
}
/**
* Sets whether to inspect response headers
* @param inspectResponseHeaders Whether to inspect response headers
*/
public void setInspectResponseHeaders(boolean inspectResponseHeaders) {
this.inspectResponseHeaders = inspectResponseHeaders;
}

private final RequestHeaders requestHeaders = new RequestHeaders();
private final ResponseHeaders responseHeaders = new ResponseHeaders();
/**
* Create default instance of headers inspection options, with default values of inspectRequestHeaders and inspectResponseHeaders.
*/
public HeadersInspectionOption() {
this(false, false);
}
/**
* Create an instance with provided values
* @param shouldInspectResponseHeaders Whether to inspect response headers
* @param shouldInspectRequestHeaders Whether to inspect request headers
*/
public HeadersInspectionOption(final boolean shouldInspectRequestHeaders, final boolean shouldInspectResponseHeaders) {
this.inspectResponseHeaders = shouldInspectResponseHeaders;
this.inspectRequestHeaders = shouldInspectRequestHeaders;
}
/**
* Get the request headers
* @return The request headers
*/
@Nonnull
public RequestHeaders getRequestHeaders() {
return this.requestHeaders;
}
/**
* Get the response headers
* @return The response headers
*/
@Nonnull
public ResponseHeaders getResponseHeaders() {
return this.responseHeaders;
}
private final RequestHeaders requestHeaders = new RequestHeaders();
private final ResponseHeaders responseHeaders = new ResponseHeaders();
/**
* Create default instance of headers inspection options, with default values of inspectRequestHeaders and inspectResponseHeaders.
*/
public HeadersInspectionOption() {
this(false, false);
}
/**
* Create an instance with provided values
* @param shouldInspectResponseHeaders Whether to inspect response headers
* @param shouldInspectRequestHeaders Whether to inspect request headers
*/
public HeadersInspectionOption(final boolean shouldInspectRequestHeaders, final boolean shouldInspectResponseHeaders) {
this.inspectResponseHeaders = shouldInspectResponseHeaders;
this.inspectRequestHeaders = shouldInspectRequestHeaders;
}
/**
* Get the request headers
* @return The request headers
*/
@Nonnull
public RequestHeaders getRequestHeaders() {
return this.requestHeaders;
}
/**
* Get the response headers
* @return The response headers
*/
@Nonnull
public ResponseHeaders getResponseHeaders() {
return this.responseHeaders;
}

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
@Nonnull
public <T extends RequestOption> Class<T> getType() {
public <T extends RequestOption> Class<T> getType() {
return (Class<T>) HeadersInspectionOption.class;
}
}
}

0 comments on commit f12e357

Please sign in to comment.