Skip to content

Commit

Permalink
Merge pull request #3 from mjrider/fixes
Browse files Browse the repository at this point in the history
bugfix and a load of code cleanups
  • Loading branch information
poef committed Jun 30, 2014
2 parents 4dce80e + 49d511a commit d064072
Show file tree
Hide file tree
Showing 10 changed files with 452 additions and 452 deletions.
1 change: 0 additions & 1 deletion src/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ public static function delete( $url, $query = null, $options = array() )
{
return self::request( 'DELETE', $url, $query, $options);
}

}
35 changes: 17 additions & 18 deletions src/http/ClientInterface.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
<?php

/*
* This file is part of the Ariadne Component Library.
*
* (c) Muze <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* This file is part of the Ariadne Component Library.
*
* (c) Muze <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace arc\http;

interface ClientInterface
{
public function get( $url, $request = null, $options = array() );
interface ClientInterface
{
public function get( $url, $request = null, $options = array() );

public function post( $url, $request = null, $options = array() );
public function post( $url, $request = null, $options = array() );

public function put( $url, $request = null, $options = array() );
public function put( $url, $request = null, $options = array() );

public function delete( $url, $request = null, $options = array() );
public function delete( $url, $request = null, $options = array() );

public function request( $type, $url, $request = null, $options = array() );
public function request( $type, $url, $request = null, $options = array() );

public function headers( $headers );

}
public function headers( $headers );
}
189 changes: 96 additions & 93 deletions src/http/ClientStream.php
Original file line number Diff line number Diff line change
@@ -1,126 +1,129 @@
<?php

/*
* This file is part of the Ariadne Component Library.
*
* (c) Muze <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*
* This file is part of the Ariadne Component Library.
*
* (c) Muze <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace arc\http;

class ClientStream implements ClientInterface
{
private $options = array('headers' => array());
class ClientStream implements ClientInterface
{
private $options = array('headers' => array());

public $responseHeaders = null;
public $requestHeaders = null;
public $responseHeaders = null;
public $requestHeaders = null;

protected function parseRequestURL($url)
{
$components = parse_url( $url );
protected function parseRequestURL($url)
{
$components = parse_url( $url );

return isset($components['query']) ? $components['query'] : false;
}
return isset($components['query']) ? $components['query'] : false;
}

protected function mergeOptions()
{
$args = func_get_args();
array_unshift( $args, $this->options );

protected function mergeOptions()
{
$args = func_get_args();
array_unshift( $args, $this->options );
return call_user_func_array( 'array_merge', $args );
}

return call_user_func_array( 'array_merge', $args );
protected function buildURL($url, $request)
{
if (is_array( $request ) || $request instanceof \ArrayObject) {
$request = http_build_query( (array) $request );
}

protected function buildURL($url, $request)
{
if ( is_array( $request ) || $request instanceof \ArrayObject ) {
$request = http_build_query( (array) $request );
}
$request = (string) $request; // to force a \ar\connect\url\urlQuery to a possibly empty string.
if ($request) {
if ( strpos( (string) $url, '?' ) === false ) {
$request = '?' . $request;
} else {
$request = '&' . $request;
}
$url .= $request;
$request = (string) $request; // to force a \ar\connect\url\urlQuery to a possibly empty string.
if ($request) {
if (strpos( (string) $url, '?' ) === false) {
$request = '?' . $request;
} else {
$request = '&' . $request;
}
$url .= $request;
}

return $url;
return $url;
}

public function request( $type, $url, $request = null, $options = array() )
{
if ($type == 'GET' && $request) {
$url = $this->buildURL( $url, $request );
$request = '';
}

public function request( $type, $url, $request = null, $options = array() )
{
if ($type == 'GET' && $request) {
$url = $this->buildURL( $url, $request );
$request = '';
}
$options = $this->mergeOptions( array(
'method' => $type,
'content' => $request
), $options );

$options = $this->mergeOptions( array(
'method' => $type,
'content' => $request
), $options );
if (isset($options['header'])) {
$options['header'] .= "\r\n";
} else {
$options['header'] = '';
}

if ( isset($options['header']) ) {
$options['header'] .= "\r\n";
} else {
$options['header'] = '';
}
$options['header'] .= isset($options['headers']) ? implode( "\r\n", $options['headers'] ) ."\r\n" : '' ;
unset($options['headers']);

$options['header'] .= isset($options['headers']) ? implode( "\r\n", $options['headers'] ) ."\r\n": '' ;
unset($options['headers']);
$context = stream_context_create( array( 'http' => $options ) );
$result = @file_get_contents( (string) $url, false, $context );
$this->responseHeaders = $http_response_header; //magic php variable set by file_get_contents.
$this->requestHeaders = isset($options['header']) ? $options['header'] : '';

$context = stream_context_create( array( 'http' => $options ) );
$result = @file_get_contents( (string) $url, false, $context );
$this->responseHeaders = $http_response_header; //magic php variable set by file_get_contents.
$this->requestHeaders = isset($options['header']) ? $options['header'] : '';
return $result;
}

return $result;
}
public function __construct( $options = array() )
{
$this->options = $options;
}

public function __construct( $options = array() )
{
$this->options = $options;
public function get( $url, $request = null, $options = array() )
{
if (!isset($request)) {
$request = $this->parseRequestURL($url);
}

public function get( $url, $request = null, $options = array() )
{
if ( !isset($request) ) {
$request = $this->parseRequestURL($url);
}
return $this->request( 'GET', $url, $request, $options );
}

return $this->request( 'GET', $url, $request, $options );
}
public function post( $url, $request = null, $options = array() )
{
return $this->request( 'POST', $url, $request, $options );
}

public function post( $url, $request = null, $options = array() )
{
return $this->request( 'POST', $url, $request, $options );
}
public function put( $url, $request = null, $options = array() )
{
return $this->request( 'PUT', $url, $request, $options );
}

public function put( $url, $request = null, $options = array() )
{
return $this->request( 'PUT', $url, $request, $options );
}
public function delete( $url, $request = null, $options = array() )
{
return $this->request( 'DELETE', $url, $request, $options );
}

public function delete( $url, $request = null, $options = array() )
{
return $this->request( 'DELETE', $url, $request, $options );
public function headers($headers)
{
if (!isset($this->options['headers'])) {
$this->options['headers'] = array();
}

public function headers($headers)
{
if (!isset($this->options['headers'])) {
$this->options['headers'] = array();
}
if ( !is_array($headers) ) {
$this->headers = explode("\r\n",$headers);
if (!is_array($headers)) {
$headers = explode("\r\n", $headers);
if (end($headers) == '') {
array_pop($headers);
}

$this->options['headers'] = array_merge($this->options['headers'], $headers);

return $this;
}

$this->options['headers'] = array_merge($this->options['headers'], $headers);

return $this;
}
}
21 changes: 10 additions & 11 deletions src/noxss.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ class noxss
public static function detect()
{
foreach ([ 'GET' => $_GET, 'POST' => $_POST, 'COOKIE' => $_COOKIE ] as $method => $inputs) {
if ( is_array( $inputs ) ) {
if (is_array( $inputs )) {
self::_gatherXSSInput( $inputs, $method );
}
}
foreach (self::$xssHeaders as $header) {
if ( array_key_exists( $header, $_SERVER ) ) {
if (array_key_exists( $header, $_SERVER )) {
self::_gatherXSSInput( $_SERVER[$header], 'SERVER' );
}
}

if ( !self::$potentialXSS && count( self::$xss ) ) {
if (!self::$potentialXSS && count( self::$xss )) {
// An input with problematic tokens has been spotted, start the output buffer once
// to check the output for an occurance of that input _unchanged_
ob_start();
Expand All @@ -80,19 +80,19 @@ public static function detect()

private static function _gatherXSSInput($input, $method, $name = null)
{
if ( is_array( $input ) ) {
if (is_array( $input )) {
foreach ($input as $key => $value) {
if ( !isset($name) ) {
if (!isset($name)) {
self::_gatherXSSInput( $value, $method, $key );
} else {
self::_gatherXSSInput( $value, $method, $name );
}
}
} else {
$input = (string) $input;
if ( ( !array_key_exists( $method, self::$ignoreList ) || !array_key_exists( $name, self::$ignoreList[$method] ) )
if (( !array_key_exists( $method, self::$ignoreList ) || !array_key_exists( $name, self::$ignoreList[$method] ) )
&& ( strlen( $input ) > self::$minimumLength )
&& preg_match( self::$reXSS, $input, $matches) )
&& preg_match( self::$reXSS, $input, $matches))
{
self::$xss[ $method ][ strlen($input) ][] = $input;
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public static function prevent($f = null)
$xssDetected = self::_checkForProblems();

if ($xssDetected) {
if ( is_callable($f) ) {
if (is_callable($f)) {
$f( self::$output );
} else {
header( 'HTTP/1.1 400 Bad Request' );
Expand All @@ -139,9 +139,9 @@ private static function _checkForProblems()
foreach (self::$xss as $inputs) {
krsort( $inputs, SORT_NUMERIC );
foreach ($inputs as $values) {
if ( is_array($values) ) {
if (is_array($values)) {
foreach ($values as $value) {
if ( false !== strpos( self::$output, $value) ) {
if (false !== strpos( self::$output, $value)) {
// One of the potential XSS attack inputs has been found _unchanged_ in the output
return true;
}
Expand All @@ -157,5 +157,4 @@ public static function ignore($name, $method = 'GET')
{
self::$ignoreList[$method][$name] = 1;
}

}
1 change: 0 additions & 1 deletion src/url.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ public static function safeUrl($url)
{
return new url\Url( $url, new url\Query() );
}

}
Loading

0 comments on commit d064072

Please sign in to comment.