[ 
https://issues.apache.org/jira/browse/WAGON-432?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14482904#comment-14482904
 ] 

Michael Osipov commented on WAGON-432:
--------------------------------------

Hi Jason,

here analysis:

Back then in July 2014 I made an analysis of the AbstractHttpClientWagon 
regarding header handling and it is a mess. I did not create another ticket 
(which I should have done actually) just because I did not have any time to 
work on. Header definitions are spread over several maps/config elements, 
headers are set which cannot be set by a client at all and headers are set 
multiple times.

1. If you take a look at the setHeaders method. You'll see that non-sense 
headers are set, merged from zillion sources and always with an 'add', so you 
cannot even override them. Including deprecated fields.

2. getUserAgent: it uses several sources as well...

3. execute: setMethod is called which does already set the User-Agent and the 
explicit setHeader method might be called.


Now the problem is that setHeaders(Properties) is called once from Aether Wagon 
Transporter correctly and triggers execute. See screenshot 
headergroup-before-execution.png. Stepping into setHeaders(HttpUriRequest) 
triggers config.isUseDefaultHeaders() which in turn performs method.addHeader( 
"User-Agent", DEFAULT_USER_AGENT );.
So far headergroup looks here "[Cache-control: no-cache, Cache-store: no-store, 
Pragma: no-cache, Expires: 0, Accept-Encoding: gzip, User-Agent: 
Apache-Maven-Wagon/2.8 (Java 1.7.0_71; ]".

httpHeaders are copied into the request. The former has 
{User-Agent=Apache-Maven/3.2.5 (Java 1.7.0_71; Windows XP 5.1)}.

We do have two headers in the request: User-Agent: Apache-Maven-Wagon/2.8 (Java 
1.7.0_71; , User-Agent: Apache-Maven/3.2.5 (Java 1.7.0_71; Windows XP 5.1)]. 
See headergroup-after-setHeaders.png.

Now lets execute getUserAgent and the if clause: the Wagon header is gone but 
Maven is twice. See headergroup-after-setUserAgent.png.

You might think now that #setHeader from HttpCore should do the magic but it 
doesn't. Javadocs say: "Overwrites the first header with the same name. The new 
header will be appended to the end of the list, if no header with the given 
name can be found."

Now it should be clear. The mess with the header code in 
AbstractHttpClientWagon and the lack of reading the Javadoc lead to that bug.

Wether the behavior from HttpCore is reasonable or not should be discussed with 
Oleg Kalnichevski on the HttpComponents users mailing list, personally the 
behavior is surprising to me and always requires a removeHeaders but this 
probably won't change before version 5.0.

I hope this helps.

Michael

> Maven sends duplicate User-Agent header
> ---------------------------------------
>
>                 Key: WAGON-432
>                 URL: https://issues.apache.org/jira/browse/WAGON-432
>             Project: Maven Wagon
>          Issue Type: Bug
>          Components: wagon-http
>    Affects Versions: 2.8
>            Reporter: Michael Osipov
>            Priority: Minor
>         Attachments: maven-3.1.1.png, maven-3.2.2.png
>
>
> Maven 3.1.1 sends only one {{User-Agent}} header, 3.2.2 sends twice. See 
> screenshots.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to