1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\HTTP; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehler/** 6*a1a3b679SAndreas Boehler * The MessageInterface is the base interface that's used by both 7*a1a3b679SAndreas Boehler * the RequestInterface and ResponseInterface. 8*a1a3b679SAndreas Boehler * 9*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2009-2015 fruux GmbH (https://fruux.com/). 10*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/) 11*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License 12*a1a3b679SAndreas Boehler */ 13*a1a3b679SAndreas Boehlerinterface MessageInterface { 14*a1a3b679SAndreas Boehler 15*a1a3b679SAndreas Boehler /** 16*a1a3b679SAndreas Boehler * Returns the body as a readable stream resource. 17*a1a3b679SAndreas Boehler * 18*a1a3b679SAndreas Boehler * Note that the stream may not be rewindable, and therefore may only be 19*a1a3b679SAndreas Boehler * read once. 20*a1a3b679SAndreas Boehler * 21*a1a3b679SAndreas Boehler * @return resource 22*a1a3b679SAndreas Boehler */ 23*a1a3b679SAndreas Boehler function getBodyAsStream(); 24*a1a3b679SAndreas Boehler 25*a1a3b679SAndreas Boehler /** 26*a1a3b679SAndreas Boehler * Returns the body as a string. 27*a1a3b679SAndreas Boehler * 28*a1a3b679SAndreas Boehler * Note that because the underlying data may be based on a stream, this 29*a1a3b679SAndreas Boehler * method could only work correctly the first time. 30*a1a3b679SAndreas Boehler * 31*a1a3b679SAndreas Boehler * @return string 32*a1a3b679SAndreas Boehler */ 33*a1a3b679SAndreas Boehler function getBodyAsString(); 34*a1a3b679SAndreas Boehler 35*a1a3b679SAndreas Boehler /** 36*a1a3b679SAndreas Boehler * Returns the message body, as it's internal representation. 37*a1a3b679SAndreas Boehler * 38*a1a3b679SAndreas Boehler * This could be either a string or a stream. 39*a1a3b679SAndreas Boehler * 40*a1a3b679SAndreas Boehler * @return resource|string 41*a1a3b679SAndreas Boehler */ 42*a1a3b679SAndreas Boehler function getBody(); 43*a1a3b679SAndreas Boehler 44*a1a3b679SAndreas Boehler /** 45*a1a3b679SAndreas Boehler * Updates the body resource with a new stream. 46*a1a3b679SAndreas Boehler * 47*a1a3b679SAndreas Boehler * @param resource $body 48*a1a3b679SAndreas Boehler * @return void 49*a1a3b679SAndreas Boehler */ 50*a1a3b679SAndreas Boehler function setBody($body); 51*a1a3b679SAndreas Boehler 52*a1a3b679SAndreas Boehler /** 53*a1a3b679SAndreas Boehler * Returns all the HTTP headers as an array. 54*a1a3b679SAndreas Boehler * 55*a1a3b679SAndreas Boehler * Every header is returned as an array, with one or more values. 56*a1a3b679SAndreas Boehler * 57*a1a3b679SAndreas Boehler * @return array 58*a1a3b679SAndreas Boehler */ 59*a1a3b679SAndreas Boehler function getHeaders(); 60*a1a3b679SAndreas Boehler 61*a1a3b679SAndreas Boehler /** 62*a1a3b679SAndreas Boehler * Will return true or false, depending on if a HTTP header exists. 63*a1a3b679SAndreas Boehler * 64*a1a3b679SAndreas Boehler * @param string $name 65*a1a3b679SAndreas Boehler * @return bool 66*a1a3b679SAndreas Boehler */ 67*a1a3b679SAndreas Boehler function hasHeader($name); 68*a1a3b679SAndreas Boehler 69*a1a3b679SAndreas Boehler /** 70*a1a3b679SAndreas Boehler * Returns a specific HTTP header, based on it's name. 71*a1a3b679SAndreas Boehler * 72*a1a3b679SAndreas Boehler * The name must be treated as case-insensitive. 73*a1a3b679SAndreas Boehler * If the header does not exist, this method must return null. 74*a1a3b679SAndreas Boehler * 75*a1a3b679SAndreas Boehler * If a header appeared more than once in a HTTP request, this method will 76*a1a3b679SAndreas Boehler * concatenate all the values with a comma. 77*a1a3b679SAndreas Boehler * 78*a1a3b679SAndreas Boehler * Note that this not make sense for all headers. Some, such as 79*a1a3b679SAndreas Boehler * `Set-Cookie` cannot be logically combined with a comma. In those cases 80*a1a3b679SAndreas Boehler * you *should* use getHeaderAsArray(). 81*a1a3b679SAndreas Boehler * 82*a1a3b679SAndreas Boehler * @param string $name 83*a1a3b679SAndreas Boehler * @return string|null 84*a1a3b679SAndreas Boehler */ 85*a1a3b679SAndreas Boehler function getHeader($name); 86*a1a3b679SAndreas Boehler 87*a1a3b679SAndreas Boehler /** 88*a1a3b679SAndreas Boehler * Returns a HTTP header as an array. 89*a1a3b679SAndreas Boehler * 90*a1a3b679SAndreas Boehler * For every time the HTTP header appeared in the request or response, an 91*a1a3b679SAndreas Boehler * item will appear in the array. 92*a1a3b679SAndreas Boehler * 93*a1a3b679SAndreas Boehler * If the header did not exists, this method will return an empty array. 94*a1a3b679SAndreas Boehler * 95*a1a3b679SAndreas Boehler * @param string $name 96*a1a3b679SAndreas Boehler * @return string[] 97*a1a3b679SAndreas Boehler */ 98*a1a3b679SAndreas Boehler function getHeaderAsArray($name); 99*a1a3b679SAndreas Boehler 100*a1a3b679SAndreas Boehler /** 101*a1a3b679SAndreas Boehler * Updates a HTTP header. 102*a1a3b679SAndreas Boehler * 103*a1a3b679SAndreas Boehler * The case-sensitity of the name value must be retained as-is. 104*a1a3b679SAndreas Boehler * 105*a1a3b679SAndreas Boehler * If the header already existed, it will be overwritten. 106*a1a3b679SAndreas Boehler * 107*a1a3b679SAndreas Boehler * @param string $name 108*a1a3b679SAndreas Boehler * @param string|string[] $value 109*a1a3b679SAndreas Boehler * @return void 110*a1a3b679SAndreas Boehler */ 111*a1a3b679SAndreas Boehler function setHeader($name, $value); 112*a1a3b679SAndreas Boehler 113*a1a3b679SAndreas Boehler /** 114*a1a3b679SAndreas Boehler * Sets a new set of HTTP headers. 115*a1a3b679SAndreas Boehler * 116*a1a3b679SAndreas Boehler * The headers array should contain headernames for keys, and their value 117*a1a3b679SAndreas Boehler * should be specified as either a string or an array. 118*a1a3b679SAndreas Boehler * 119*a1a3b679SAndreas Boehler * Any header that already existed will be overwritten. 120*a1a3b679SAndreas Boehler * 121*a1a3b679SAndreas Boehler * @param array $headers 122*a1a3b679SAndreas Boehler * @return void 123*a1a3b679SAndreas Boehler */ 124*a1a3b679SAndreas Boehler function setHeaders(array $headers); 125*a1a3b679SAndreas Boehler 126*a1a3b679SAndreas Boehler /** 127*a1a3b679SAndreas Boehler * Adds a HTTP header. 128*a1a3b679SAndreas Boehler * 129*a1a3b679SAndreas Boehler * This method will not overwrite any existing HTTP header, but instead add 130*a1a3b679SAndreas Boehler * another value. Individual values can be retrieved with 131*a1a3b679SAndreas Boehler * getHeadersAsArray. 132*a1a3b679SAndreas Boehler * 133*a1a3b679SAndreas Boehler * @param string $name 134*a1a3b679SAndreas Boehler * @param string $value 135*a1a3b679SAndreas Boehler * @return void 136*a1a3b679SAndreas Boehler */ 137*a1a3b679SAndreas Boehler function addHeader($name, $value); 138*a1a3b679SAndreas Boehler 139*a1a3b679SAndreas Boehler /** 140*a1a3b679SAndreas Boehler * Adds a new set of HTTP headers. 141*a1a3b679SAndreas Boehler * 142*a1a3b679SAndreas Boehler * Any existing headers will not be overwritten. 143*a1a3b679SAndreas Boehler * 144*a1a3b679SAndreas Boehler * @param array $headers 145*a1a3b679SAndreas Boehler * @return void 146*a1a3b679SAndreas Boehler */ 147*a1a3b679SAndreas Boehler function addHeaders(array $headers); 148*a1a3b679SAndreas Boehler 149*a1a3b679SAndreas Boehler /** 150*a1a3b679SAndreas Boehler * Removes a HTTP header. 151*a1a3b679SAndreas Boehler * 152*a1a3b679SAndreas Boehler * The specified header name must be treated as case-insenstive. 153*a1a3b679SAndreas Boehler * This method should return true if the header was successfully deleted, 154*a1a3b679SAndreas Boehler * and false if the header did not exist. 155*a1a3b679SAndreas Boehler * 156*a1a3b679SAndreas Boehler * @return bool 157*a1a3b679SAndreas Boehler */ 158*a1a3b679SAndreas Boehler function removeHeader($name); 159*a1a3b679SAndreas Boehler 160*a1a3b679SAndreas Boehler /** 161*a1a3b679SAndreas Boehler * Sets the HTTP version. 162*a1a3b679SAndreas Boehler * 163*a1a3b679SAndreas Boehler * Should be 1.0 or 1.1. 164*a1a3b679SAndreas Boehler * 165*a1a3b679SAndreas Boehler * @param string $version 166*a1a3b679SAndreas Boehler * @return void 167*a1a3b679SAndreas Boehler */ 168*a1a3b679SAndreas Boehler function setHttpVersion($version); 169*a1a3b679SAndreas Boehler 170*a1a3b679SAndreas Boehler /** 171*a1a3b679SAndreas Boehler * Returns the HTTP version. 172*a1a3b679SAndreas Boehler * 173*a1a3b679SAndreas Boehler * @return string 174*a1a3b679SAndreas Boehler */ 175*a1a3b679SAndreas Boehler function getHttpVersion(); 176*a1a3b679SAndreas Boehler 177*a1a3b679SAndreas Boehler} 178