1 /* 2 * ==================================================================== 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with 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, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * ==================================================================== 20 * 21 * This software consists of voluntary contributions made by many 22 * individuals on behalf of the Apache Software Foundation. For more 23 * information on the Apache Software Foundation, please see 24 * <http://www.apache.org/>. 25 * 26 */ 27 28 package org.apache.hc.core5.http; 29 30 /** 31 * HTTP messages consist of requests from client to server and responses 32 * from server to client. 33 * 34 * @since 4.0 35 */ 36 public interface HttpMessage extends MessageHeaders { 37 38 /** 39 * Sets protocol version. 40 * <p> 41 * For incoming messages it represents protocol version this message was transmitted with. 42 * For outgoing messages it represents a hint what protocol version should be used to transmit 43 * the message. 44 * 45 * @since 5.0 46 */ 47 void setVersion(ProtocolVersion version); 48 49 /** 50 * Returns protocol version or {@code null} when not available. 51 * <p> 52 * For incoming messages it represents protocol version this message was transmitted with. 53 * For outgoing messages it represents a hint what protocol version should be used to transmit 54 * the message. 55 * 56 * @since 5.0 57 */ 58 ProtocolVersion getVersion(); 59 60 /** 61 * Adds a header to this message. The header will be appended to the end of 62 * the list. 63 * 64 * @param header the header to append. 65 */ 66 void addHeader(Header header); 67 68 /** 69 * Adds a header to this message. The header will be appended to the end of 70 * the list. 71 * 72 * @param name the name of the header. 73 * @param value the value of the header, taken as the value's {@link Object#toString()}. 74 */ 75 void addHeader(String name, Object value); 76 77 /** 78 * Overwrites the first header with the same name. The new header will be appended to 79 * the end of the list, if no header with the given name can be found. 80 * 81 * @param header the header to set. 82 */ 83 void setHeader(Header header); 84 85 /** 86 * Overwrites the first header with the same name. The new header will be appended to 87 * the end of the list, if no header with the given name can be found. 88 * 89 * @param name the name of the header. 90 * @param value the value of the header, taken as the value's {@link Object#toString()}. 91 */ 92 void setHeader(String name, Object value); 93 94 /** 95 * Overwrites all the headers in the message. 96 * 97 * @param headers the array of headers to set. 98 */ 99 void setHeaders(Header... headers); 100 101 /** 102 * Removes a header from this message. 103 * 104 * @param header the header to remove. 105 * @return <code>true</code> if a header was removed as a result of this call. 106 */ 107 boolean removeHeader(Header header); 108 109 /** 110 * Removes all headers with a certain name from this message. 111 * 112 * @param name The name of the headers to remove. 113 * @return <code>true</code> if any header was removed as a result of this call. 114 */ 115 boolean removeHeaders(String name); 116 117 }