 /// A web request handler which can be used to return static disk-based files to the client.
 /// Supports byte ranges, ETags and streaming very large files.
 public struct StaticFileHandler {
-	
+
 	let chunkedBufferSize = 1024*200
 	let documentRoot: String
 	let allowResponseFilters: Bool
-	
+
 	/// Public initializer given a document root.
-	/// If allowResponseFilters is false (which is the default) then the file will be sent in 
+	/// If allowResponseFilters is false (which is the default) then the file will be sent in
 	/// the most effecient way possible and output filters will be bypassed.
 	public init(documentRoot: String, allowResponseFilters: Bool = false) {
 		self.documentRoot = documentRoot
 		self.allowResponseFilters = allowResponseFilters
 	}
-	
+
     /// Main entry point. A registered URL handler should call this and pass the request and response objects.
     /// After calling this, the StaticFileHandler owns the request and will handle it until completion.
 	public func handleRequest(request: HTTPRequest, response: HTTPResponse) {

            return fnf(msg: "The file \(path) could not be opened \(error).")
        }
	}
	
	func sendFile(request: HTTPRequest, response: HTTPResponse, file: File) {
		
		response.addHeader(.acceptRanges, value: "bytes")

		if let rangeRequest = request.header(.range) {

			} else {
				completion(false)
			}
		#endif
		}
	}

	// bytes=0-3/7-9/10-15
	func parseRangeHeader(fromHeader header: String, max: Int) -> [Range<Int>] {
		let initialSplit = header.characters.split(separator: "=")
		guard initialSplit.count == 2 && String(initialSplit[0]) == "bytes" else {
			return [Range<Int>]()
		}

		let ranges = initialSplit[1]
		return ranges.split(separator: "/").flatMap { self.parseOneRange(fromString: String($0), max: max) }
	}

	// 0-3
	// 0-
	func parseOneRange(fromString string: String, max: Int) -> Range<Int>? {
		let split = string.characters.split(separator: "-")

		if split.count == 1 {
			guard let lower = Int(String(split[0])) else {
				return nil
			}
			return Range(uncheckedBounds: (lower, max))
		}

		guard let lower = Int(String(split[0])), let upper = Int(String(split[1])) else {
			return nil
		}

		return Range(uncheckedBounds: (lower, upper+1))
	}
}
