diff options
Diffstat (limited to 'Zotlabs/Web')
-rw-r--r-- | Zotlabs/Web/HTTPHeaders.php | 46 | ||||
-rw-r--r-- | Zotlabs/Web/Router.php | 25 |
2 files changed, 56 insertions, 15 deletions
diff --git a/Zotlabs/Web/HTTPHeaders.php b/Zotlabs/Web/HTTPHeaders.php new file mode 100644 index 000000000..1e4c1bf84 --- /dev/null +++ b/Zotlabs/Web/HTTPHeaders.php @@ -0,0 +1,46 @@ +<?php + +namespace Zotlabs\Web; + +class HTTPHeaders { + + private $in_progress = []; + private $parsed = []; + + + function __construct($headers) { + + $lines = explode("\n",str_replace("\r",'',$headers)); + if($lines) { + foreach($lines as $line) { + if(preg_match('/^\s+/',$line,$matches) && trim($line)) { + if($this->in_progress['k']) { + $this->in_progress['v'] .= ' ' . ltrim($line); + continue; + } + } + else { + if($this->in_progress['k']) { + $this->parsed[] = [ $this->in_progress['k'] => $this->in_progress['v'] ]; + $this->in_progress = []; + } + + $this->in_progress['k'] = strtolower(substr($line,0,strpos($line,':'))); + $this->in_progress['v'] = ltrim(substr($line,strpos($line,':') + 1)); + } + + } + if($this->in_progress['k']) { + $this->parsed[] = [ $this->in_progress['k'] => $this->in_progress['v'] ]; + $this->in_progress = []; + } + } + } + + function fetch() { + return $this->parsed; + } +} + + + diff --git a/Zotlabs/Web/Router.php b/Zotlabs/Web/Router.php index 271836ba9..ba2e78b25 100644 --- a/Zotlabs/Web/Router.php +++ b/Zotlabs/Web/Router.php @@ -121,29 +121,24 @@ class Router { /* * The URL provided does not resolve to a valid module. - * - * On Dreamhost sites, quite often things go wrong for no apparent reason and they send us to '/internal_error.html'. - * We don't like doing this, but as it occasionally accounts for 10-20% or more of all site traffic - - * we are going to trap this and redirect back to the requested page. As long as you don't have a critical error on your page - * this will often succeed and eventually do the right thing. - * - * Otherwise we are going to emit a 404 not found. */ if(! (\App::$module_loaded)) { - // Stupid browser tried to pre-fetch our Javascript img template. Don't log the event or return anything - just quietly exit. + $x = [ + 'module' => $module, + 'installed' => \App::$module_loaded, + 'controller' => $this->controller + ]; + call_hooks('page_not_found',$x); + + // Stupid browser tried to pre-fetch our Javascript img template. + // Don't log the event or return anything - just quietly exit. + if((x($_SERVER, 'QUERY_STRING')) && preg_match('/{[0-9]}/', $_SERVER['QUERY_STRING']) !== 0) { killme(); } - if((x($_SERVER, 'QUERY_STRING')) - && ($_SERVER['QUERY_STRING'] === 'q=internal_error.html') - && \App::$config['system']['dreamhost_error_hack']) { - logger('index.php: dreamhost_error_hack invoked. Original URI =' . $_SERVER['REQUEST_URI'],LOGGER_DEBUG); - goaway(z_root() . $_SERVER['REQUEST_URI']); - } - if(get_config('system','log_404',true)) { logger("Module {$module} not found.", LOGGER_DEBUG, LOG_WARNING); logger('index.php: page not found: ' . $_SERVER['REQUEST_URI'] |