php/WP_CLI/WpHttpCacheManager.php
public function filter_pre_http_request( $response, $args, $url ) {
		// check if whitelisted
		if ( ! isset( $this->whitelist[ $url ] ) ) {
			return $response;
		}
		// check if downloading
		if ( 'GET' !== $args['method'] || empty( $args['filename'] ) ) {
			return $response;
		}
		// check cache and export to designated location
		$filename = $this->cache->has( $this->whitelist[ $url ]['key'], $this->whitelist[ $url ]['ttl'] );
		if ( $filename ) {
			WP_CLI::log( sprintf( 'Using cached file \'%s\'...', $filename ) );
			if ( copy( $filename, $args['filename'] ) ) {
				// simulate successful download response
				return array(
					'response' => array(
						'code'    => 200,
						'message' => 'OK',
					),
					'filename' => $args['filename'],
				);
			}

			WP_CLI::error( sprintf( 'Error copying cached file %s to %s', $filename, $url ) );
		}
		return $response;
	}
public function filter_pre_http_request( $response, $args, $url ) {
		// check if whitelisted
		if ( ! isset( $this->whitelist[ $url ] ) ) {
			return $response;
		}
		// check if downloading
		if ( 'GET' !== $args['method'] || empty( $args['filename'] ) ) {
			return $response;
		}
		// check cache and export to designated location
		$filename = $this->cache->has( $this->whitelist[ $url ]['key'], $this->whitelist[ $url ]['ttl'] );
		if ( $filename ) {
			WP_CLI::log( sprintf( 'Using cached file \'%s\'...', $filename ) );
			if ( copy( $filename, $args['filename'] ) ) {
				// simulate successful download response
				return array(
					'response' => array(
						'code'    => 200,
						'message' => 'OK',
					),
					'filename' => $args['filename'],
				);
			}

			WP_CLI::error( sprintf( 'Error copying cached file %s to %s', $filename, $url ) );
		}
		return $response;
	}
public function filter_pre_http_request ( $ response , $ args , $ url ) { // check if whitelisted if ( ! isset ( $ this -> whitelist [ $ url ] ) ) { return $ response ; } // check if downloading if ( 'GET' !== $ args [ 'method' ] || empty ( $ args [ 'filename' ] ) ) { return $ response ; } // check cache and export to designated location $ filename = $ this -> cache -> has ( $ this -> whitelist [ $ url ] [ 'key' ] , $ this -> whitelist [ $ url ] [ 'ttl' ] ) ; if ( $ filename ) { WP_CLI :: log ( sprintf ( 'Using cached file \'%s\'...' , $ filename ) ) ; if ( copy ( $ filename , $ args [ 'filename' ] ) ) { // simulate successful download response return array ( 'response' => array ( 'code' => 200 , 'message' => 'OK' , ) , 'filename' => $ args [ 'filename' ] , ) ; } WP_CLI :: error ( sprintf ( 'Error copying cached file %s to %s' , $ filename , $ url ) ) ; } return $ response ; }
short circuit wp http api with cached file
short circuit wp http api with cached file