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 import struct http4swift.HTTPRequest 0026 0027 public protocol Request{ 0028 0029 var method
ContentType.swift:53 extension Request {Request.swift:39 extension Request {Request.swift:49 struct RawRequest: Request {Request.swift:84 struct ParameterizedRequest: Request {Request.swift:86 let underlying: RequestRequest.swift:90 init(underlying: Request, parameters: [String: String]) {Request.swift:127 struct FixedRequest: Request {Router.swift:25 public typealias Handler = (Request) -> (ResponseSource)Router.swift:36 func dispatch(request: Request) -> Response? {: String { get } 0030 var path
Request.swift:96 return underlying.methodRouter.swift:38 if entry.0 == request.method {: String { get } 0031 var proto
Request.swift:100 return underlying.pathRouter.swift:39 if let result = entry.1.match(request.path) {: String { get } 0032 var headers
Request.swift:104 return underlying.proto: [String: String] { get } 0033 var body
ContentType.swift:56 if let type = headers["Content-Type"] {Request.swift:108 return underlying.headers: [CChar] { get } 0034 var bodyString: String { get } 0035 var parameters
Request.swift:42 var buffer = bodyRequest.swift:112 return underlying.body: [String: String] { get } 0036 0037 } 0038 0039 extension Request { 0040 0041 public var bodyString: String { 0042 var buffer = body 0043 buffer.append(CChar(0)) 0044 return String.fromCString(buffer) ?? "" 0045 } 0046 0047 } 0048 0049 struct RawRequest: Request { 0050 0051 let underlying: HTTPRequest 0052 0053 init(underlying: HTTPRequest) { 0054 self.underlying = underlying 0055 } 0056 0057 var method: String { 0058 return underlying.method 0059 } 0060 0061 var path: String { 0062 return underlying.path 0063 } 0064 0065 var proto: String { 0066 return underlying.proto 0067 } 0068 0069 var headers: [String: String] { 0070 return underlying.headers 0071 } 0072 0073 var body: [CChar] { 0074 return underlying.body 0075 } 0076 0077 var parameters: [String: String] { 0078 // TODO: return from URI query or body parameters 0079 return [String: String]() 0080 } 0081 0082 } 0083 0084 struct ParameterizedRequest
Request.swift:117 var fields = underlying.parameters: Request { 0085 0086 let underlying
Router.swift:41 let wrapped = ParameterizedRequest(: Request 0087 0088 let params
Request.swift:91 self.underlying = underlyingRequest.swift:96 return underlying.methodRequest.swift:100 return underlying.pathRequest.swift:104 return underlying.protoRequest.swift:108 return underlying.headersRequest.swift:112 return underlying.bodyRequest.swift:117 var fields = underlying.parameters: [String: String] 0089 0090 init
Request.swift:92 self.params = parametersRequest.swift:118 params.forEach { (key, value) in(underlying: Request, parameters: [String: String]) { 0091 self.underlying = underlying 0092 self.params = parameters 0093 } 0094 0095 var method: String { 0096 return underlying.method 0097 } 0098 0099 var path: String { 0100 return underlying.path 0101 } 0102 0103 var proto: String { 0104 return underlying.proto 0105 } 0106 0107 var headers: [String: String] { 0108 return underlying.headers 0109 } 0110 0111 var body: [CChar] { 0112 return underlying.body 0113 } 0114 0115 var parameters: [String: String] { 0116 get { 0117 var fields = underlying.parameters 0118 params.forEach { (key, value) in 0119 fields.updateValue(value, forKey: key) 0120 } 0121 return fields 0122 } 0123 } 0124 0125 } 0126 0127 struct FixedRequest: Request { 0128 0129 var method: String = "GET" 0130 var path: String = "/" 0131 var proto: String = "HTTP/1.0" 0132 var headers: [String: String] = [String: String]() 0133 var body: [CChar] = [CChar]() 0134 var parameters: [String: String] = [String: String]() 0135 0136 } 0137
Router.swift:41 let wrapped = ParameterizedRequest(