<commit_before><?php
namespace Ant\Bundle\ChateaClientBundle\Controller;

use Guzzle\Http\Exception\ClientErrorResponseException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class ApiProxyController extends Controller
{
    /**
     * @return \Ant\Bundle\ChateaClientBundle\Http\ApiRequestAllow
     */

    private function getApiRequestAllow()
    {
        return $this->container->get('antwebes_chateaclient_bundle.http.api_request_allow');
    }

    /**
     * Resolve api calls
     *
     * @param Request $request
     *
     * @return Response
     */
    public function apiAction(Request $request)
    {
        $pathInfo = $request->getPathInfo();

        if(!$this->getApiRequestAllow()->isAllow($pathInfo)){
            throw new NotFoundHttpException('No route allow for " '.$request->getMethod().' '.$pathInfo.'"');
        }

        $apiUri = trim($request->getRequestUri(),'/');

        try{
            return $this->container->get('antwebes_chateaclient_bundle.http.api_client')->sendRequest('GET',$apiUri);
        }catch (ClientErrorResponseException $e){
            $headersGuzzle = $e->getResponse()->getHeaders()->toArray();
            $headersSymfony = array();

            foreach($headersGuzzle as $key=>$value){
                //this header is not suporter in symfony
                if($key != 'Transfer-Encoding' && $value !== 'chunked'){
                    $headersSymfony[$key] = $value[0];
                }
            }

            return new Response($e->getResponse()->getBody(true),
                $e->getResponse()->getStatusCode(),
                $headersSymfony
            );
        }
    }
}<commit_msg>isXMLHttpRequest to calls api<commit_after><?php
namespace Ant\Bundle\ChateaClientBundle\Controller;

use Guzzle\Http\Exception\ClientErrorResponseException;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class ApiProxyController extends Controller
{
    /**
     * @return \Ant\Bundle\ChateaClientBundle\Http\ApiRequestAllow
     */

    private function getApiRequestAllow()
    {
        return $this->container->get('antwebes_chateaclient_bundle.http.api_request_allow');
    }

    /**
     * Resolve api calls
     *
     * @param Request $request
     *
     * @return Response
     */
    public function apiAction(Request $request)
    {
        if ($request->isXmlHttpRequest() or $request->headers->get('Content-Type') =='application/json') {
            $pathInfo = $request->getPathInfo();
            if(!$this->getApiRequestAllow()->isAllow($pathInfo)){
                throw new NotFoundHttpException('No route allow for " '.$request->getMethod().' '.$pathInfo.'"');
            }
            $query_string = null;
            if ($request->server->get('QUERY_STRING')){
                $query_string = '?' .$request->server->get('QUERY_STRING');
            }

            $url_api = $pathInfo . $query_string;
            $apiUri = trim($url_api,'/');
            try{
                return $this->container->get('antwebes_chateaclient_bundle.http.api_client')->sendRequest('GET',$apiUri);
            }catch (ClientErrorResponseException $e){
                $headersGuzzle = $e->getResponse()->getHeaders()->toArray();
                $headersSymfony = array();
                foreach($headersGuzzle as $key=>$value){
//this header is not suporter in symfony
                    if($key != 'Transfer-Encoding' && $value !== 'chunked'){
                        $headersSymfony[$key] = $value[0];
                    }
                }
                return new Response($e->getResponse()->getBody(true),
                    $e->getResponse()->getStatusCode(),
                    $headersSymfony
                );
            }
        }else{
            throw new NotFoundHttpException();
        }
    }
}
{'fraction_non_alphanumeric': 0.13467117988394584, 'fraction_numerical': 0.00048355899419729207, 'mean_word_length': 2.4021381578947367, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4870774', 'n_tokens_mistral': 1132, 'n_tokens_neox': 1099, 'n_words': 181}