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

Implement toString() for HttpProtocolConfig and its components #2281

Merged
merged 2 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -85,4 +85,15 @@ public boolean validateCookies() {
public boolean validateValues() {
return validateValues;
}

@Override
public String toString() {
return "DefaultHttpHeadersFactory{" +
Copy link
Contributor

Choose a reason for hiding this comment

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

I usually use this.getClass().getSimpleName() so that the result is correct even for sub-classes that do not override. For final classes I end up using the same pattern for consistency and so that I don't have to change it if the class is refactored, becomes non-final, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, I've adjusted my Intellij IDEA template for generating toString() methods:

public java.lang.String toString() {
#if ( $members.size() > 0 )
#set ( $i = 0 )
    return getClass().getSimpleName() +
#foreach( $member in $members )
#if ( $i == 0 )
    "{##
#else
    ", ##
#end
#if ( $member.objectArray )
#if ($java_version < 5)
$member.name=" + ($member.accessor == null ? null : java.util.Arrays.asList($member.accessor)) +
#else
$member.name=" + java.util.Arrays.toString($member.accessor) +
#end
#elseif ( $member.primitiveArray && $java_version >= 5)
$member.name=" + java.util.Arrays.toString($member.accessor) +
#elseif ( $member.string )
$member.name='" + $member.accessor + '\'' +
#else
$member.name=" + $member.accessor +
#end
#set ( $i = $i + 1 )
#end
    '}';
#else
    return getClass().getSimpleName() + "{}";
#end
}

"validateNames=" + validateNames +
", validateCookies=" + validateCookies +
", validateValues=" + validateValues +
", headersArraySizeHint=" + headersArraySizeHint +
", trailersArraySizeHint=" + trailersArraySizeHint +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © 2020 Apple Inc. and the ServiceTalk project authors
* Copyright © 2020, 2022 Apple Inc. and the ServiceTalk project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,4 +46,13 @@ public Duration ackTimeout() {
public boolean withoutActiveStreams() {
return withoutActiveStreams;
}

@Override
public String toString() {
return "DefaultKeepAlivePolicy{" +
"idleDuration=" + idleDuration +
", ackTimeout=" + ackTimeout +
", withoutActiveStreams=" + withoutActiveStreams +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,19 @@ public int trailersEncodedSizeEstimate() {
public H1SpecExceptions specExceptions() {
return specExceptions;
}

@Override
public String toString() {
return "DefaultH1ProtocolConfig{" +
"alpnId=" + alpnId() +
", headersFactory=" + headersFactory +
", maxPipelinedRequests=" + maxPipelinedRequests +
", maxStartLineLength=" + maxStartLineLength +
", maxHeaderFieldLength=" + maxHeaderFieldLength +
", headersEncodedSizeEstimate=" + headersEncodedSizeEstimate +
", trailersEncodedSizeEstimate=" + trailersEncodedSizeEstimate +
", specExceptions=" + specExceptions +
'}';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ public boolean allowLFWithoutCR() {
return allowLFWithoutCR;
}

@Override
public String toString() {
return "H1SpecExceptions{" +
"allowPrematureClosureBeforePayloadBody=" + allowPrematureClosureBeforePayloadBody +
", allowLFWithoutCR=" + allowLFWithoutCR +
'}';
}

/**
* Builder for {@link H1SpecExceptions}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import io.netty.handler.codec.http2.DefaultHttp2Headers;

import java.util.function.BiPredicate;

/**
* A {@link HttpHeadersFactory} optimized for HTTP/2.
*/
Expand All @@ -30,8 +28,6 @@ public final class H2HeadersFactory implements HttpHeadersFactory {
private static final boolean DEFAULT_VALIDATE_VALUES = false;
public static final HttpHeadersFactory INSTANCE = new H2HeadersFactory(true, true, DEFAULT_VALIDATE_VALUES);

static final BiPredicate<CharSequence, CharSequence> DEFAULT_SENSITIVITY_DETECTOR = (name, value) -> false;

private final boolean validateNames;
private final boolean validateCookies;
private final boolean validateValues;
Expand Down Expand Up @@ -96,4 +92,15 @@ public boolean validateCookies() {
public boolean validateValues() {
return validateValues;
}

@Override
public String toString() {
return "H2HeadersFactory{" +
"validateNames=" + validateNames +
", validateCookies=" + validateCookies +
", validateValues=" + validateValues +
", headersArraySizeHint=" + headersArraySizeHint +
", trailersArraySizeHint=" + trailersArraySizeHint +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.function.BooleanSupplier;
import javax.annotation.Nullable;

import static io.servicetalk.http.netty.H2HeadersFactory.DEFAULT_SENSITIVITY_DETECTOR;
import static io.servicetalk.http.netty.H2KeepAlivePolicies.DISABLE_KEEP_ALIVE;
import static java.util.Objects.requireNonNull;

Expand All @@ -37,6 +36,8 @@
*/
public final class H2ProtocolConfigBuilder {

private static final BiPredicate<CharSequence, CharSequence> DEFAULT_SENSITIVITY_DETECTOR = (name, value) -> false;

private HttpHeadersFactory headersFactory = H2HeadersFactory.INSTANCE;
private BiPredicate<CharSequence, CharSequence> headersSensitivityDetector = DEFAULT_SENSITIVITY_DETECTOR;
@Nullable
Expand Down Expand Up @@ -152,5 +153,17 @@ public UserDataLoggerConfig frameLoggerConfig() {
public KeepAlivePolicy keepAlivePolicy() {
return keepAlivePolicy;
}

@Override
public String toString() {
return "DefaultH2ProtocolConfig{" +
"alpnId=" + alpnId() +
", headersFactory=" + headersFactory +
", headersSensitivityDetector=" + (headersSensitivityDetector == DEFAULT_SENSITIVITY_DETECTOR ?
"DEFAULT_SENSITIVITY_DETECTOR" : headersSensitivityDetector.toString()) +
", frameLoggerConfig=" + frameLoggerConfig +
", keepAlivePolicy=" + keepAlivePolicy +
'}';
}
}
}