|  | @@ -19,35 +19,52 @@
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  package org.elasticsearch.http;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import org.apache.logging.log4j.LogManager;
 | 
	
		
			
				|  |  |  import org.elasticsearch.common.io.stream.StreamInput;
 | 
	
		
			
				|  |  |  import org.elasticsearch.common.io.stream.StreamOutput;
 | 
	
		
			
				|  |  |  import org.elasticsearch.common.io.stream.Writeable;
 | 
	
		
			
				|  |  | +import org.elasticsearch.common.logging.DeprecationLogger;
 | 
	
		
			
				|  |  | +import org.elasticsearch.common.network.InetAddresses;
 | 
	
		
			
				|  |  |  import org.elasticsearch.common.transport.BoundTransportAddress;
 | 
	
		
			
				|  |  | +import org.elasticsearch.common.transport.TransportAddress;
 | 
	
		
			
				|  |  |  import org.elasticsearch.common.unit.ByteSizeValue;
 | 
	
		
			
				|  |  |  import org.elasticsearch.common.xcontent.ToXContentFragment;
 | 
	
		
			
				|  |  |  import org.elasticsearch.common.xcontent.XContentBuilder;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.io.IOException;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import static org.elasticsearch.common.Booleans.parseBoolean;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  public class HttpInfo implements Writeable, ToXContentFragment {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(LogManager.getLogger(HttpInfo.class));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /** Whether to add hostname to publish host field when serializing. */
 | 
	
		
			
				|  |  | +    private static final boolean CNAME_IN_PUBLISH_HOST =
 | 
	
		
			
				|  |  | +        parseBoolean(System.getProperty("es.http.cname_in_publish_address"), false);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      private final BoundTransportAddress address;
 | 
	
		
			
				|  |  |      private final long maxContentLength;
 | 
	
		
			
				|  |  | +    private final boolean cnameInPublishHost;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public HttpInfo(StreamInput in) throws IOException {
 | 
	
		
			
				|  |  | -        address = BoundTransportAddress.readBoundTransportAddress(in);
 | 
	
		
			
				|  |  | -        maxContentLength = in.readLong();
 | 
	
		
			
				|  |  | +        this(BoundTransportAddress.readBoundTransportAddress(in), in.readLong(), CNAME_IN_PUBLISH_HOST);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    @Override
 | 
	
		
			
				|  |  | -    public void writeTo(StreamOutput out) throws IOException {
 | 
	
		
			
				|  |  | -        address.writeTo(out);
 | 
	
		
			
				|  |  | -        out.writeLong(maxContentLength);
 | 
	
		
			
				|  |  | +    public HttpInfo(BoundTransportAddress address, long maxContentLength) {
 | 
	
		
			
				|  |  | +        this(address, maxContentLength, CNAME_IN_PUBLISH_HOST);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    public HttpInfo(BoundTransportAddress address, long maxContentLength) {
 | 
	
		
			
				|  |  | +    HttpInfo(BoundTransportAddress address, long maxContentLength, boolean cnameInPublishHost) {
 | 
	
		
			
				|  |  |          this.address = address;
 | 
	
		
			
				|  |  |          this.maxContentLength = maxContentLength;
 | 
	
		
			
				|  |  | +        this.cnameInPublishHost = cnameInPublishHost;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void writeTo(StreamOutput out) throws IOException {
 | 
	
		
			
				|  |  | +        address.writeTo(out);
 | 
	
		
			
				|  |  | +        out.writeLong(maxContentLength);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      static final class Fields {
 | 
	
	
		
			
				|  | @@ -62,7 +79,21 @@ public class HttpInfo implements Writeable, ToXContentFragment {
 | 
	
		
			
				|  |  |      public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
 | 
	
		
			
				|  |  |          builder.startObject(Fields.HTTP);
 | 
	
		
			
				|  |  |          builder.array(Fields.BOUND_ADDRESS, (Object[]) address.boundAddresses());
 | 
	
		
			
				|  |  | -        builder.field(Fields.PUBLISH_ADDRESS, address.publishAddress().toString());
 | 
	
		
			
				|  |  | +        TransportAddress publishAddress = address.publishAddress();
 | 
	
		
			
				|  |  | +        String publishAddressString = publishAddress.toString();
 | 
	
		
			
				|  |  | +        String hostString = publishAddress.address().getHostString();
 | 
	
		
			
				|  |  | +        if (InetAddresses.isInetAddress(hostString) == false) {
 | 
	
		
			
				|  |  | +            if (cnameInPublishHost) {
 | 
	
		
			
				|  |  | +                publishAddressString = hostString + '/' + publishAddress.toString();
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                DEPRECATION_LOGGER.deprecated(
 | 
	
		
			
				|  |  | +                    "[http.publish_host] was printed as [ip:port] instead of [hostname/ip:port]. "
 | 
	
		
			
				|  |  | +                        + "This format is deprecated and will change to [hostname/ip:port] in a future version. "
 | 
	
		
			
				|  |  | +                        + "Use -Des.http.cname_in_publish_address=true to enforce non-deprecated formatting."
 | 
	
		
			
				|  |  | +                );
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        builder.field(Fields.PUBLISH_ADDRESS, publishAddressString);
 | 
	
		
			
				|  |  |          builder.humanReadableField(Fields.MAX_CONTENT_LENGTH_IN_BYTES, Fields.MAX_CONTENT_LENGTH, maxContentLength());
 | 
	
		
			
				|  |  |          builder.endObject();
 | 
	
		
			
				|  |  |          return builder;
 |