httpstate.html
来自「网络爬虫开源代码」· HTML 代码 · 共 728 行 · 第 1/4 页
HTML
728 行
<a name="356" href="#356">356</a> <em> * </em><a name="357" href="#357">357</a> <em> * @deprecated Use </em><a name="358" href="#358">358</a> <em> * {@link org.apache.commons.httpclient.params.HttpClientParams#setAuthenticationPreemptive(boolean)}, </em><a name="359" href="#359">359</a> <em> * {@link HttpClient#getParams()}.</em><a name="360" href="#360">360</a> <em> */</em><a name="361" href="#361">361</a> <a name="362" href="#362">362</a> <strong>public</strong> <strong>void</strong> setAuthenticationPreemptive(<strong>boolean</strong> value) {<a name="363" href="#363">363</a> <strong>this</strong>.preemptive = value;<a name="364" href="#364">364</a> }<a name="365" href="#365">365</a> <a name="366" href="#366">366</a> <a name="367" href="#367">367</a> <em>/**<em>*</em></em><a name="368" href="#368">368</a> <em> * Returns <tt>true</tt> if preemptive authentication should be </em><a name="369" href="#369">369</a> <em> * attempted, <tt>false</tt> otherwise.</em><a name="370" href="#370">370</a> <em> * </em><a name="371" href="#371">371</a> <em> * @return boolean flag.</em><a name="372" href="#372">372</a> <em> * </em><a name="373" href="#373">373</a> <em> * @deprecated Use </em><a name="374" href="#374">374</a> <em> * {@link org.apache.commons.httpclient.params.HttpClientParams#isAuthenticationPreemptive()}, </em><a name="375" href="#375">375</a> <em> * {@link HttpClient#getParams()}.</em><a name="376" href="#376">376</a> <em> */</em><a name="377" href="#377">377</a> <a name="378" href="#378">378</a> <strong>public</strong> <strong>boolean</strong> isAuthenticationPreemptive() {<a name="379" href="#379">379</a> <strong>return</strong> <strong>this</strong>.preemptive;<a name="380" href="#380">380</a> }<a name="381" href="#381">381</a> <a name="382" href="#382">382</a> <a name="383" href="#383">383</a> <em>/**<em>*</em></em><a name="384" href="#384">384</a> <em> * Sets the current {@link CookiePolicy cookie policy} for this HTTP</em><a name="385" href="#385">385</a> <em> * state to one of the following supported policies: </em><a name="386" href="#386">386</a> <em> * {@link CookiePolicy#COMPATIBILITY}, </em><a name="387" href="#387">387</a> <em> * {@link CookiePolicy#NETSCAPE_DRAFT} or</em><a name="388" href="#388">388</a> <em> * {@link CookiePolicy#RFC2109}.</em><a name="389" href="#389">389</a> <em> * </em><a name="390" href="#390">390</a> <em> * @param policy new {@link CookiePolicy cookie policy}</em><a name="391" href="#391">391</a> <em> * </em><a name="392" href="#392">392</a> <em> * @deprecated </em><a name="393" href="#393">393</a> <em> * Use {@link org.apache.commons.httpclient.params.HttpMethodParams#setCookiePolicy(String)},</em><a name="394" href="#394">394</a> <em> * {@link HttpMethod#getParams()}. </em><a name="395" href="#395">395</a> <em> */</em><a name="396" href="#396">396</a> <a name="397" href="#397">397</a> <strong>public</strong> <strong>void</strong> setCookiePolicy(<strong>int</strong> policy) {<a name="398" href="#398">398</a> <strong>this</strong>.cookiePolicy = policy;<a name="399" href="#399">399</a> }<a name="400" href="#400">400</a> <a name="401" href="#401">401</a> <em>/**<em>* </em></em><a name="402" href="#402">402</a> <em> * Sets the {@link Credentials credentials} for the given authentication </em><a name="403" href="#403">403</a> <em> * realm on the given host. The <code>null</code> realm signifies default </em><a name="404" href="#404">404</a> <em> * credentials for the given host, which should be used when no </em><a name="405" href="#405">405</a> <em> * {@link Credentials credentials} have been explictly supplied for the </em><a name="406" href="#406">406</a> <em> * challenging realm. The <code>null</code> host signifies default </em><a name="407" href="#407">407</a> <em> * credentials, which should be used when no {@link Credentials credentials} </em><a name="408" href="#408">408</a> <em> * have been explictly supplied for the challenging host. Any previous </em><a name="409" href="#409">409</a> <em> * credentials for the given realm on the given host will be overwritten.</em><a name="410" href="#410">410</a> <em> * </em><a name="411" href="#411">411</a> <em> * @param realm the authentication realm</em><a name="412" href="#412">412</a> <em> * @param host the host the realm belongs to</em><a name="413" href="#413">413</a> <em> * @param credentials the authentication {@link Credentials credentials} </em><a name="414" href="#414">414</a> <em> * for the given realm.</em><a name="415" href="#415">415</a> <em> * </em><a name="416" href="#416">416</a> <em> * @see #getCredentials(String, String)</em><a name="417" href="#417">417</a> <em> * @see #setProxyCredentials(String, String, Credentials) </em><a name="418" href="#418">418</a> <em> * </em><a name="419" href="#419">419</a> <em> * @deprecated use #setCredentials(AuthScope, Credentials)</em><a name="420" href="#420">420</a> <em> */</em><a name="421" href="#421">421</a> <a name="422" href="#422">422</a> <strong>public</strong> <strong>synchronized</strong> <strong>void</strong> setCredentials(String realm, String host, Credentials credentials) {<a name="423" href="#423">423</a> LOG.trace(<span class="string">"enter HttpState.setCredentials(String, String, Credentials)"</span>);<a name="424" href="#424">424</a> credMap.put(<strong>new</strong> AuthScope(host, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME), credentials);<a name="425" href="#425">425</a> }<a name="426" href="#426">426</a> <a name="427" href="#427">427</a> <em>/**<em>* </em></em><a name="428" href="#428">428</a> <em> * Sets the {@link Credentials credentials} for the given authentication </em><a name="429" href="#429">429</a> <em> * scope. Any previous credentials for the given scope will be overwritten.</em><a name="430" href="#430">430</a> <em> * </em><a name="431" href="#431">431</a> <em> * @param authscope the {@link AuthScope authentication scope}</em><a name="432" href="#432">432</a> <em> * @param credentials the authentication {@link Credentials credentials} </em><a name="433" href="#433">433</a> <em> * for the given scope.</em><a name="434" href="#434">434</a> <em> * </em><a name="435" href="#435">435</a> <em> * @see #getCredentials(AuthScope)</em><a name="436" href="#436">436</a> <em> * @see #setProxyCredentials(AuthScope, Credentials) </em><a name="437" href="#437">437</a> <em> * </em><a name="438" href="#438">438</a> <em> * @since 3.0</em><a name="439" href="#439">439</a> <em> */</em><a name="440" href="#440">440</a> <strong>public</strong> <strong>synchronized</strong> <strong>void</strong> setCredentials(<strong>final</strong> AuthScope authscope, <strong>final</strong> Credentials credentials) {<a name="441" href="#441">441</a> <strong>if</strong> (authscope == <strong>null</strong>) {<a name="442" href="#442">442</a> <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"Authentication scope may not be null"</span>);<a name="443" href="#443">443</a> }<a name="444" href="#444">444</a> LOG.trace(<span class="string">"enter HttpState.setCredentials(AuthScope, Credentials)"</span>);<a name="445" href="#445">445</a> credMap.put(authscope, credentials);<a name="446" href="#446">446</a> }<a name="447" href="#447">447</a> <a name="448" href="#448">448</a> <em>/**<em>*</em></em><a name="449" href="#449">449</a> <em> * Find matching {@link Credentials credentials} for the given authentication scope.</em><a name="450" href="#450">450</a> <em> *</em><a name="451" href="#451">451</a> <em> * @param map the credentials hash map</em><a name="452" href="#452">452</a> <em> * @param token the {@link AuthScope authentication scope}</em><a name="453" href="#453">453</a> <em> * @return the credentials </em><a name="454" href="#454">454</a> <em> * </em><a name="455" href="#455">455</a> <em> */</em><a name="456" href="#456">456</a> <strong>private</strong> <strong>static</strong> Credentials matchCredentials(<strong>final</strong> HashMap map, <strong>final</strong> AuthScope authscope) {<a name="457" href="#457">457</a> <em class="comment">// see if we get a direct hit</em><a name="458" href="#458">458</a> Credentials creds = (Credentials)map.get(authscope);<a name="459" href="#459">459</a> <strong>if</strong> (creds == <strong>null</strong>) {<a name="460" href="#460">460</a> <em class="comment">// Nope.</em><a name="461" href="#461">461</a> <em class="comment">// Do a full scan</em><a name="462" href="#462">462</a> <strong>int</strong> bestMatchFactor = -1;<a name="463" href="#463">463</a> AuthScope bestMatch = <strong>null</strong>;<a name="464" href="#464">464</a> Iterator items = map.keySet().iterator();<a name="465" href="#465">465</a> <strong>while</strong> (items.hasNext()) {<a name="466" href="#466">466</a> AuthScope current = (AuthScope)items.next();<a name="467" href="#467">467</a> <strong>int</strong> factor = authscope.match(current);<a name="468" href="#468">468</a> <strong>if</strong> (factor > bestMatchFactor) {<a name="469" href="#469">469</a> bestMatchFactor = factor;<a name="470" href="#470">470</a> bestMatch = current;<a name="471" href="#471">471</a> }<a name="472" href="#472">472</a> }<a name="473" href="#473">473</a> <strong>if</strong> (bestMatch != <strong>null</strong>) {<a name="474" href="#474">474</a> creds = (Credentials)map.get(bestMatch);<a name="475" href="#475">475</a> }<a name="476" href="#476">476</a> }<a name="477" href="#477">477</a> <strong>return</strong> creds;<a name="478" href="#478">478</a> }<a name="479" href="#479">479</a> <a name="480" href="#480">480</a> <em>/**<em>*</em></em><a name="481" href="#481">481</a> <em> * Get the {@link Credentials credentials} for the given authentication scope on the </em><a name="482" href="#482">482</a> <em> * given host.</em><a name="483" href="#483">483</a> <em> *</em><a name="484" href="#484">484</a> <em> * If the <i>realm</i> exists on <i>host</i>, return the coresponding credentials.</em><a name="485" href="#485">485</a> <em> * If the <i>host</i> exists with a <tt>null</tt> <i>realm</i>, return the corresponding</em><a name="486" href="#486">486</a> <em> * credentials.</em><a name="487" href="#487">487</a> <em> * If the <i>realm</i> exists with a <tt>null</tt> <i>host</i>, return the</em><a name="488" href="#488">488</a> <em> * corresponding credentials. If the <i>realm</i> does not exist, return</em><a name="489" href="#489">489</a> <em> * the default Credentials. If there are no default credentials, return</em><a name="490" href="#490">490</a> <em> * <code>null</code>.</em><a name="491" href="#491">491</a> <em> *</em><a name="492" href="#492">492</a> <em> * @param realm the authentication realm</em><a name="493" href="#493">493</a> <em> * @param host the host the realm is on</em><a name="494" href="#494">494</a> <em> * @return the credentials </em><a name="495" href="#495">495</a> <em> * </em><a name="496" href="#496">496</a> <em> * @see #setCredentials(String, String, Credentials)</em><a name="497" href="#497">497</a> <em> * </em><a name="498" href="#498">498</a> <em> * @deprecated use #getCredentials(AuthScope)</em><a name="499" href="#499">499</a> <em> */</em><a name="500" href="#500">500</a> <a name="501" href="#501">501</a> <strong>public</strong> <strong>synchronized</strong> Credentials getCredentials(String realm, String host) {<a name="502" href="#502">502</a> LOG.trace(<span class="string">"enter HttpState.getCredentials(String, String"</span>);<a name="503" href="#503">503</a> <strong>return</strong> matchCredentials(<strong>this</strong>.credMap, <a name="504" href="#504">504</a> <strong>new</strong> AuthScope(host, AuthScope.ANY_PORT, realm, AuthScope.ANY_SCHEME));<a name="505" href="#505">505</a> }<a name="506" href="#506">506</a> <a name="507" href="#507">507</a> <em>/**<em>*</em></em><a name="508" href="#508">508</a> <em> * Get the {@link Credentials credentials} for the given authentication scope.</em><a name="509" href="#509">509</a> <em> *</em><a name="510" href="#510">510</a> <em> * @param authscope the {@link AuthScope authentication scope}</em><a name="511" href="#511">511</a> <em> * @return the credentials </em><a name="512" href="#512">512</a> <em> * </em><a name="513" href="#513">513</a> <em> * @see #setCredentials(AuthScope, Credentials)</em><a name="514" href="#514">514</a> <em> * </em><a name="515" href="#515">515</a> <em> * @since 3.0</em><a name="516" href="#516">516</a> <em> */</em><a name="517" href="#517">517</a> <strong>public</strong> <strong>synchronized</strong> Credentials getCredentials(<strong>final</strong> AuthScope authscope) {<a name="518" href="#518">518</a> <strong>if</strong> (authscope == <strong>null</strong>) {<a name="519" href="#519">519</a> <strong>throw</strong> <strong>new</strong> IllegalArgumentException(<span class="string">"Authentication scope may not be null"</span>);<a name="520" href="#520">520</a> }<a name="521" href="#521">521</a> LOG.trace(<span class="string">"enter HttpState.getCredentials(AuthScope)"</span>);<a name="522" href="#522">522</a> <strong>return</strong> matchCredentials(<strong>this</strong>.credMap, authscope);<a name="523" href="#523">523</a> }<a name="524" href="#524">524</a> <a name="525" href="#525">525</a> <em>/**<em>*</em></em><a name="526" href="#526">526</a> <em> * Sets the {@link Credentials credentials} for the given proxy authentication </em><a name="527" href="#527">527</a> <em> * realm on the given proxy host. The <code>null</code> proxy realm signifies </em><a name="528" href="#528">528</a> <em> * default credentials for the given proxy host, which should be used when no </em><a name="529" href="#529">529</a> <em> * {@link Credentials credentials} have been explictly supplied for the </em><a name="530" href="#530">530</a> <em> * challenging proxy realm. The <code>null</code> proxy host signifies default </em><a name="531" href="#531">531</a> <em> * credentials, which should be used when no {@link Credentials credentials} </em><a name="532" href="#532">532</a> <em> * have been explictly supplied for the challenging proxy host. Any previous </em><a name="533" href="#533">533</a> <em> * credentials for the given proxy realm on the given proxy host will be </em><a name="534" href="#534">534</a> <em> * overwritten.</em><a name="535" href="#535">535</a> <em> *</em><a name="536" href="#536">536</a> <em> * @param realm the authentication realm</em><a name="537" href="#537">537</a> <em> * @param proxyHost the proxy host</em>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?