/** * Returns the header collection. * The header collection contains the HTTP headers associated with HTTP message. * @return HeaderCollection the header collection */ public function getHeaders() { if (!is_object($this->_headers)) { $headerCollection = new HeaderCollection(); if (is_array($this->_headers)) { foreach ($this->_headers as $name => $value) { if (is_int($name)) { // parse raw header : $rawHeader = $value; if (($separatorPos = strpos($rawHeader, ':')) !== false) { $name = strtolower(trim(substr($rawHeader, 0, $separatorPos))); $value = trim(substr($rawHeader, $separatorPos + 1)); $headerCollection->add($name, $value); } elseif (strpos($rawHeader, 'HTTP/') === 0) { $parts = explode(' ', $rawHeader, 3); $headerCollection->add('http-code', $parts[1]); } else { $headerCollection->add('raw', $rawHeader); } } else { $headerCollection->set($name, $value); } } } $this->_headers = $headerCollection; } return $this->_headers; }
/** * Sets HPKP header. * @param HeaderCollection $headers */ public function addPublicKeyPins(HeaderCollection $headers) { if ($this->hpkpPins && is_array($this->hpkpPins)) { $values = []; foreach ($this->hpkpPins as $pin) { $values[] = "pin-sha256=\"" . $pin . "\""; } if (!empty($this->hpkpReportUri)) { $values[] = "report-uri=\"" . $this->hpkpReportUri . "\""; } $values[] = "max-age=" . $this->hpkpMaxAge; if ($this->hpkpIncludeSubdomains) { $values[] = "includeSubDomains"; } $headers->set('Public-Key-Pins', implode("; ", $values)); } }