1 30 31 package org.apache.commons.httpclient.params; 32 33 import org.apache.commons.httpclient.HttpVersion; 34 import org.apache.commons.httpclient.cookie.CookiePolicy; 35 import org.apache.commons.logging.Log; 36 import org.apache.commons.logging.LogFactory; 37 38 52 public class HttpMethodParams extends DefaultHttpParams { 53 54 55 private static final Log LOG = LogFactory.getLog(HttpMethodParams.class); 56 57 64 public static final String USER_AGENT = "http.useragent"; 65 66 74 public static final String PROTOCOL_VERSION = "http.protocol.version"; 75 76 83 public static final String UNAMBIGUOUS_STATUS_LINE = "http.protocol.unambiguous-statusline"; 84 85 92 public static final String SINGLE_COOKIE_HEADER = "http.protocol.single-cookie-header"; 93 94 101 public static final String STRICT_TRANSFER_ENCODING = "http.protocol.strict-transfer-encoding"; 102 103 110 public static final String REJECT_HEAD_BODY = "http.protocol.reject-head-body"; 111 112 121 public static final String HEAD_BODY_CHECK_TIMEOUT = "http.protocol.head-body-timeout"; 122 123 149 public static final String USE_EXPECT_CONTINUE = "http.protocol.expect-continue"; 150 151 159 public static final String CREDENTIAL_CHARSET = "http.protocol.credential-charset"; 160 161 167 public static final String HTTP_ELEMENT_CHARSET = "http.protocol.element-charset"; 168 169 175 public static final String HTTP_URI_CHARSET = "http.protocol.uri-charset"; 176 177 183 public static final String HTTP_CONTENT_CHARSET = "http.protocol.content-charset"; 184 185 191 public static final String COOKIE_POLICY = "http.protocol.cookie-policy"; 192 193 209 public static final String WARN_EXTRA_INPUT = "http.protocol.warn-extra-input"; 210 211 229 public static final String STATUS_LINE_GARBAGE_LIMIT = "http.protocol.status-line-garbage-limit"; 230 231 239 public static final String SO_TIMEOUT = "http.socket.timeout"; 240 241 249 public static final String DATE_PATTERNS = "http.dateparser.patterns"; 250 251 257 public static final String RETRY_HANDLER = "http.method.retry-handler"; 258 259 266 public static final String BUFFER_WARN_TRIGGER_LIMIT = "http.method.response.buffer.warnlimit"; 267 268 274 public static final String VIRTUAL_HOST = "http.virtual-host"; 275 276 283 public static final String MULTIPART_BOUNDARY = "http.method.multipart.boundary"; 284 285 293 public HttpMethodParams() { 294 super(getDefaultParams()); 295 } 296 297 308 public HttpMethodParams(HttpParams defaults) { 309 super(defaults); 310 } 311 312 316 public String getHttpElementCharset() { 317 String charset = (String ) getParameter(HTTP_ELEMENT_CHARSET); 318 if (charset == null) { 319 LOG.warn("HTTP element charset not configured, using US-ASCII"); 320 charset = "US-ASCII"; 321 } 322 return charset; 323 } 324 325 329 public void setHttpElementCharset(String charset) { 330 setParameter(HTTP_ELEMENT_CHARSET, charset); 331 } 332 333 338 public String getContentCharset() { 339 String charset = (String ) getParameter(HTTP_CONTENT_CHARSET); 340 if (charset == null) { 341 LOG.warn("Default content charset not configured, using ISO-8859-1"); 342 charset = "ISO-8859-1"; 343 } 344 return charset; 345 } 346 347 351 public void setUriCharset(String charset) { 352 setParameter(HTTP_URI_CHARSET, charset); 353 } 354 355 359 public String getUriCharset() { 360 String charset = (String ) getParameter(HTTP_URI_CHARSET); 361 if (charset == null) { 362 charset = "UTF-8"; 363 } 364 return charset; 365 } 366 367 372 public void setContentCharset(String charset) { 373 setParameter(HTTP_CONTENT_CHARSET, charset); 374 } 375 376 381 public String getCredentialCharset() { 382 String charset = (String ) getParameter(CREDENTIAL_CHARSET); 383 if (charset == null) { 384 LOG.debug("Credential charset not configured, using HTTP element charset"); 385 charset = getHttpElementCharset(); 386 } 387 return charset; 388 } 389 390 394 public void setCredentialCharset(String charset) { 395 setParameter(CREDENTIAL_CHARSET, charset); 396 } 397 398 405 public HttpVersion getVersion() { 406 Object param = getParameter(PROTOCOL_VERSION); 407 if (param == null) { 408 return HttpVersion.HTTP_1_1; 409 } 410 return (HttpVersion)param; 411 } 412 413 420 public void setVersion(HttpVersion version) { 421 setParameter(PROTOCOL_VERSION, version); 422 } 423 424 425 432 public String getCookiePolicy() { 433 Object param = getParameter(COOKIE_POLICY); 434 if (param == null) { 435 return CookiePolicy.DEFAULT; 436 } 437 return (String )param; 438 } 439 440 447 public void setCookiePolicy(String policy) { 448 setParameter(COOKIE_POLICY, policy); 449 } 450 451 458 public int getSoTimeout() { 459 return getIntParameter(SO_TIMEOUT, 0); 460 } 461 462 469 public void setSoTimeout(int timeout) { 470 setIntParameter(SO_TIMEOUT, timeout); 471 } 472 473 478 public void setVirtualHost(final String hostname) { 479 setParameter(VIRTUAL_HOST, hostname); 480 } 481 482 487 public String getVirtualHost() { 488 return (String ) getParameter(VIRTUAL_HOST); 489 } 490 491 private static final String [] PROTOCOL_STRICTNESS_PARAMETERS = { 492 UNAMBIGUOUS_STATUS_LINE, 493 SINGLE_COOKIE_HEADER, 494 STRICT_TRANSFER_ENCODING, 495 REJECT_HEAD_BODY, 496 WARN_EXTRA_INPUT 497 }; 498 499 506 public void makeStrict() { 507 setParameters(PROTOCOL_STRICTNESS_PARAMETERS, Boolean.TRUE); 508 setIntParameter(STATUS_LINE_GARBAGE_LIMIT, 0); 509 } 510 511 517 public void makeLenient() { 518 setParameters(PROTOCOL_STRICTNESS_PARAMETERS, Boolean.FALSE); 519 setIntParameter(STATUS_LINE_GARBAGE_LIMIT, Integer.MAX_VALUE); 520 } 521 522 } 523 | Popular Tags |