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 * </p> 45 * 46 * @param version The protocol version. 47 * @since 5.0 48 */ 49 void setVersion(ProtocolVersion version); 50 51 /** 52 * Returns protocol version or {@code null} when not available. 53 * <p> 54 * For incoming messages it represents protocol version this message was transmitted with. 55 * For outgoing messages it represents a hint what protocol version should be used to transmit 56 * the message. 57 * </p> 58 * 59 * @return The protocol version. 60 * @since 5.0 61 */ 62 ProtocolVersion getVersion(); 63 64 /** 65 * Adds a header to this message. The header will be appended to the end of 66 * the list. 67 * 68 * @param header the header to append. 69 */ 70 void addHeader(Header header); 71 72 /** 73 * Adds a header to this message. The header will be appended to the end of 74 * the list. 75 * 76 * @param name the name of the header. 77 * @param value the value of the header, taken as the value's {@link Object#toString()}. 78 */ 79 void addHeader(String name, Object value); 80 81 /** 82 * Overwrites the first header with the same name. The new header will be appended to 83 * the end of the list, if no header with the given name can be found. 84 * 85 * @param header the header to set. 86 */ 87 void setHeader(Header header); 88 89 /** 90 * Overwrites the first header with the same name. The new header will be appended to 91 * the end of the list, if no header with the given name can be found. 92 * 93 * @param name the name of the header. 94 * @param value the value of the header, taken as the value's {@link Object#toString()}. 95 */ 96 void setHeader(String name, Object value); 97 98 /** 99 * Overwrites all the headers in the message. 100 * 101 * @param headers the array of headers to set. 102 */ 103 void setHeaders(Header... headers); 104 105 /** 106 * Removes a header from this message. 107 * 108 * @param header the header to remove. 109 * @return {@code true} if a header was removed as a result of this call. 110 */ 111 boolean removeHeader(Header header); 112 113 /** 114 * Removes all headers with a certain name from this message. 115 * 116 * @param name The name of the headers to remove. 117 * @return {@code true} if any header was removed as a result of this call. 118 */ 119 boolean removeHeaders(String name); 120 121 }