<commit_before>//
//  CORS.swift
//  GrubAPI
//
//  Created by <NAME> on 3/22/17.
//
//

import HTTP
import JSON
import Vapor

class CORS: Middleware {
    func respond(to request: Request, chainingTo chain: Responder) throws -> Response {
        let response: Response
        if request.isPreflight {
            response = "".makeResponse()
        } else {
            response = try chain.respond(to: request)
        }
        
        response.headers["Access-Control-Allow-Origin"] = request.headers["Origin"] ?? "*";
        response.headers["Access-Control-Allow-Headers"] = "X-Requested-With, Origin, Content-Type, Accept, Authorization"
        response.headers["Access-Control-Allow-Methods"] = "POST, GET, PUT, OPTIONS, DELETE, PATCH"
        return response
    }
}

extension Request {
    var isPreflight: Bool {
        return method == .options
            && headers["Access-Control-Request-Method"] != nil
    }
}<commit_msg>Shrug CORS Fix<commit_after>//
//  CORS.swift
//  GrubAPI
//
//  Created by <NAME> on 3/22/17.
//
//

import HTTP
import JSON
import Vapor

class CORS: Middleware {
    func respond(to request: Request, chainingTo chain: Responder) throws -> Response {
        let response: Response
        if request.isPreflight {
            response = "".makeResponse()
        } else {
            response = try chain.respond(to: request)
        }
        
        response.headers["Access-Control-Allow-Origin"] = "*";
        response.headers["Access-Control-Allow-Headers"] = "X-Requested-With, Origin, Content-Type, Accept, Authorization"
        response.headers["Access-Control-Allow-Methods"] = "POST, GET, PUT, OPTIONS, DELETE, PATCH"
        return response
    }
}

extension Request {
    var isPreflight: Bool {
        return method == .options
            && headers["Access-Control-Request-Method"] != nil
    }
}
{'fraction_non_alphanumeric': 0.1302250803858521, 'fraction_numerical': 0.0053590568060021436, 'mean_word_length': 2.406934306569343, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4973272', 'n_tokens_mistral': 556, 'n_tokens_neox': 540, 'n_words': 131}