예제 #1
0
 /**
  * Sets the value of the {@code "Connection"} header depending on the protocol version of the
  * specified message. This method sets or removes the {@code "Connection"} header depending on
  * what the default keep alive mode of the message's protocol version is, as specified by {@link
  * HttpVersion#isKeepAliveDefault()}.
  *
  * <ul>
  *   <li>If the connection is kept alive by default:
  *       <ul>
  *         <li>set to {@code "close"} if {@code keepAlive} is {@code false}.
  *         <li>remove otherwise.
  *       </ul>
  *   <li>If the connection is closed by default:
  *       <ul>
  *         <li>set to {@code "keep-alive"} if {@code keepAlive} is {@code true}.
  *         <li>remove otherwise.
  *       </ul>
  * </ul>
  */
 public static void setKeepAlive(HttpHeader message, boolean keepAlive) {
   if (message.getProtocolVersion().isKeepAliveDefault()) {
     if (keepAlive) {
       message.removeHeader(Names.CONNECTION);
     } else {
       message.setHeader(Names.CONNECTION, Values.CLOSE);
     }
   } else {
     if (keepAlive) {
       message.setHeader(Names.CONNECTION, Values.KEEP_ALIVE);
     } else {
       message.removeHeader(Names.CONNECTION);
     }
   }
 }
예제 #2
0
 /**
  * Sets or removes the {@code "Expect: 100-continue"} header to / from the specified message. If
  * the specified {@code value} is {@code true}, the {@code "Expect: 100-continue"} header is set
  * and all other previous {@code "Expect"} headers are removed. Otherwise, all {@code "Expect"}
  * headers are removed completely.
  */
 public static void set100ContinueExpected(HttpHeader message, boolean set) {
   if (set) {
     message.setHeader(Names.EXPECT, Values.CONTINUE);
   } else {
     message.removeHeader(Names.EXPECT);
   }
 }
예제 #3
0
 public static void removeTransferEncodingChunked(HttpHeader m) {
   List<String> values = m.getHeaders(Names.TRANSFER_ENCODING);
   values.remove(Values.CHUNKED);
   if (values.isEmpty()) {
     m.removeHeader(Names.TRANSFER_ENCODING);
   } else {
     m.setHeader(Names.TRANSFER_ENCODING, values);
   }
 }
예제 #4
0
 /** Removes the header with the specified name. */
 public static void removeHeader(HttpHeader message, String name) {
   message.removeHeader(name);
 }