+import S4
+import MediaType
+
 extension Request {
     ///URL parameters (ex: `:id`).
     public var parameters: [String: String] {


        return cookies
    }

    private func parseFormEncoded(_ string: String) -> [String: String] {
        var formEncoded: [String: String] = [:]

        for pair in string.split(byString: "&") {

        }
    }
}

extension Data {
    func split(separatedBy separator: Data) -> [Data] {
        var ranges = [(from: Int, to: Int)]()
        var parts = [Data]()
        
        // Find occurences of boundries
        for (index, element) in self.enumerated() {
            guard element == separator.first && self.count >= index + separator.count else {
                continue
            }
            
            guard self[index + separator.count - 1] == separator.bytes.last && Data(self[index..<(index+separator.count)]) == separator else {
                continue
            }
            
            ranges.append((index, index + separator.count))
        }
        
        for (pos, range) in ranges.enumerated() where pos < ranges.count - 1 {
            // Take the data inbetween this and the next boundry
            let nextRange = ranges[pos + 1]
            
            parts.append(Data(self[range.to..<nextRange.from]))
        }
        
        return parts
    }
}

internal enum MultiPart {
    case file(MediaType, Data)
    case input(String)
}