0001 import Nest 0002 0003 0004 public struct Request : RequestType, CustomStringConvertible, CustomDebugStringConvertible { 0005 public var method:String 0006 public var path
Request.swift:30 return "\(method) \(path)"Request.swift:34 let request = ["\(method) \(path)"] + headers.map { "\($0) \($1)" }:String 0007 public var headers:[Header] 0008 public var body:String? 0009 public var params:[String:String] 0010 public var cookies:[String:String] 0011 0012 public init(method:String, path:String, headers:[Header]? = nil, body:String? = nil) { 0013 self.method = method 0014 self.path = path 0015 self.headers = headers ?? [] 0016 self.body = body 0017 self.params = [:] 0018 self.cookies = [:] 0019 0020 if let rawCookie = (self.headers.filter { $0.0.lowercaseString == "Cookies".lowercaseString }.first?.1) { 0021 let cookiePairs = rawCookie.characters.split(";").flatMap(String.init) 0022 for cookie in cookiePairs { 0023 let keyValue = cookie.characters.split("=").flatMap(String.init) 0024 self.cookies[keyValue[0]] = keyValue[1] 0025 } 0026 } 0027 } 0028 0029 public var description:String { 0030 return "\(method) \(path)" 0031 } 0032 0033 public var debugDescription:String { 0034 let request = ["\(method) \(path)"] + headers.map { "\($0) \($1)" } 0035 return request.joinWithSeparator("\n") 0036 } 0037 } 0038 0039 0040 extension RequestType { 0041 public subscript(header: String) -> String? { 0042 get { 0043 return headers.filter { $0.0.lowercaseString == header.lowercaseString }.first?.1 0044 } 0045 } 0046 0047 /// Returns the Host header 0048 public var host:String? { 0049 return self["Host"] 0050 } 0051 0052 /// Returns the Content-Type header 0053 public var contentType:String? { 0054 return self["Content-Type"] 0055 } 0056 0057 /// Returns the Content-Length header 0058 public var contentLength:Int? { 0059 if let contentLength = self["Content-Length"] { 0060 return Int(contentLength) 0061 } 0062 0063 return nil 0064 } 0065 0066 /// Returns the Accept header 0067 public var accept:String? { 0068 return self["Accept"] 0069 } 0070 0071 /// Returns the Authorization header 0072 public var authorization:String? { 0073 return self["Authorization"] 0074 } 0075 0076 } 0077
Request.swift:30 return "\(method) \(path)"Request.swift:34 let request = ["\(method) \(path)"] + headers.map { "\($0) \($1)" }