function html_inputName($input) { return 'name="' . preserveUnderscores($input[1]) . '"'; }
private function readHeaders($handle, $header) { ## Check for end of headers if (empty($header)) { # Tell cURL end of headers return 0; } # Check for status code if (!$this->status && preg_match('#HTTP/1\\.(?:\\d|x)\\s+(\\d\\d\\d)#', $header, $tmp)) { $this->status = (int) $tmp[1]; ########################################## ## HTTP Status codes ########################################## if ($this->status == 304) { $this->abort = 'notmodified'; } } # Extract the header name and contents if (strpos($header, ':')) { $parts = explode(':', $header, 2); $headerName = strtolower($parts[0]); $headerValue = trim($parts[1]); if ($headerName == 'set-cookie') { ########################################## ## Cookies - handle cookies in response ########################################## if ($this->proxyOptions['allowCookies']) { $cookieValue = ''; ## Explode ';' gives our parameters # Cookie responses are set in the format # name=val; expires=DATE; path=PATH; domain=DOMAIN; secure; httponly # where all but name=val is optional $args = explode(';', $headerValue); ## The goal is to create a new string: value;path;options; ## as the cookie value. # Firstly split the name/value. $tmp = explode('=', $args[0], 2); // Store the name for later $thisCookie['name'] = preserveUnderscores(trim($tmp[0])); // Add value to string $cookieValue .= (empty($tmp[1]) ? '' : trim($tmp[1])) . ';'; ## If we send cookies with the paths / domains set by server # they will be inaccessible to us so we need to store those # parameters and the cookie value inside the cookie itself # (we actually store the domain as part of the cookie name) # Loop through remaining parameters and parse options foreach ($args as $arg) { // If = found, explode it and set key/val if (strpos($arg, '=')) { $parts = explode('=', $arg, 2); $thisCookie[strtolower(trim($parts[0]))] = trim($parts[1]); } else { // Otherwise just add the option to the array $thisCookie[] = trim($arg); } } ## SSL handling # Mark secure cookies as secure only if we're on HTTPS ourselves $secure = in_array('secure', $thisCookie) && !empty($_SERVER['HTTPS']); ## Determine options to send // If explicitly set, use the given path / domain else use current $thisCookie['path'] = empty($thisCookie['path']) ? '/' . urlPATH : $thisCookie['path']; $thisCookie['domain'] = empty($thisCookie['domain']) ? str_replace('www.', '', urlDOMAIN) : $thisCookie['domain']; // Add real path to cookie value $cookieValue .= $thisCookie['path'] . ';'; ## Determine name to save cookie as # Default format is: anon[cookiedomain][cookiename] $saveAs = optCOOKIE . '[' . $thisCookie['domain'] . '][' . rawurlencode($thisCookie['name']) . ']'; ## Set expiry date to end of session if not given $expires = empty($thisCookie['expires']) ? 0 : intval(strtotime($thisCookie['expires'])); ## Force end of session expiration (if not deletion) # We can't allow too many cookies to stay since all # have to be sent to us in the Cookie: header for every # page request and we'd soon reach the limit set by # the server (LimitRequestFieldSize for Apache) if not # the client first. if ($this->proxyOptions['tempCookies'] && $expires > time()) { $expires = 0; } # Send the cookie # Set as httponly if applicable version_compare(PHP_VERSION, '5.2.0', '>=') ? setcookie($saveAs, $cookieValue, $expires, '/', false, $secure, true) : setcookie($saveAs, $cookieValue, $expires, '/', false, $secure); # Save for debugging if (DEBUG_MODE) { $this->cookies[] = $headerValue; } } } else { // Save the header $this->headers[$headerName] = $headerValue; ########################################## ## Handle response headers ########################################## switch ($headerName) { ## Handle a redirect case 'location': $this->abort = 'redirect'; break; ## Content length filesize check ## Content length filesize check case 'content-length': # Check option enabled if (!optMAXSIZE) { break; } # Compare sizes if ($headerValue > optMAXSIZE) { # Log error $this->abort = 'filetoolarge'; } break; ## Content type - do we parse? ## Content type - do we parse? case 'content-type': # Extract mime from charset (if sent) $tmp = explode(';', $headerValue); $mime = trim($tmp[0]); # Define content-type to parser type relations $contentType = array('text/javascript' => 'javascript', 'application/javascript' => 'javascript', 'application/x-javascript' => 'javascript', 'application/xhtml+xml' => 'html', 'text/html' => 'html', 'text/css' => 'css'); # Which type is the current document? $this->docType = isset($contentType[$mime]) ? $contentType[$mime] : false; break; } } } else { // Unable to split, save whole string $this->headers[] = trim($header); } # Return bytes return strlen($header); }