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

Conversation

idelpivnitskiy
Copy link
Member

Motivation:

For easier debugging and visibility of the internal state of the
HttpProtocolConfig implementations and its subcomponents.

Modifications:

  • Implement toString() for DefaultH1ProtocolConfig,
    DefaultH2ProtocolConfig, DefaultHttpHeadersFactory,
    H2HeadersFactory, DefaultKeepAlivePolicy, H1SpecExceptions;

Result:

Users can log intercepted configurations to see what is inside.

Motivation:

For easier debugging and visibility of the internal state of the
`HttpProtocolConfig` implementations and its subcomponents.

Modifications:

- Implement `toString()` for `DefaultH1ProtocolConfig`,
`DefaultH2ProtocolConfig`, `DefaultHttpHeadersFactory`,
`H2HeadersFactory`, `DefaultKeepAlivePolicy`, `H1SpecExceptions`;

Result:

Users can log intercepted configurations to see what is inside.
@idelpivnitskiy idelpivnitskiy self-assigned this Jul 19, 2022

@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
}

@idelpivnitskiy idelpivnitskiy merged commit 639c1b6 into apple:main Jul 20, 2022
@idelpivnitskiy idelpivnitskiy deleted the toString branch July 20, 2022 22:30
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.

2 participants