protected void addCookieRequestHeader(HttpState state, HttpConnection conn)
        throws IOException, HttpException {

        LOG.trace("enter HttpMethodBase.addCookieRequestHeader(HttpState, "
                  + "HttpConnection)");

        Header[] cookieheaders = getRequestHeaderGroup().getHeaders("Cookie");
        for (int i = 0; i < cookieheaders.length; i++) {
            Header cookieheader = cookieheaders[i];
            if (cookieheader.isAutogenerated()) {
                getRequestHeaderGroup().removeHeader(cookieheader);
            }
        }

        CookieSpec matcher = getCookieSpec(state);
        String host = this.params.getVirtualHost();
        if (host == null) {
            host = conn.getHost();
        }
        Cookie[] cookies = matcher.match(host, conn.getPort(),
            getPath(), conn.isSecure(), state.getCookies());
        if ((cookies != null) && (cookies.length > 0)) {
            if (getParams().isParameterTrue(HttpMethodParams.SINGLE_COOKIE_HEADER)) {
                // In strict mode put all cookies on the same header
                putAllCookiesInASingleHeader(host, matcher, cookies);
            } else {
                // In non-strict mode put each cookie on a separate header
                for (int i = 0; i < cookies.length; i++) {
                    String s = matcher.formatCookie(cookies[i]);
                    getRequestHeaderGroup().addHeader(new Header(HttpHeader.COOKIE, s, true));
                }
            }
            if (matcher instanceof CookieVersionSupport) {
                CookieVersionSupport versupport = (CookieVersionSupport) matcher;
                int ver = versupport.getVersion();
                boolean needVersionHeader = false;
                for (int i = 0; i < cookies.length; i++) {
                    if (ver != cookies[i].getVersion()) {
                        needVersionHeader = true;
                    }
                }
                if (needVersionHeader) {
                    // Advertise cookie version support
                    getRequestHeaderGroup().addHeader(versupport.getVersionHeader());
                }
            }
        }
    }
protected void addCookieRequestHeader ( HttpState state , HttpConnection conn ) throws IOException , HttpException { LOG . trace ( "enter HttpMethodBase.addCookieRequestHeader(HttpState, " + "HttpConnection)" ) ; Header [ ] cookieheaders = getRequestHeaderGroup ( ) . getHeaders ( "Cookie" ) ; for ( int i = 0 ; i < cookieheaders . length ; i ++ ) { Header cookieheader = cookieheaders [ i ] ; if ( cookieheader . isAutogenerated ( ) ) { getRequestHeaderGroup ( ) . removeHeader ( cookieheader ) ; } } CookieSpec matcher = getCookieSpec ( state ) ; String host = this . params . getVirtualHost ( ) ; if ( host == null ) { host = conn . getHost ( ) ; } Cookie [ ] cookies = matcher . match ( host , conn . getPort ( ) , getPath ( ) , conn . isSecure ( ) , state . getCookies ( ) ) ; if ( ( cookies != null ) && ( cookies . length > 0 ) ) { if ( getParams ( ) . isParameterTrue ( HttpMethodParams . SINGLE_COOKIE_HEADER ) ) { putAllCookiesInASingleHeader ( host , matcher , cookies ) ; } else { for ( int i = 0 ; i < cookies . length ; i ++ ) { String s = matcher . formatCookie ( cookies [ i ] ) ; getRequestHeaderGroup ( ) . addHeader ( new Header ( HttpHeader . COOKIE , s , true ) ) ; } } if ( matcher instanceof CookieVersionSupport ) { CookieVersionSupport versupport = ( CookieVersionSupport ) matcher ; int ver = versupport . getVersion ( ) ; boolean needVersionHeader = false ; for ( int i = 0 ; i < cookies . length ; i ++ ) { if ( ver != cookies [ i ] . getVersion ( ) ) { needVersionHeader = true ; } } if ( needVersionHeader ) { getRequestHeaderGroup ( ) . addHeader ( versupport . getVersionHeader ( ) ) ; } } } }
Generates <tt>Cookie</tt> request headers for those {@link Cookie cookie}s
that match the given host, port and path.

@param state the {@link HttpState state} information associated with this method
@param conn the {@link HttpConnection connection} used to execute
this HTTP method

@throws IOException if an I/O (transport) error occurs. Some transport exceptions
can be recovered from.
@throws HttpException  if a protocol exception occurs. Usually protocol exceptions
cannot be recovered from.