1 31 32 package org.apache.commons.httpclient.methods; 33 34 import java.io.IOException ; 35 import org.apache.commons.httpclient.HttpConnection; 36 import org.apache.commons.httpclient.HttpException; 37 import org.apache.commons.httpclient.HttpState; 38 import org.apache.commons.logging.Log; 39 import org.apache.commons.logging.LogFactory; 40 41 68 69 public abstract class ExpectContinueMethod extends GetMethod { 70 71 73 private boolean useExpectHeader = false; 74 75 76 private static final Log LOG = LogFactory.getLog(ExpectContinueMethod.class); 77 78 83 public ExpectContinueMethod() { 84 super(); 85 } 86 87 94 public ExpectContinueMethod(String uri) { 95 super(uri); 96 } 97 98 107 public ExpectContinueMethod(String uri, String tempDir) { 108 super(uri, tempDir); 109 } 110 111 121 public ExpectContinueMethod(String uri, String tempDir, String tempFile) { 122 super(uri, tempDir, tempFile); 123 } 124 125 140 public boolean getUseExpectHeader() { 141 return this.useExpectHeader; 142 } 143 144 171 public void setUseExpectHeader(boolean value) { 172 this.useExpectHeader = value; 173 } 174 175 184 protected abstract boolean hasRequestContent(); 185 186 200 protected void addRequestHeaders(HttpState state, HttpConnection conn) 201 throws IOException , HttpException { 202 LOG.trace("enter ExpectContinueMethod.addRequestHeaders(HttpState, HttpConnection)"); 203 204 super.addRequestHeaders(state, conn); 205 boolean headerPresent = (getRequestHeader("Expect") != null); 207 211 if (getUseExpectHeader() && isHttp11() && hasRequestContent()) { 212 if (!headerPresent) { 213 setRequestHeader("Expect", "100-continue"); 214 } 215 } else { 216 if (headerPresent) { 217 removeRequestHeader("Expect"); 218 } 219 } 220 } 221 } 222 | Popular Tags |