📄 httpmethodparams.java
字号:
* This parameter expects a value if type {@link Integer}. * </p> */ public static final String BUFFER_WARN_TRIGGER_LIMIT = "http.method.response.buffer.warnlimit"; /** * Defines the virtual host name. * <p> * This parameter expects a value of type {@link java.lang.String}. * </p> */ public static final String VIRTUAL_HOST = "http.virtual-host"; /** * Sets the value to use as the multipart boundary. * <p> * This parameter expects a value if type {@link String}. * </p> * @see org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity */ public static final String MULTIPART_BOUNDARY = "http.method.multipart.boundary"; /** * Creates a new collection of parameters with the collection returned * by {@link #getDefaultParams()} as a parent. The collection will defer * to its parent for a default value if a particular parameter is not * explicitly set in the collection itself. * * @see #getDefaultParams() */ public HttpMethodParams() { super(getDefaultParams()); } /** * Creates a new collection of parameters with the given parent. * The collection will defer to its parent for a default value * if a particular parameter is not explicitly set in the collection * itself. * * @param defaults the parent collection to defer to, if a parameter * is not explictly set in the collection itself. * * @see #getDefaultParams() */ public HttpMethodParams(HttpParams defaults) { super(defaults); } /** * Returns the charset to be used for writing HTTP headers. * @return The charset */ public String getHttpElementCharset() { String charset = (String) getParameter(HTTP_ELEMENT_CHARSET); if (charset == null) { LOG.warn("HTTP element charset not configured, using US-ASCII"); charset = "US-ASCII"; } return charset; } /** * Sets the charset to be used for writing HTTP headers. * @param charset The charset */ public void setHttpElementCharset(String charset) { setParameter(HTTP_ELEMENT_CHARSET, charset); } /** * Returns the default charset to be used for writing content body, * when no charset explicitly specified. * @return The charset */ public String getContentCharset() { String charset = (String) getParameter(HTTP_CONTENT_CHARSET); if (charset == null) { LOG.warn("Default content charset not configured, using ISO-8859-1"); charset = "ISO-8859-1"; } return charset; } /** * Sets the charset to be used for parsing URIs. * @param charset The charset */ public void setUriCharset(String charset) { setParameter(HTTP_URI_CHARSET, charset); } /** * Returns the charset to be used for parsing URIs. * @return The charset */ public String getUriCharset() { String charset = (String) getParameter(HTTP_URI_CHARSET); if (charset == null) { charset = "UTF-8"; } return charset; } /** * Sets the default charset to be used for writing content body, * when no charset explicitly specified. * @param charset The charset */ public void setContentCharset(String charset) { setParameter(HTTP_CONTENT_CHARSET, charset); } /** * Returns the charset to be used for {@link org.apache.commons.httpclient.Credentials}. If * not configured the {@link #HTTP_ELEMENT_CHARSET HTTP element charset} is used. * @return The charset */ public String getCredentialCharset() { String charset = (String) getParameter(CREDENTIAL_CHARSET); if (charset == null) { LOG.debug("Credential charset not configured, using HTTP element charset"); charset = getHttpElementCharset(); } return charset; } /** * Sets the charset to be used for writing HTTP headers. * @param charset The charset */ public void setCredentialCharset(String charset) { setParameter(CREDENTIAL_CHARSET, charset); } /** * Returns {@link HttpVersion HTTP protocol version} to be used by the * {@link org.apache.commons.httpclient.HttpMethod HTTP methods} that * this collection of parameters applies to. * * @return {@link HttpVersion HTTP protocol version} */ public HttpVersion getVersion() { Object param = getParameter(PROTOCOL_VERSION); if (param == null) { return HttpVersion.HTTP_1_1; } return (HttpVersion)param; } /** * Assigns the {@link HttpVersion HTTP protocol version} to be used by the * {@link org.apache.commons.httpclient.HttpMethod HTTP methods} that * this collection of parameters applies to. * * @param version the {@link HttpVersion HTTP protocol version} */ public void setVersion(HttpVersion version) { setParameter(PROTOCOL_VERSION, version); } /** * Returns {@link CookiePolicy cookie policy} to be used by the * {@link org.apache.commons.httpclient.HttpMethod HTTP methods} * this collection of parameters applies to. * * @return {@link CookiePolicy cookie policy} */ public String getCookiePolicy() { Object param = getParameter(COOKIE_POLICY); if (param == null) { return CookiePolicy.DEFAULT; } return (String)param; } /** * Assigns the {@link CookiePolicy cookie policy} to be used by the * {@link org.apache.commons.httpclient.HttpMethod HTTP methods} * this collection of parameters applies to. * * @param policy the {@link CookiePolicy cookie policy} */ public void setCookiePolicy(String policy) { setParameter(COOKIE_POLICY, policy); } /** * Returns the default socket timeout (<tt>SO_TIMEOUT</tt>) in milliseconds which is the * timeout for waiting for data. A timeout value of zero is interpreted as an infinite * timeout. * * @return timeout in milliseconds */ public int getSoTimeout() { return getIntParameter(SO_TIMEOUT, 0); } /** * Sets the default socket timeout (<tt>SO_TIMEOUT</tt>) in milliseconds which is the * timeout for waiting for data. A timeout value of zero is interpreted as an infinite * timeout. * * @param timeout Timeout in milliseconds */ public void setSoTimeout(int timeout) { setIntParameter(SO_TIMEOUT, timeout); } /** * Sets the virtual host name. * * @param hostname The host name */ public void setVirtualHost(final String hostname) { setParameter(VIRTUAL_HOST, hostname); } /** * Returns the virtual host name. * * @return The virtual host name */ public String getVirtualHost() { return (String) getParameter(VIRTUAL_HOST); } private static final String[] PROTOCOL_STRICTNESS_PARAMETERS = { UNAMBIGUOUS_STATUS_LINE, SINGLE_COOKIE_HEADER, STRICT_TRANSFER_ENCODING, REJECT_HEAD_BODY, WARN_EXTRA_INPUT }; /** * Makes the {@link org.apache.commons.httpclient.HttpMethod HTTP methods} * strictly follow the HTTP protocol specification (RFC 2616 and other relevant RFCs). * It must be noted that popular HTTP agents have different degree of HTTP protocol * compliance and some HTTP serves are programmed to expect the behaviour that does not * strictly adhere to the HTTP specification. */ public void makeStrict() { setParameters(PROTOCOL_STRICTNESS_PARAMETERS, Boolean.TRUE); setIntParameter(STATUS_LINE_GARBAGE_LIMIT, 0); } /** * Makes the {@link org.apache.commons.httpclient.HttpMethod HTTP methods} * attempt to mimic the exact behaviour of commonly used HTTP agents, * which many HTTP servers expect, even though such behaviour may violate * the HTTP protocol specification (RFC 2616 and other relevant RFCs). */ public void makeLenient() { setParameters(PROTOCOL_STRICTNESS_PARAMETERS, Boolean.FALSE); setIntParameter(STATUS_LINE_GARBAGE_LIMIT, Integer.MAX_VALUE); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -