hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: Better header API
Date Tue, 01 Dec 2015 19:48:34 GMT
On Tue, Dec 1, 2015 at 4:07 AM, Michael Osipov <michaelo@apache.org> wrote:

> Am 2015-12-01 um 02:22 schrieb Gary Gregory:
>
>> On Mon, Nov 30, 2015 at 1:43 PM, Michael Osipov <michaelo@apache.org>
>> wrote:
>>
>> Am 2015-11-30 um 19:53 schrieb Gary Gregory:
>>>
>>> I mean:
>>>>
>>>> Index: src/main/java/org/apache/hc/core5/http/HttpMessage.java
>>>> ===================================================================
>>>> --- src/main/java/org/apache/hc/core5/http/HttpMessage.java (revision
>>>> 1717301)
>>>> +++ src/main/java/org/apache/hc/core5/http/HttpMessage.java (working
>>>> copy)
>>>> @@ -55,7 +55,7 @@
>>>>         * @param name the name of the header.
>>>>         * @param value the value of the header.
>>>>         */
>>>> -    void addHeader(String name, String value);
>>>> +    void addHeader(String name, Object value);
>>>>
>>>>        /**
>>>>         * Overwrites the first header with the same name. The new header
>>>> will
>>>> be appended to
>>>> @@ -72,7 +72,7 @@
>>>>         * @param name the name of the header.
>>>>         * @param value the value of the header.
>>>>         */
>>>> -    void setHeader(String name, String value);
>>>> +    void setHeader(String name, Object value);
>>>>
>>>>        /**
>>>>         * Overwrites all the headers in the message.
>>>> Index:
>>>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>>>> ===================================================================
>>>> ---
>>>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>>>> (revision
>>>> 1717301)
>>>> +++
>>>> src/main/java/org/apache/hc/core5/http/message/AbstractHttpMessage.java
>>>> (working
>>>> copy)
>>>> @@ -43,13 +43,13 @@
>>>>        private HttpEntity entity;
>>>>
>>>>        @Override
>>>> -    public void addHeader(final String name, final String value) {
>>>> +    public void addHeader(final String name, final Object value) {
>>>>            Args.notNull(name, "Header name");
>>>>            addHeader(new BasicHeader(name, value));
>>>>        }
>>>>
>>>>        @Override
>>>> -    public void setHeader(final String name, final String value) {
>>>> +    public void setHeader(final String name, final Object value) {
>>>>            Args.notNull(name, "Header name");
>>>>            setHeader(new BasicHeader(name, value));
>>>>        }
>>>> Index: src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>>>> ===================================================================
>>>> --- src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>>>> (revision
>>>> 1717301)
>>>> +++ src/main/java/org/apache/hc/core5/http/message/BasicHeader.java
>>>> (working
>>>> copy)
>>>> @@ -28,6 +28,7 @@
>>>>    package org.apache.hc.core5.http.message;
>>>>
>>>>    import java.io.Serializable;
>>>> +import java.util.Objects;
>>>>
>>>>    import org.apache.hc.core5.annotation.Immutable;
>>>>    import org.apache.hc.core5.http.Header;
>>>> @@ -55,10 +56,10 @@
>>>>         * @param name the header name
>>>>         * @param value the header value
>>>>         */
>>>> -    public BasicHeader(final String name, final String value) {
>>>> +    public BasicHeader(final String name, final Object value) {
>>>>            super();
>>>>            this.name = Args.notNull(name, "Name");
>>>> -        this.value = value;
>>>> +        this.value = Objects.toString(value, null);
>>>>        }
>>>>
>>>>        @Override
>>>>
>>>> Thoughts?
>>>>
>>>>
>>> Gary,
>>>
>>> what benefit do you expect from this patch? If I would read the new code,
>>> I would expect some magic which would auto-convert compatible types to
>>> its
>>> HTTP header counterparts. E.g., numbers, dates, lists, etc.
>>> Which you obviously don't. If you don't plan to add that, you should at
>>> least extend the Javadoc and say you relief the caller from the #toString
>>> burden. No more, no less.
>>>
>>>
>> I have a case now where all I want indeed is to toString() the object
>> passed in. I'm happy to Javadoc it that way if that's OK with everyone.
>>
>
> Please do so.


Done.

Gary

>
>
> Michael
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message