smarter parseheader
This commit is contained in:
		
				
					committed by
					
						 Steffen Schröder
						Steffen Schröder
					
				
			
			
				
	
			
			
			
						parent
						
							dc2f16e678
						
					
				
				
					commit
					8dc735df42
				
			| @@ -78,8 +78,8 @@ class AsynchronousFileReader { | |||||||
| 		if (count($resultArray) < 2) { | 		if (count($resultArray) < 2) { | ||||||
| 			$result = self::INVALID_RESULT_ERROR; | 			$result = self::INVALID_RESULT_ERROR; | ||||||
| 		} else { | 		} else { | ||||||
| 			$header = $this->parse_header($resultArray[0]); | 			$header = $this->parseHeader($resultArray[0]); | ||||||
| 			if (isset($header["Transfer-Encoding"])) { | 			if (isset($header["transfer-encoding"])) { | ||||||
| 				$result = $this->decode_chunked($resultArray[1]); | 				$result = $this->decode_chunked($resultArray[1]); | ||||||
| 			} else { | 			} else { | ||||||
| 				$result = $resultArray[1]; | 				$result = $resultArray[1]; | ||||||
| @@ -105,43 +105,29 @@ class AsynchronousFileReader { | |||||||
| 		return $res; | 		return $res; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Parse The Header | 	 * Parse the Header | ||||||
| 	 * | 	 * @param $header | ||||||
| 	 * @param $raw_headers |  | ||||||
| 	 * @return array | 	 * @return array | ||||||
| 	 */ | 	 */ | ||||||
| 	private function parse_header($raw_headers) { | 	function parseHeader($header) { | ||||||
| 		$headers = array(); | 		$headers = explode(PHP_EOL, $header); | ||||||
| 		$key     = ''; | 		$output  = array(); | ||||||
|  |  | ||||||
| 		foreach(explode("\n", $raw_headers) as $i => $h) { | 		if ('HTTP' === substr($headers[0], 0, 4)) { | ||||||
| 			$h = explode(':', $h, 2); | 			list(, $output['status'], $output['status_text']) = explode(' ', $headers[0]); | ||||||
|  | 			unset($headers[0]); | ||||||
| 			if (isset($h[1])) { |  | ||||||
| 				if (!isset($headers[$h[0]])) { |  | ||||||
| 					$headers[$h[0]] = trim($h[1]); |  | ||||||
| 				} elseif (is_array($headers[$h[0]])) { |  | ||||||
| 					$headers[$h[0]] = array_merge($headers[$h[0]], array(trim($h[1]))); // [+] |  | ||||||
| 				} else { |  | ||||||
| 					$headers[$h[0]] = array_merge(array($headers[$h[0]]), array(trim($h[1]))); // [+] |  | ||||||
| 				} |  | ||||||
|  |  | ||||||
| 				$key = $h[0]; |  | ||||||
| 			} else { |  | ||||||
| 				if (substr($h[0], 0, 1) == "\t") // [+] |  | ||||||
| 				{ |  | ||||||
| 					$headers[$key] .= "\r\n\t" . trim($h[0]); |  | ||||||
| 				} elseif (!$key) { |  | ||||||
| 					$headers[0] = trim($h[0]); |  | ||||||
| 				} |  | ||||||
| 				trim($h[0]); |  | ||||||
| 			} |  | ||||||
| 		} | 		} | ||||||
| 		return $headers; |  | ||||||
|  | 		foreach($headers as $v) { | ||||||
|  | 			$h                         = preg_split('/:\s*/', $v); | ||||||
|  | 			$output[strtolower($h[0])] = $h[1]; | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		return $output; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Load a remote file | 	 * Load a remote file | ||||||
| 	 * | 	 * | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user