0001 /* 0002 The MIT License (MIT) 0003 0004 Copyright (c) 2015 Shun Takebayashi 0005 0006 Permission is hereby granted, free of charge, to any person obtaining a copy 0007 of this software and associated documentation files (the "Software"), to deal 0008 in the Software without restriction, including without limitation the rights 0009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 0010 copies of the Software, and to permit persons to whom the Software is 0011 furnished to do so, subject to the following conditions: 0012 0013 The above copyright notice and this permission notice shall be included in all 0014 copies or substantial portions of the Software. 0015 0016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 0019 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 0020 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 0021 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 0022 SOFTWARE. 0023 */ 0024 0025 public struct ContentType{ 0026 0027 let mediaType
ContentType.swift:37 extension ContentType: CustomStringConvertible {ContentType.swift:64 return ContentType(mediaType: mediaType, parameters: params)ContentType.swift:66 return ContentType()ContentType.swift:55 public var contentType: ContentType {: String 0028 let parameters
ContentType.swift:31 self.mediaType = mediaTypeContentType.swift:44 return "\(mediaType); \(pairs.joinWithSeparator("; "))"ContentType.swift:47 return mediaType: [String: String] 0029 0030 init
ContentType.swift:32 self.parameters = parametersContentType.swift:40 if parameters.count > 0 {ContentType.swift:41 let pairs = parameters.map { (k, v) in(mediaType: String = "text/plain", parameters: [String: String] = [:]) { 0031 self.mediaType = mediaType 0032 self.parameters = parameters 0033 } 0034 0035 } 0036 0037 extension ContentType: CustomStringConvertible { 0038 0039 public var description: String { 0040 if parameters.count > 0 { 0041 let pairs = parameters.map { (k, v) in 0042 return "\(k)=\(v)" 0043 } 0044 return "\(mediaType); \(pairs.joinWithSeparator("; "))" 0045 } 0046 else { 0047 return mediaType 0048 } 0049 } 0050 0051 } 0052 0053 extension Request { 0054 0055 public var contentType: ContentType { 0056 if let type = headers["Content-Type"] { 0057 var chunks = type.characters.split(";") 0058 let mediaType = String(chunks.removeFirst()) 0059 var params = [String: String]() 0060 chunks.filter { s in return s.contains("=") }.forEach { chunk in 0061 let kv = chunk.split("=", maxSplit: 1, allowEmptySlices: true) 0062 params[String(kv[0])] = String(kv[1]) 0063 } 0064 return ContentType(mediaType: mediaType, parameters: params) 0065 } 0066 return ContentType() 0067 } 0068 0069 } 0070
ContentType.swift:64 return ContentType(mediaType: mediaType, parameters: params)ContentType.swift:66 return ContentType()