0001    //
0002    //  Connection.swift
0003    //  Dynamo
0004    //
0005    //  Created by John Holdsworth on 22/06/2015.
0006    //  Copyright (c) 2015 John Holdsworth. All rights reserved.
0007    //
0008    //  $Id: //depot/Dynamo/Sources/Connection.swift#13 $
0009    //
0010    //  Repo: https://github.com/johnno1962/Dynamo
0011    //
0012    
0013    import Foundation
0014    
0015    #if os(Linux)
0016    import Glibc
0017    #endif
0018    
0019    let dummyBase
Connection.swift:63
    public var url = dummyBase
Connection.swift:211
                url = NSURL( string: path, relativeToURL: dummyBase ) ?? dummyBase
Connection.swift:211
                url = NSURL( string: path, relativeToURL: dummyBase ) ?? dummyBase
Proxies.swift:38
        if httpClient.url.host == dummyBase.host {
= NSURL( string: "http://nohost" )! 0020 0021 /** 0022 HTTP return status mapping 0023 */ 0024 public var dynamoStatusText
Connection.swift:360
        let statusText = dynamoStatusText[status] ?? "Unknown Status"
= [ 0025 200: "OK", 0026 304: "Redirect", 0027 400: "Invalid request", 0028 404: "File not found", 0029 500: "Server error" 0030 ] 0031 0032 var webDateFormatter
Connection.swift:357
        addResponseHeader( "Date", value: webDateFormatter.stringFromDate( NSDate() ) )
Document.swift:121
        return webDateFormatter.stringFromDate( date )
: NSDateFormatter = { 0033 let formatter = NSDateFormatter() 0034 formatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss zzz" 0035 return formatter 0036 }() 0037 0038 public extension String { 0039 public func toInt
Connection.swift:251
            return (requestHeaders["Content-Length"] ?? requestHeaders["Content-length"])?.toInt()
Example.swift:51
            if let width = parameters["width"]?.toInt(), height = parameters["height"]?.toInt() {
Example.swift:51
            if let width = parameters["width"]?.toInt(), height = parameters["height"]?.toInt() {
Example.swift:66
            if let width = parameters["width"]?.toInt(), height = parameters["height"]?.toInt() {
Example.swift:66
            if let width = parameters["width"]?.toInt(), height = parameters["height"]?.toInt() {
() -> Int? { 0040 return Int(self) 0041 } 0042 } 0043 0044 /** 0045 Class representing a request from a client web browser. This is the request part 0046 of DynamoHTTPConnection though in practice they are the same instance. 0047 */ 0048 0049 public class DynamoHTTPRequest
Connection.swift:301
public class DynamoHTTPConnection: DynamoHTTPRequest {
: _NSObject_ { 0050 0051 let clientSocket
Connection.swift:89
        self.clientSocket = clientSocket
Connection.swift:140
        if getpeername( clientSocket, &addr, &addrLen ) == 0 {
Connection.swift:151
        return recv( clientSocket, buffer, count, 0 )
Connection.swift:305
        return send( clientSocket, buffer, count, 0 )
Connection.swift:460
        close( clientSocket )
Proxies.swift:190
                readMap[from.clientSocket] = to
Proxies.swift:191
                readMap[to.clientSocket] = from
Proxies.swift:250
                        writeMap.removeValueForKey( writer.clientSocket )
Proxies.swift:264
                if let writer = readMap[readFD], reader = readMap[writer.clientSocket]
Proxies.swift:281
                            writeMap[writer.clientSocket] = writer
Proxies.swift:293
                            writeMap.removeValueForKey( writer.clientSocket )
Proxies.swift:302
                            writeMap.removeValueForKey( writer.clientSocket )
Proxies.swift:320
            readMap.removeValueForKey( writer.clientSocket )
: Int32 0052 0053 /** reeust method received frmo browser */ 0054 public var method
Connection.swift:207
                method = components[0]
Document.swift:32
        logger( "\(httpClient.method) \(httpClient.path) \(httpClient.version) - \(httpClient.remoteAddr)" )
Document.swift:130
        if httpClient.method == "GET" {
Example.swift:44
        else if out.method == "GET" {
Proxies.swift:53
                remoteConnection.rawPrint( "\(httpClient.method) \(remotePath) \(httpClient.version)\r\n" )
Proxies.swift:86
        if httpClient.method == "CONNECT" {
Servers.swift:148
                    httpClient.response( "Invalid request: \(httpClient.method) \(httpClient.path) \(httpClient.version)" )
Swiftlets.swift:65
        if httpClient.method == "POST" {
= "GET" 0055 0056 /** path to document requests */ 0057 public var path
Connection.swift:208
                path = components[1]
Connection.swift:211
                url = NSURL( string: path, relativeToURL: dummyBase ) ?? dummyBase
Document.swift:32
        logger( "\(httpClient.method) \(httpClient.path) \(httpClient.version) - \(httpClient.remoteAddr)" )
Proxies.swift:46
                if !remotePath.hasSuffix( "/" ) && (httpClient.path.hasSuffix( "/" ) || httpClient.path.rangeOfString( "/?" ) != nil) {
Proxies.swift:46
                if !remotePath.hasSuffix( "/" ) && (httpClient.path.hasSuffix( "/" ) || httpClient.path.rangeOfString( "/?" ) != nil) {
Proxies.swift:88
            if let urlForDestination = NSURL( string: "https://\(httpClient.path)" ),
Proxies.swift:92
                    DynamoSelector.relay( httpClient.path, from: httpClient, to: remoteConnection, logger )
Servers.swift:148
                    httpClient.response( "Invalid request: \(httpClient.method) \(httpClient.path) \(httpClient.version)" )
Swiftlets.swift:367
        let path = httpClient.path
= "/" 0058 0059 /** HTTP version from browser */ 0060 public var version
Connection.swift:209
                version = components[2]
Connection.swift:361
        rawPrint( "\(version) \(status) \(statusText)\r\n\(responseHeaders)\r\n" )
Document.swift:32
        logger( "\(httpClient.method) \(httpClient.path) \(httpClient.version) - \(httpClient.remoteAddr)" )
Proxies.swift:53
                remoteConnection.rawPrint( "\(httpClient.method) \(remotePath) \(httpClient.version)\r\n" )
Servers.swift:148
                    httpClient.response( "Invalid request: \(httpClient.method) \(httpClient.path) \(httpClient.version)" )
= "HTTP/1.1" 0061 0062 /** request parsed as NSURL */ 0063 public var url
Connection.swift:211
                url = NSURL( string: path, relativeToURL: dummyBase ) ?? dummyBase
Document.swift:133
            var fullPath = "\(documentRoot)/\(siteHost)"+(httpClient.url.path ?? "/")
Proxies.swift:38
        if httpClient.url.host == dummyBase.host {
Proxies.swift:42
        if let host = httpClient.url.host {
Proxies.swift:43
            if let remoteConnection = DynamoHTTPConnection( url: httpClient.url ) {
Proxies.swift:45
                var remotePath = httpClient.url.path ?? "/"
Proxies.swift:49
                if let query = httpClient.url.query {
Swiftlets.swift:40
        if let pathInfo = httpClient.url.path where pathInfo.hasPrefix( pathPrefix ) {
Swiftlets.swift:61
        if let queryString = httpClient.url.query {
= dummyBase 0064 0065 /** HTTP request headers received */ 0066 public var requestHeaders
Connection.swift:212
                requestHeaders = [String: String]()
Connection.swift:221
                        requestHeaders[line.substringToIndex( divider )] = line.substringFromIndex( divider.advancedBy( 2 ) )
Connection.swift:241
            return requestHeaders["Content-Type"] ?? requestHeaders["Content-type"] ?? "text/plain"
Connection.swift:241
            return requestHeaders["Content-Type"] ?? requestHeaders["Content-type"] ?? "text/plain"
Connection.swift:251
            return (requestHeaders["Content-Length"] ?? requestHeaders["Content-length"])?.toInt()
Connection.swift:251
            return (requestHeaders["Content-Length"] ?? requestHeaders["Content-length"])?.toInt()
Connection.swift:431
        if compressResponse && requestHeaders["Accept-Encoding"] == "gzip, deflate" {
Document.swift:132
            let siteHost = httpClient.requestHeaders["Host"] ?? "localhost"
Document.swift:159
                if let since = httpClient.requestHeaders["If-Modified-Since"]
Proxies.swift:54
                for (name, value) in httpClient.requestHeaders {
Swiftlets.swift:56
        if let cookieHeader = httpClient.requestHeaders["Cookie"] {
Swiftlets.swift:369
        if let sspMatch = path.rangeOfString( ".ssp" )?.endIndex, host = httpClient.requestHeaders["Host"] {
= [String:String]() 0067 0068 /** status to be returned in response */ 0069 public var status
Connection.swift:217
                status = 200
Connection.swift:360
        let statusText = dynamoStatusText[status] ?? "Unknown Status"
Connection.swift:361
        rawPrint( "\(version) \(status) \(statusText)\r\n\(responseHeaders)\r\n" )
Connection.swift:382
        status = 200
Connection.swift:392
            status = theStatus
Servers.swift:147
                    httpClient.status = 400
= 200 0070 0071 // response ivars need to be here... 0072 private var responseHeaders
Connection.swift:213
                responseHeaders = ""
Connection.swift:235
        responseHeaders += "\(name): \(value)\r\n"
Connection.swift:353
        if responseHeaders == "" {
Connection.swift:361
        rawPrint( "\(version) \(status) \(statusText)\r\n\(responseHeaders)\r\n" )
= "" 0073 private var sentResponseHeaders
Connection.swift:214
                sentResponseHeaders = false
Connection.swift:329
        if !sentResponseHeaders {
Connection.swift:362
        sentResponseHeaders = true
Connection.swift:374
        if !sentResponseHeaders {
= false 0074 0075 /** "deflate" respose when possible - less bandwidth but slow */ 0076 public var compressResponse
Connection.swift:216
                compressResponse = false
Connection.swift:431
        if compressResponse && requestHeaders["Accept-Encoding"] == "gzip, deflate" {
= false 0077 0078 /** whether Content-Length has been supplied */ 0079 var knowsResponseLength
Connection.swift:215
                knowsResponseLength = false
Connection.swift:255
            knowsResponseLength = true
Swiftlets.swift:76
                return httpClient.knowsResponseLength ? .ProcessedAndReusable : .Processed
Swiftlets.swift:91
        return httpClient.knowsResponseLength ? .ProcessedAndReusable : .Processed
= false 0080 0081 // read buffering 0082 let readBuffer
Connection.swift:156
        var pos = min( readBuffer.length, count )
Connection.swift:158
            memcpy( buffer, readBuffer.bytes, pos )
Connection.swift:159
            readBuffer.replaceBytesInRange( NSMakeRange( 0, pos ), withBytes: nil, length: 0 )
Connection.swift:175
            let endOfLine = UnsafeMutablePointer<Int8>( memchr( readBuffer.bytes, newlineChar, readBuffer.length ) )
Connection.swift:175
            let endOfLine = UnsafeMutablePointer<Int8>( memchr( readBuffer.bytes, newlineChar, readBuffer.length ) )
Connection.swift:184
                let line = String.fromCString( UnsafePointer<Int8>(readBuffer.bytes) )?
Connection.swift:186
                readBuffer.replaceBytesInRange( NSMakeRange( 0, UnsafePointer<Void>(endOfLine)+1-readBuffer.bytes ), withBytes:nil, length:0 )
Connection.swift:186
                readBuffer.replaceBytesInRange( NSMakeRange( 0, UnsafePointer<Void>(endOfLine)+1-readBuffer.bytes ), withBytes:nil, length:0 )
Connection.swift:194
            readBuffer.appendBytes( buffer, length: bytesRead )
Proxies.swift:59
                if httpClient.readBuffer.length != 0 {
Proxies.swift:60
                    let readBuffer = httpClient.readBuffer
Proxies.swift:201
                if writer.readBuffer.length < maxReadAhead {
Proxies.swift:268
                        let readBuffer = writer.readBuffer
Proxies.swift:289
                    let readBuffer = writer.readBuffer
= NSMutableData() 0083 var readTotal
Proxies.swift:265
                    where FD_ISSET( readFD, readFlags ) || writer.readTotal != 0 && reader.hasBytesAvailable {
Proxies.swift:270
                        logger?( "\(writer.label) \(writer.readTotal)+\(readBuffer.length)+\(bytesRead) bytes (\(readFD)/\(readMap.count)/\(fdcount))" )
Proxies.swift:277
                            writer.readTotal += bytesRead
= 0 0084 var label
Proxies.swift:179
                to.label = "-> \(label)"
Proxies.swift:180
                from.label = "<- \(label)"
Proxies.swift:270
                        logger?( "\(writer.label) \(writer.readTotal)+\(readBuffer.length)+\(bytesRead) bytes (\(readFD)/\(readMap.count)/\(fdcount))" )
Proxies.swift:294
                            dynamoLog( "Short write on relay \(writer.label)" )
= "" 0085 0086 /** initialise connection to browser with socket */ 0087 public init
Connection.swift:125
                    self.init( clientSocket: remoteSocket )
Connection.swift:131
        self.init( clientSocket: -1 )
?( clientSocket: Int32 ) { 0088 0089 self.clientSocket = clientSocket 0090 0091 super.init() 0092 0093 if clientSocket >= 0 { 0094 #if !os(Linux) 0095 var yes: u_int = 1, yeslen = socklen_t(sizeof(yes.dynamicType)) 0096 if setsockopt( clientSocket, SOL_SOCKET, SO_NOSIGPIPE, &yes, yeslen ) < 0 { 0097 dynamoStrerror( "Could not set SO_NOSIGPIPE" ) 0098 return nil 0099 } 0100 #endif 0101 } 0102 } 0103 0104 /** initialise connection to reote host/port specified in URL */ 0105 public convenience init
Proxies.swift:43
            if let remoteConnection = DynamoHTTPConnection( url: httpClient.url ) {
Proxies.swift:89
                remoteConnection = DynamoHTTPConnection( url: urlForDestination ) {
Servers.swift:212
                    surrogateConnection = DynamoHTTPConnection( url: surrogateURL ) {
?( url: NSURL ) { 0106 if let host = url.host { 0107 let port = UInt16(url.port?.intValue ?? 80) 0108 0109 if let addr = addressForHost( host, port: port ) { 0110 var addr = addr 0111 #if os(Linux) 0112 let addrLen = socklen_t(sizeof(sockaddr)) 0113 #else 0114 let addrLen = socklen_t(addr.sa_len) 0115 #endif 0116 0117 let remoteSocket = socket( Int32(addr.sa_family), sockType, 0 ) 0118 if remoteSocket < 0 { 0119 dynamoStrerror( "Could not obtain remote socket" ) 0120 } 0121 else if connect( remoteSocket, &addr, addrLen ) < 0 { 0122 dynamoStrerror( "Could not connect to: \(host):\(port)" ) 0123 } 0124 else { 0125 self.init( clientSocket: remoteSocket ) 0126 return 0127 } 0128 } 0129 } 0130 0131 self.init( clientSocket: -1 ) 0132 return nil 0133 } 0134 0135 /** reports to IP address of remote user (if not proxied */ 0136 public var remoteAddr
Document.swift:32
        logger( "\(httpClient.method) \(httpClient.path) \(httpClient.version) - \(httpClient.remoteAddr)" )
: String { 0137 var addr = sockaddr() 0138 var addrLen = socklen_t(sizeof(addr.dynamicType)) 0139 0140 if getpeername( clientSocket, &addr, &addrLen ) == 0 { 0141 if addr.sa_family == sa_family_t(AF_INET) { 0142 return String.fromCString( inet_ntoa( sockaddr_in_cast(&addr).memory.sin_addr ) )! 0143 } 0144 } 0145 0146 return "address unknown" 0147 } 0148 0149 /** raw read from browser/remote connection */ 0150 func _read
Connection.swift:162
            let bytesRead = _read( buffer+pos, count: count-pos )
Connection.swift:190
            let bytesRead = _read( UnsafeMutablePointer<Void>(buffer), count: buffer.count )
Connection.swift:451
        return _read( buffer, count: count )
( buffer: UnsafeMutablePointer<Void>, count: Int ) -> Int { 0151 return recv( clientSocket, buffer, count, 0 ) 0152 } 0153 0154 /** read the requested number of bytes */ 0155 public func read
Connection.swift:263
            if read( &bytes, count: postLength ) != postLength {
Connection.swift:274
                where read( UnsafeMutablePointer<Void>(data.bytes), count: postLength ) == postLength {
( buffer: UnsafeMutablePointer<Void>, count: Int ) -> Int { 0156 var pos = min( readBuffer.length, count ) 0157 if pos != 0 { 0158 memcpy( buffer, readBuffer.bytes, pos ) 0159 readBuffer.replaceBytesInRange( NSMakeRange( 0, pos ), withBytes: nil, length: 0 ) 0160 } 0161 while pos < count { 0162 let bytesRead = _read( buffer+pos, count: count-pos ) 0163 if bytesRead <= 0 { 0164 break 0165 } 0166 pos += bytesRead 0167 } 0168 return pos 0169 } 0170 0171 var buffer
Connection.swift:190
            let bytesRead = _read( UnsafeMutablePointer<Void>(buffer), count: buffer.count )
Connection.swift:190
            let bytesRead = _read( UnsafeMutablePointer<Void>(buffer), count: buffer.count )
Connection.swift:194
            readBuffer.appendBytes( buffer, length: bytesRead )
= [Int8](count: 8192, repeatedValue: 0), newlineChar
Connection.swift:175
            let endOfLine = UnsafeMutablePointer<Int8>( memchr( readBuffer.bytes, newlineChar, readBuffer.length ) )
= Int32(10) 0172 0173 func readLine
Connection.swift:202
        if let request = readLine() {
Connection.swift:219
                while let line = readLine() {
() -> String? { 0174 while true { 0175 let endOfLine = UnsafeMutablePointer<Int8>( memchr( readBuffer.bytes, newlineChar, readBuffer.length ) ) 0176 if endOfLine != nil { 0177 endOfLine[0] = 0 0178 #if os(Linux) 0179 if endOfLine[-1] == 13 { 0180 endOfLine[-1] = 0 0181 } 0182 #endif 0183 0184 let line = String.fromCString( UnsafePointer<Int8>(readBuffer.bytes) )? 0185 .stringByTrimmingCharactersInSet( NSCharacterSet.whitespaceAndNewlineCharacterSet() ) 0186 readBuffer.replaceBytesInRange( NSMakeRange( 0, UnsafePointer<Void>(endOfLine)+1-readBuffer.bytes ), withBytes:nil, length:0 ) 0187 return line 0188 } 0189 0190 let bytesRead = _read( UnsafeMutablePointer<Void>(buffer), count: buffer.count ) 0191 if bytesRead <= 0 { 0192 break /// 0193 } 0194 readBuffer.appendBytes( buffer, length: bytesRead ) 0195 } 0196 return nil 0197 } 0198 0199 /** read/parse standard HTTP headers from browser */ 0200 func readHeaders
Servers.swift:127
            while httpClient.readHeaders() {
() -> Bool { 0201 0202 if let request = readLine() { 0203 0204 let components = request.componentsSeparatedByString( " " ) 0205 if components.count == 3 { 0206 0207 method = components[0] 0208 path = components[1] 0209 version = components[2] 0210 0211 url = NSURL( string: path, relativeToURL: dummyBase ) ?? dummyBase 0212 requestHeaders = [String: String]() 0213 responseHeaders = "" 0214 sentResponseHeaders = false 0215 knowsResponseLength = false 0216 compressResponse = false 0217 status = 200 0218 0219 while let line = readLine() { 0220 if let divider = line.rangeOfString( ": " )?.startIndex { 0221 requestHeaders[line.substringToIndex( divider )] = line.substringFromIndex( divider.advancedBy( 2 ) ) 0222 } 0223 else { 0224 return true 0225 } 0226 } 0227 } 0228 } 0229 0230 return false 0231 } 0232 0233 /** add a HTTP header value to the response */ 0234 public func addResponseHeader
Connection.swift:244
            addResponseHeader( "Content-Type", value: newValue )
Connection.swift:254
            addResponseHeader( "Content-Length", value: String( newValue ?? 0 ) )
Connection.swift:345
            addResponseHeader( "Set-Cookie", value: value )
Connection.swift:357
        addResponseHeader( "Date", value: webDateFormatter.stringFromDate( NSDate() ) )
Connection.swift:358
        addResponseHeader( "Server", value: "Dynamo" )
Connection.swift:434
                addResponseHeader( "Content-Encoding", value: "deflate" )
Document.swift:149
                httpClient.addResponseHeader( "Content-Encoding", value: "gzip" )
Document.swift:157
                httpClient.addResponseHeader( "Last-Modified", value: lastModified )
( name: String, value: String ) { 0235 responseHeaders += "\(name): \(value)\r\n" 0236 } 0237 0238 /** getter(request)/setter(response) for content mime type */ 0239 public var contentType
Connection.swift:354
            contentType = dynamoHtmlMimeType
Connection.swift:418
                contentType = dynamoMimeTypeMapping["json"] ?? "application/json"
Document.swift:145
            httpClient.contentType = (ext != nil ? dynamoMimeTypeMapping[ext!] : nil) ?? dynamoHtmlMimeType
Swiftlets.swift:66
            if httpClient.contentType == "application/json" {
Swiftlets.swift:79
            if httpClient.contentType == "application/x-www-form-urlencoded" {
Swiftlets.swift:187
            out.contentType = dynamoHtmlMimeType
: String { 0240 get { 0241 return requestHeaders["Content-Type"] ?? requestHeaders["Content-type"] ?? "text/plain" 0242 } 0243 set { 0244 addResponseHeader( "Content-Type", value: newValue ) 0245 } 0246 } 0247 0248 /** getter(rquest)/setter(response) for content length */ 0249 public var contentLength
Connection.swift:261
        if let postLength = contentLength {
Connection.swift:264
                dynamoLog( "Could not read \(contentLength) bytes post data from client " )
Connection.swift:273
        if let postLength = contentLength, data = NSMutableData( length: postLength )
Connection.swift:438
        contentLength = dout.length
: Int? { 0250 get { 0251 return (requestHeaders["Content-Length"] ?? requestHeaders["Content-length"])?.toInt() 0252 } 0253 set { 0254 addResponseHeader( "Content-Length", value: String( newValue ?? 0 ) ) 0255 knowsResponseLength = true 0256 } 0257 } 0258 0259 /** POST data as String */ 0260 public func postString
Swiftlets.swift:80
                if let postString = httpClient.postString() {
() -> String? { 0261 if let postLength = contentLength { 0262 var bytes = [Int8]( count: postLength + 1, repeatedValue: 0 ) 0263 if read( &bytes, count: postLength ) != postLength { 0264 dynamoLog( "Could not read \(contentLength) bytes post data from client " ) 0265 } 0266 return String.fromCString( bytes ) 0267 } 0268 return nil 0269 } 0270 0271 /** POST data as NSData */ 0272 public func postData
Connection.swift:283
        if let data = postData() {
() -> NSData? { 0273 if let postLength = contentLength, data = NSMutableData( length: postLength ) 0274 where read( UnsafeMutablePointer<Void>(data.bytes), count: postLength ) == postLength { 0275 return data 0276 } 0277 return nil 0278 } 0279 0280 #if !os(Linux) 0281 /** POST data as JSON object */ 0282 public func postJSON
Swiftlets.swift:68
                if let json = httpClient.postJSON() {
() -> AnyObject? { 0283 if let data = postData() { 0284 do { 0285 return try NSJSONSerialization.JSONObjectWithData( data, options: [] ) 0286 } catch let error as NSError { 0287 dynamoLog( "JSON parse error:: \(error)" ) 0288 } 0289 } 0290 return nil 0291 } 0292 #endif 0293 0294 } 0295 0296 /** 0297 Class representing a connection to a client web browser. One is created each time a browser 0298 connects to read the standard HTTP headers ready to present to each of the swiftlets of the server. 0299 */ 0300 0301 public class DynamoHTTPConnection
Document.swift:31
    public func present( httpClient: DynamoHTTPConnection ) -> DynamoProcessed {
Document.swift:128
    public func present( httpClient: DynamoHTTPConnection ) -> DynamoProcessed {
Example.swift:27
    override public func processRequest( out: DynamoHTTPConnection, pathInfo: String, parameters: [String:String], cookies: [String:String] ) {
Proxies.swift:36
    public func present( httpClient: DynamoHTTPConnection ) -> DynamoProcessed {
Proxies.swift:43
            if let remoteConnection = DynamoHTTPConnection( url: httpClient.url ) {
Proxies.swift:85
    public override func present( httpClient: DynamoHTTPConnection ) -> DynamoProcessed {
Proxies.swift:89
                remoteConnection = DynamoHTTPConnection( url: urlForDestination ) {
Proxies.swift:147
    var readMap = [Int32:DynamoHTTPConnection]()
Proxies.swift:148
    var writeMap = [Int32:DynamoHTTPConnection]()
Proxies.swift:149
    var queue = [(String,DynamoHTTPConnection,DynamoHTTPConnection)]()
Proxies.swift:149
    var queue = [(String,DynamoHTTPConnection,DynamoHTTPConnection)]()
Proxies.swift:151
    class func relay( label: String, from: DynamoHTTPConnection, to: DynamoHTTPConnection, _ logger: ((String) -> ())? ) {
Proxies.swift:151
    class func relay( label: String, from: DynamoHTTPConnection, to: DynamoHTTPConnection, _ logger: ((String) -> ())? ) {
Servers.swift:119
    func wrapConnection( clientSocket: Int32 ) -> DynamoHTTPConnection? {
Servers.swift:120
        return DynamoHTTPConnection( clientSocket: clientSocket )
Servers.swift:212
                    surrogateConnection = DynamoHTTPConnection( url: surrogateURL ) {
Servers.swift:222
    override func wrapConnection( clientSocket: Int32 ) -> DynamoHTTPConnection? {
Servers.swift:228
class DynamoSSLConnection: DynamoHTTPConnection {
Swiftlets.swift:38
    public func present( httpClient: DynamoHTTPConnection ) -> DynamoProcessed {
Swiftlets.swift:53
    public func process( httpClient: DynamoHTTPConnection, pathInfo: String ) -> DynamoProcessed {
Swiftlets.swift:115
    public func processRequest( out: DynamoHTTPConnection, pathInfo: String, parameters: [String:String], cookies: [String:String] ) {
Swiftlets.swift:123
    public func processJSON( out: DynamoHTTPConnection, pathInfo: String, parameters: [String:String], cookies: [String:String], json: AnyObject ) {
Swiftlets.swift:179
    public override func processRequest( out: DynamoHTTPConnection, pathInfo: String, parameters: [String : String], cookies: [String : String] ) {
Swiftlets.swift:234
    public override func processRequest( out: DynamoHTTPConnection, pathInfo: String, parameters: [String : String], cookies: [String : String] ) {
Swiftlets.swift:300
    public override func processRequest( out: DynamoHTTPConnection, pathInfo: String, parameters: [String : String], cookies: [String : String] ) {
Swiftlets.swift:365
    override public func present( httpClient: DynamoHTTPConnection ) -> DynamoProcessed {
Types.swift:69
    func present( httpClient: DynamoHTTPConnection ) -> DynamoProcessed
Types.swift:84
    func processRequest( out: DynamoHTTPConnection, pathInfo: String, parameters: [String : String], cookies: [String : String] )
: DynamoHTTPRequest { 0302 0303 /** raw write to browser/remote connection */ 0304 func _write
Connection.swift:312
            let bytesWritten = _write( buffer+pos, count: count-pos )
Connection.swift:455
        return _write( buffer, count: count )
( buffer: UnsafePointer<Void>, count: Int ) -> Int { 0305 return send( clientSocket, buffer, count, 0 ) 0306 } 0307 0308 /** write the requested number of bytes */ 0309 public func write
Connection.swift:368
            write( bytes, count: Int(strlen(bytes)) )
Connection.swift:440
        if write( dout.bytes, count: dout.length ) != dout.length {
Proxies.swift:61
                    remoteConnection.write( readBuffer.bytes, count: readBuffer.length )
( buffer: UnsafePointer<Void>, count: Int ) -> Int { 0310 var pos = 0 0311 while pos < count { 0312 let bytesWritten = _write( buffer+pos, count: count-pos ) 0313 if bytesWritten <= 0 { 0314 break 0315 } 0316 pos += bytesWritten 0317 } 0318 return pos 0319 } 0320 0321 /** flush any buffered print() output to browser */ 0322 public func flush
Connection.swift:459
        flush()
Proxies.swift:64
                remoteConnection.flush()
Proxies.swift:91
                    httpClient.flush()
Servers.swift:138
                        httpClient.flush()
Servers.swift:281
        flush()
() { 0323 // writes not buffered currently 0324 } 0325 0326 /** have browser set cookie for this session/domain/path */ 0327 public func setCookie
Swiftlets.swift:186
            out.setCookie( cookieName, value: sessionKey!, path: pathPrefix )
( name: String, value: String, domain: String? = nil, path: String? = nil, expires: Int? = nil ) { 0328 0329 if !sentResponseHeaders { 0330 var value = "\(name)=\(value.stringByAddingPercentEscapesUsingEncoding( NSUTF8StringEncoding )!)" 0331 0332 if domain != nil { 0333 value += "; Domain="+domain! 0334 } 0335 if path != nil { 0336 value += "; Path="+path! 0337 } 0338 if expires != nil { 0339 let cookieDateFormatter = NSDateFormatter() 0340 cookieDateFormatter.dateFormat = "EEE, dd-MMM-yyyy HH:mm:ss zzz" 0341 let expires = NSDate().dateByAddingTimeInterval( NSTimeInterval(expires!) ) 0342 value += "; Expires=" + cookieDateFormatter.stringFromDate( expires ) 0343 } 0344 0345 addResponseHeader( "Set-Cookie", value: value ) 0346 } 0347 else { 0348 dynamoLog( "Cookies must be set before the first HTML content is sent" ) 0349 } 0350 } 0351 0352 private func sendResponseHeaders
Connection.swift:375
            sendResponseHeaders()
Connection.swift:439
        sendResponseHeaders()
() { 0353 if responseHeaders == "" { 0354 contentType = dynamoHtmlMimeType 0355 } 0356 0357 addResponseHeader( "Date", value: webDateFormatter.stringFromDate( NSDate() ) ) 0358 addResponseHeader( "Server", value: "Dynamo" ) 0359 0360 let statusText = dynamoStatusText[status] ?? "Unknown Status" 0361 rawPrint( "\(version) \(status) \(statusText)\r\n\(responseHeaders)\r\n" ) 0362 sentResponseHeaders = true 0363 } 0364 0365 /** print a sring directly to browser */ 0366 public func rawPrint
Connection.swift:361
        rawPrint( "\(version) \(status) \(statusText)\r\n\(responseHeaders)\r\n" )
Connection.swift:377
        rawPrint( output )
Proxies.swift:53
                remoteConnection.rawPrint( "\(httpClient.method) \(remotePath) \(httpClient.version)\r\n" )
Proxies.swift:55
                    remoteConnection.rawPrint( "\(name): \(value)\r\n" )
Proxies.swift:57
                remoteConnection.rawPrint( "\r\n" )
Proxies.swift:90
                    httpClient.rawPrint( "HTTP/1.0 200 Connection established\r\nProxy-agent: Dynamo/1.0\r\n\r\n" )
( output: String ) { 0367 output.withCString { (bytes) in 0368 write( bytes, count: Int(strlen(bytes)) ) 0369 } 0370 } 0371 0372 /** print a string, sending HTTP headers if not already sent */ 0373 public func print
Example.swift:28
        out.print( html( nil ) + head( title( "Table Example" ) +
Example.swift:32
            out.print( h3( "Quick table creation example" ) )
Example.swift:33
            out.print(
Example.swift:46
                out.print( h2( title ) )
Example.swift:49
            out.print( h3( "Enter table values" ) + form( ["method": "POST"], nil ) + table( nil ) )
Example.swift:53
                    out.print( tr( nil ) )
Example.swift:55
                        out.print( td( input( ["type":"textfield", "name":"x\(x)y\(y)", "size":"5"] ) ) )
Example.swift:57
                    out.print( _tr() )
Example.swift:61
            out.print( _table()+p()+input( ["type": "submit", "value": "Complete"] )+_form() )
Example.swift:64
            out.print( h3( "Your table:" ) + table( ["border":"1"], nil ) )
Example.swift:68
                    out.print( tr( nil ) )
Example.swift:70
                        out.print( td( parameters["x\(x)y\(y)"]! ) )
Example.swift:72
                    out.print( _tr() )
Example.swift:76
            out.print( _table() )
Example.swift:79
        out.print( p() + backButton() )
( output: String ) { 0374 if !sentResponseHeaders { 0375 sendResponseHeaders() 0376 } 0377 rawPrint( output ) 0378 } 0379 0380 /** enum base response */ 0381 public func sendResponse
Document.swift:161
                    return httpClient.sendResponse( .Status( status: 304, text: "" ) )
Document.swift:165
                    return httpClient.sendResponse( .Data( data: data ) )
Document.swift:171
                return httpClient.sendResponse( .Status( status: 404, text: "<b>File not found:</b> \(fullPath)" ) )
Proxies.swift:69
                httpClient.sendResponse( .OK( html: "Unable to resolve host \(host)" ) )
( resp: DynamoResponse ) -> DynamoProcessed { 0382 status = 200 0383 0384 switch resp { 0385 case .OK( let html ): 0386 response( html ) 0387 case .JSON( let json ): 0388 responseJSON( json ) 0389 case .Data( let data ): 0390 responseData( data ) 0391 case .Status( let theStatus, let text ): 0392 status = theStatus 0393 response( text ) 0394 } 0395 0396 return .ProcessedAndReusable 0397 } 0398 0399 /** set response as a whole from a String */ 0400 public func response
Connection.swift:386
            response( html )
Connection.swift:393
            response( text )
Servers.swift:148
                    httpClient.response( "Invalid request: \(httpClient.method) \(httpClient.path) \(httpClient.version)" )
( output: String ) { 0401 output.withCString { (bytes) in 0402 #if os(Linux) 0403 responseData( NSData( bytes: UnsafeMutablePointer<Void>(bytes), 0404 length: Int(strlen( bytes )) ) ) 0405 #else 0406 responseData( NSData( bytesNoCopy: UnsafeMutablePointer<Void>(bytes), 0407 length: Int(strlen( bytes )), freeWhenDone: false ) ) 0408 #endif 0409 } 0410 } 0411 0412 /** set response as a whole from JSON object */ 0413 public func responseJSON
Connection.swift:388
            responseJSON( json )
( object: AnyObject ) { 0414 if NSJSONSerialization.isValidJSONObject( object ) { 0415 do { 0416 let json = try NSJSONSerialization.dataWithJSONObject( object, 0417 options: NSJSONWritingOptions.PrettyPrinted ) 0418 contentType = dynamoMimeTypeMapping["json"] ?? "application/json" 0419 responseData( json ) 0420 return 0421 } catch let error as NSError { 0422 dynamoLog( "Could not encode: \(object) \(error)" ) 0423 } 0424 } 0425 } 0426 0427 /** set response as a whole from NSData */ 0428 public func responseData
Connection.swift:390
            responseData( data )
Connection.swift:406
                responseData( NSData( bytesNoCopy: UnsafeMutablePointer<Void>(bytes),
Connection.swift:419
                responseData( json )
( data: NSData ) { 0429 var dout = data 0430 #if os(OSX) 0431 if compressResponse && requestHeaders["Accept-Encoding"] == "gzip, deflate" { 0432 if let deflated = dout.deflate() { 0433 dout = deflated 0434 addResponseHeader( "Content-Encoding", value: "deflate" ) 0435 } 0436 } 0437 #endif 0438 contentLength = dout.length 0439 sendResponseHeaders() 0440 if write( dout.bytes, count: dout.length ) != dout.length { 0441 dynamoLog( "Could not write \(dout.length) bytes to client " ) 0442 } 0443 } 0444 0445 // for DynamoSelector used by proxies 0446 var hasBytesAvailable
Proxies.swift:265
                    where FD_ISSET( readFD, readFlags ) || writer.readTotal != 0 && reader.hasBytesAvailable {
: Bool { 0447 return false 0448 } 0449 0450 func receive
Proxies.swift:267
                    if let bytesRead = reader.receive( &buffer, count: buffer.count ) {
( buffer: UnsafeMutablePointer<Void>, count: Int ) -> Int? { 0451 return _read( buffer, count: count ) 0452 } 0453 0454 func forward
Proxies.swift:291
                    if let bytesWritten = writer.forward( readBuffer.bytes, count: readBuffer.length ) {
( buffer: UnsafePointer<Void>, count: Int ) -> Int? { 0455 return _write( buffer, count: count ) 0456 } 0457 0458 deinit { 0459 flush() 0460 close( clientSocket ) 0461 } 0462 0463 } 0464