function http_date_string() { $result = FALSE; if (class_exists('HTTP')) { $result = HTTP::Date(time()); } return $result; }
public function getHeadersAsString() { $text = sprintf("HTTP/%s %s %s" . self::CRLF, $this->version, $this->code, self::resolveStatusCode($this->code)); $this->setHeader(self::DATE, HTTP::Date(time())); if ($this->body && !$this->existsHeader('Content-Type')) { $this->setContentType('text/html;charset=UTF-8'); } $text .= parent::getHeadersAsString() . self::CRLF; return $text; }
public function toString() { $out = $this->name . '=' . urldecode($this->value); if ($this->expire !== null) { $out .= '; expires=' . HTTP::Date($this->expire); } if ($this->path !== null) { $out .= '; path=' . $this->path; } if ($this->domain !== null) { $out .= '; domain=' . urlencode($this->domain); } if ($this->secure === true) { $out .= '; secure'; } return $out; }
/** * Set Header * * The default value for the Last-Modified header will be current * date and atime if $value is omitted. * * @access public * @return bool Returns true on success or false if $key was empty or * $value was not of an scalar type. * @param string $key The name of the header. * @param string $value The value of the header. (NULL to unset header) */ function setHeader($key, $value = null) { if (empty($key) || isset($value) && !is_scalar($value)) { return false; } $key = strToLower($key); if ($key == 'last-modified') { if (!isset($value)) { $value = HTTP::Date(time()); } elseif (is_numeric($value)) { $value = HTTP::Date($value); } } if (isset($value)) { $this->_headers[$key] = $value; } else { unset($this->_headers[$key]); } return true; }
function testpost() { require_once 'HTTP/Request.php'; $r =& new HTTP_Request($this->testScript); $r->setMethod(HTTP_REQUEST_METHOD_GET); $r->sendRequest(); $lm = $r->getResponseHeader('last-modified'); $r->setMethod(HTTP_REQUEST_METHOD_POST); $r->sendRequest(); $this->assertEquals(200, $r->getResponseCode(), 'HTTP 200 Ok (POST without If-Modified-Since)'); $r->addHeader('If-Modified-Since', HTTP::Date(strtotime('yesterday'))); $r->sendRequest(); $this->assertEquals(200, $r->getResponseCode(), 'HTTP 200 Ok (POST with If-Modified-Since == yesterday)'); $r->addHeader('If-Modified-Since', HTTP::Date(time() - 3)); $r->sendRequest(); $this->assertEquals(200, $r->getResponseCode(), 'HTTP 200 Ok (POST with If-Modified-Since == now)'); $r->addHeader('If-Modified-Since', HTTP::Date($lm)); sleep(3); $r->sendRequest(); $this->assertEquals(200, $r->getResponseCode(), 'HTTP 200 Ok (POST with If-Modified-Since == Last-Modified)'); $this->assertEquals(HTTP::Date(), $r->getResponseHeader('last-modified'), 'POST time() == Last-Modified'); unset($r); }
/** * Set "Last-Modified" * * This is usually determined by filemtime() in HTTP_Download::setFile() * If you set raw data for download with HTTP_Download::setData() and you * want do send an appropiate "Last-Modified" header, you should call this * method. * * @access public * @return void * @param int unix timestamp */ function setLastModified($last_modified) { $this->lastModified = HTTP::Date((int) $last_modified); $this->headers['Last-Modified'] = (int) $last_modified; }
function testdateToTimestamp() { $h =& new HTTP_Header(); $this->assertEquals(strtotime($d = HTTP::Date()), $h->dateToTimestamp($d)); unset($h); }