<commit_before><?php
namespace API\Middleware;

class JSON extends \Slim\Middleware
{
    public function __construct($root = '')
    {
        $this->root = $root;
    }
    
    public function call()
    {
        if (preg_match('|^' . $this->root . '.*|', $this->app->request->getResourceUri())) {

            // Force response headers to JSON
            $this->app->response->headers->set(
                'Content-Type',
                'application/json'
            );
            
            $method = strtolower($this->app->request->getMethod());
            $mediaType = $this->app->request->getMediaType();

            if (in_array($method, array('post', 'put', 'patch')) && '' !== $this->app->request()->getBody()) {
                if (empty($mediaType) || $mediaType !== 'application/json') {
                    $this->app->halt(415);
                }
            }
        }
        $this->next->call();
    }
}<commit_msg>Padronização dos dadpos de entrada. Agora as URIs obedecem a RFC 3986 (http://www.ietf.org/rfc/rfc3986.txt). Para isso o Content-Type deve ser application/x-www-form-urlencoded<commit_after><?php
namespace API\Middleware;

class JSON extends \Slim\Middleware
{
    public function __construct($root = '')
    {
        $this->root = $root;
    }
    
    public function call()
    {
        if (preg_match('|^' . $this->root . '.*|', $this->app->request->getResourceUri())) {

            // Force response headers to JSON
            $this->app->response->headers->set(
                'Content-Type',
                'application/json'
            );
            
            $method = strtolower($this->app->request->getMethod());
            $mediaType = $this->app->request->getMediaType();

            if (in_array($method, array('post', 'put', 'patch')) && '' !== $this->app->request()->getBody()) {
                // http://www.ietf.org/rfc/rfc3986.txt
                if (empty($mediaType) || $mediaType !== 'application/x-www-form-urlencoded') {
                    $this->app->halt(415);
                }
            }
        }
        $this->next->call();
    }
}
{'fraction_non_alphanumeric': 0.17788235294117646, 'fraction_numerical': 0.008470588235294117, 'mean_word_length': 1.804749340369393, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '5771784', 'n_tokens_mistral': 640, 'n_tokens_neox': 613, 'n_words': 106}