NoncompliantPostMethod xref

    1   /*
    2    * ====================================================================
    3    *
    4    *  Licensed to the Apache Software Foundation (ASF) under one or more
    5    *  contributor license agreements.  See the NOTICE file distributed with
    6    *  this work for additional information regarding copyright ownership.
    7    *  The ASF licenses this file to You under the Apache License, Version 2.0
    8    *  (the "License"); you may not use this file except in compliance with
    9    *  the License.  You may obtain a copy of the License at
    10   *
    11   *      http://www.apache.org/licenses/LICENSE-2.0
    12   *
    13   *  Unless required by applicable law or agreed to in writing, software
    14   *  distributed under the License is distributed on an "AS IS" BASIS,
    15   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16   *  See the License for the specific language governing permissions and
    17   *  limitations under the License.
    18   * ====================================================================
    19   *
    20   * This software consists of voluntary contributions made by many
    21   * individuals on behalf of the Apache Software Foundation.  For more
    22   * information on the Apache Software Foundation, please see
    23   * <http://www.apache.org/>.
    24   *
    25   * [Additional notices, if required by prior licensing conditions]
    26   *
    27   */
    28  package org.apache.commons.httpclient;
    29
    30  import java.io.IOException;
    31  import org.apache.commons.httpclient.methods.PostMethod;
    32
    33  /**
    34   * HTTP POST methid intended to simulate side-effects of
    35   * interaction with non-compiant HTTP servers or proxies
    36   *
    37   * @author Oleg Kalnichevski
    38   */
    39
    40  public class NoncompliantPostMethod extends PostMethod {
    41
    42      public NoncompliantPostMethod(){
    43          super();
    44      }
    45
    46      public NoncompliantPostMethod(String uri) {
    47          super(uri);
    48      }
    49
    50      /**
    51       * NoncompliantPostMethod class skips "Expect: 100-continue"
    52       * header when sending request headers to an HTTP server.
    53       *
    54       * <p>
    55       * That makes the server expect the request body to follow
    56       * immediately after the request head. The HTTP server does not
    57       * send status code 100 expected by the client. The client should
    58       * be able to recover gracefully by sending the request body
    59       * after a defined timeout without having received "continue"
    60       * code.
    61       * </p>
    62       */
    63      protected void writeRequestHeaders(HttpState state, HttpConnection conn)
    64          throws IOException, HttpException {
    65          addRequestHeaders(state, conn);
    66          Header[] headers = getRequestHeaders();
    67          for (int i = 0; i < headers.length; i++) {
    68              Header header = headers[i];
    69              // Write all the headers but "Expect"
    70              if (!header.getName().equalsIgnoreCase("Expect") ) {
    71                  conn.print(header.toExternalForm(), "US-ASCII");
    72              }
    73          }
    74      }
    75
    76  }