⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cookiespecbase.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="576" href="#576">576</a> <em>     * If the SortedMap comes from an HttpState and is not itself</em><a name="577" href="#577">577</a> <em>     * thread-safe, it may be necessary to synchronize on the HttpState</em><a name="578" href="#578">578</a> <em>     * instance to protect against concurrent modification. </em><a name="579" href="#579">579</a> <em>     *</em><a name="580" href="#580">580</a> <em>     * @param host the host to which the request is being submitted</em><a name="581" href="#581">581</a> <em>     * @param port the port to which the request is being submitted (currently</em><a name="582" href="#582">582</a> <em>     * ignored)</em><a name="583" href="#583">583</a> <em>     * @param path the path to which the request is being submitted</em><a name="584" href="#584">584</a> <em>     * @param secure &lt;tt>true&lt;/tt> if the request is using a secure protocol</em><a name="585" href="#585">585</a> <em>     * @param cookies SortedMap of &lt;tt>Cookie&lt;/tt>s to be matched</em><a name="586" href="#586">586</a> <em>     * @return an array of &lt;tt>Cookie&lt;/tt>s matching the criterium</em><a name="587" href="#587">587</a> <em>     */</em><a name="588" href="#588">588</a> <a name="589" href="#589">589</a>     <strong>public</strong> <a href="../../../../../org/apache/commons/httpclient/Cookie.html">Cookie</a>[] match(String host, <strong>int</strong> port, String path, <a name="590" href="#590">590</a>         <strong>boolean</strong> secure, <strong>final</strong> SortedMap cookies) {<a name="591" href="#591">591</a>             <a name="592" href="#592">592</a>         LOG.trace(<span class="string">"enter CookieSpecBase.match("</span><a name="593" href="#593">593</a>            + <span class="string">"String, int, String, boolean, SortedMap)"</span>);<a name="594" href="#594">594</a> <a name="595" href="#595">595</a>         <em class="comment">// TODO: skip meaningless 'narrowing' when host is a numeric IP</em><a name="596" href="#596">596</a>         <em class="comment">// (harmless in the meantime)</em><a name="597" href="#597">597</a>         <a name="598" href="#598">598</a>         <strong>if</strong> (cookies == <strong>null</strong>) {<a name="599" href="#599">599</a>             <strong>return</strong> <strong>null</strong>;<a name="600" href="#600">600</a>         }<a name="601" href="#601">601</a>         List matching = <strong>new</strong> LinkedList();<a name="602" href="#602">602</a>         String narrowHost = host;<a name="603" href="#603">603</a>         <strong>do</strong> {<a name="604" href="#604">604</a>             Iterator iter = cookies.subMap(narrowHost,<a name="605" href="#605">605</a>                     narrowHost + Cookie.DOMAIN_OVERBOUNDS).values().iterator();<a name="606" href="#606">606</a>             <strong>while</strong> (iter.hasNext()) {<a name="607" href="#607">607</a>                 <a href="../../../../../org/apache/commons/httpclient/Cookie.html">Cookie</a> cookie = (Cookie) (iter.next());<a name="608" href="#608">608</a>                 <strong>if</strong> (match(host, port, path, secure, cookie)) {<a name="609" href="#609">609</a>                     addInPathOrder(matching, cookie);<a name="610" href="#610">610</a>                 }<a name="611" href="#611">611</a>             }<a name="612" href="#612">612</a>             StoredIterator.close(iter);<a name="613" href="#613">613</a>             <strong>int</strong> trimTo = narrowHost.indexOf('.', 1);<a name="614" href="#614">614</a>             narrowHost = (trimTo &lt; 0) ? <strong>null</strong> : narrowHost.substring(trimTo+1);<a name="615" href="#615">615</a>         } <strong>while</strong> (narrowHost != <strong>null</strong>);<a name="616" href="#616">616</a> <a name="617" href="#617">617</a>         <strong>return</strong> (Cookie[]) matching.toArray(<strong>new</strong> Cookie[matching.size()]); <a name="618" href="#618">618</a>     }<a name="619" href="#619">619</a> <em class="comment">//  END IA CHANGES</em><a name="620" href="#620">620</a>     <a name="621" href="#621">621</a>     <em>/**<em>*</em></em><a name="622" href="#622">622</a> <em>     * Adds the given cookie into the given list in descending path order. That</em><a name="623" href="#623">623</a> <em>     * is, more specific path to least specific paths.  This may not be the</em><a name="624" href="#624">624</a> <em>     * fastest algorythm, but it'll work OK for the small number of cookies</em><a name="625" href="#625">625</a> <em>     * we're generally dealing with.</em><a name="626" href="#626">626</a> <em>     *</em><a name="627" href="#627">627</a> <em>     * @param list - the list to add the cookie to</em><a name="628" href="#628">628</a> <em>     * @param addCookie - the Cookie to add to list</em><a name="629" href="#629">629</a> <em>     */</em><a name="630" href="#630">630</a>     <strong>private</strong> <strong>static</strong> <strong>void</strong> addInPathOrder(List list, <a href="../../../../../org/apache/commons/httpclient/Cookie.html">Cookie</a> addCookie) {<a name="631" href="#631">631</a>         <strong>int</strong> i = 0;<a name="632" href="#632">632</a> <a name="633" href="#633">633</a>         <strong>for</strong> (i = 0; i &lt; list.size(); i++) {<a name="634" href="#634">634</a>             <a href="../../../../../org/apache/commons/httpclient/Cookie.html">Cookie</a> c = (Cookie) list.get(i);<a name="635" href="#635">635</a>             <strong>if</strong> (addCookie.compare(addCookie, c) > 0) {<a name="636" href="#636">636</a>                 <strong>break</strong>;<a name="637" href="#637">637</a>             }<a name="638" href="#638">638</a>         }<a name="639" href="#639">639</a>         list.add(i, addCookie);<a name="640" href="#640">640</a>     }<a name="641" href="#641">641</a> <a name="642" href="#642">642</a>     <em>/**<em>*</em></em><a name="643" href="#643">643</a> <em>     * Return a string suitable for sending in a &lt;tt>"Cookie"&lt;/tt> header</em><a name="644" href="#644">644</a> <em>     * @param cookie a {@link Cookie} to be formatted as string</em><a name="645" href="#645">645</a> <em>     * @return a string suitable for sending in a &lt;tt>"Cookie"&lt;/tt> header.</em><a name="646" href="#646">646</a> <em>     */</em><a name="647" href="#647">647</a>     <strong>public</strong> String formatCookie(<a href="../../../../../org/apache/commons/httpclient/Cookie.html">Cookie</a> cookie) {<a name="648" href="#648">648</a>         LOG.trace(<span class="string">"enter CookieSpecBase.formatCookie(Cookie)"</span>);<a name="649" href="#649">649</a>         <strong>if</strong> (cookie == <strong>null</strong>) {<a name="650" href="#650">650</a>             <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"Cookie may not be null"</span>);<a name="651" href="#651">651</a>         }<a name="652" href="#652">652</a>         StringBuffer buf = <strong>new</strong> StringBuffer();<a name="653" href="#653">653</a>         buf.append(cookie.getName());<a name="654" href="#654">654</a>         buf.append(<span class="string">"="</span>);<a name="655" href="#655">655</a>         String s = cookie.getValue();<a name="656" href="#656">656</a>         <strong>if</strong> (s != <strong>null</strong>) {<a name="657" href="#657">657</a>             buf.append(s);<a name="658" href="#658">658</a>         }<a name="659" href="#659">659</a>         <strong>return</strong> buf.toString();<a name="660" href="#660">660</a>     }<a name="661" href="#661">661</a> <a name="662" href="#662">662</a>     <em>/**<em>*</em></em><a name="663" href="#663">663</a> <em>     * Create a &lt;tt>"Cookie"&lt;/tt> header value containing all {@link Cookie}s in</em><a name="664" href="#664">664</a> <em>     * &lt;i>cookies&lt;/i> suitable for sending in a &lt;tt>"Cookie"&lt;/tt> header</em><a name="665" href="#665">665</a> <em>     * @param cookies an array of {@link Cookie}s to be formatted</em><a name="666" href="#666">666</a> <em>     * @return a string suitable for sending in a Cookie header.</em><a name="667" href="#667">667</a> <em>     * @throws IllegalArgumentException if an input parameter is illegal</em><a name="668" href="#668">668</a> <em>     */</em><a name="669" href="#669">669</a> <a name="670" href="#670">670</a>     <strong>public</strong> String formatCookies(<a href="../../../../../org/apache/commons/httpclient/Cookie.html">Cookie</a>[] cookies)<a name="671" href="#671">671</a>       throws IllegalArgumentException {<a name="672" href="#672">672</a>         LOG.trace(<span class="string">"enter CookieSpecBase.formatCookies(Cookie[])"</span>);<a name="673" href="#673">673</a>         <strong>if</strong> (cookies == <strong>null</strong>) {<a name="674" href="#674">674</a>             <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"Cookie array may not be null"</span>);<a name="675" href="#675">675</a>         }<a name="676" href="#676">676</a>         <strong>if</strong> (cookies.length == 0) {<a name="677" href="#677">677</a>             <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"Cookie array may not be empty"</span>);<a name="678" href="#678">678</a>         }<a name="679" href="#679">679</a> <a name="680" href="#680">680</a>         StringBuffer buffer = <strong>new</strong> StringBuffer();<a name="681" href="#681">681</a>         <strong>for</strong> (<strong>int</strong> i = 0; i &lt; cookies.length; i++) {<a name="682" href="#682">682</a>             <strong>if</strong> (i > 0) {<a name="683" href="#683">683</a>                 buffer.append(<span class="string">"; "</span>);<a name="684" href="#684">684</a>             }<a name="685" href="#685">685</a>             buffer.append(formatCookie(cookies[i]));<a name="686" href="#686">686</a>         }<a name="687" href="#687">687</a>         <strong>return</strong> buffer.toString();<a name="688" href="#688">688</a>     }<a name="689" href="#689">689</a> <a name="690" href="#690">690</a> <a name="691" href="#691">691</a>     <em>/**<em>*</em></em><a name="692" href="#692">692</a> <em>     * Create a &lt;tt>"Cookie"&lt;/tt> {@link Header} containing all {@link Cookie}s</em><a name="693" href="#693">693</a> <em>     * in &lt;i>cookies&lt;/i>.</em><a name="694" href="#694">694</a> <em>     * @param cookies an array of {@link Cookie}s to be formatted as a &lt;tt>"</em><a name="695" href="#695">695</a> <em>     * Cookie"&lt;/tt> header</em><a name="696" href="#696">696</a> <em>     * @return a &lt;tt>"Cookie"&lt;/tt> {@link Header}.</em><a name="697" href="#697">697</a> <em>     */</em><a name="698" href="#698">698</a>     <strong>public</strong> Header formatCookieHeader(<a href="../../../../../org/apache/commons/httpclient/Cookie.html">Cookie</a>[] cookies) {<a name="699" href="#699">699</a>         LOG.trace(<span class="string">"enter CookieSpecBase.formatCookieHeader(Cookie[])"</span>);<a name="700" href="#700">700</a>         <strong>return</strong> <strong>new</strong> Header(<span class="string">"Cookie"</span>, formatCookies(cookies));<a name="701" href="#701">701</a>     }<a name="702" href="#702">702</a> <a name="703" href="#703">703</a> <a name="704" href="#704">704</a>     <em>/**<em>*</em></em><a name="705" href="#705">705</a> <em>     * Create a &lt;tt>"Cookie"&lt;/tt> {@link Header} containing the {@link Cookie}.</em><a name="706" href="#706">706</a> <em>     * @param cookie &lt;tt>Cookie&lt;/tt>s to be formatted as a &lt;tt>Cookie&lt;/tt></em><a name="707" href="#707">707</a> <em>     * header</em><a name="708" href="#708">708</a> <em>     * @return a Cookie header.</em><a name="709" href="#709">709</a> <em>     */</em><a name="710" href="#710">710</a>     <strong>public</strong> Header formatCookieHeader(<a href="../../../../../org/apache/commons/httpclient/Cookie.html">Cookie</a> cookie) {<a name="711" href="#711">711</a>         LOG.trace(<span class="string">"enter CookieSpecBase.formatCookieHeader(Cookie)"</span>);<a name="712" href="#712">712</a>         <strong>return</strong> <strong>new</strong> Header(<span class="string">"Cookie"</span>, formatCookie(cookie));<a name="713" href="#713">713</a>     }<a name="714" href="#714">714</a> <a name="715" href="#715">715</a> }</pre><hr/><div id="footer">This page was automatically generated by <a href="http://maven.apache.org/">Maven</a></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -