swifter icon indicating copy to clipboard operation
swifter copied to clipboard

Failed to send response: writeFailed("Broken pipe")

Open starqueen106 opened this issue 8 years ago • 0 comments

current i am using the decrypted and write on local http server but i getting error "Failed to send response: writeFailed("Broken pipe")"

public func sharedEncryptedFile(_ path: String) -> ((HttpRequest) -> HttpResponse) { return { r in

return HttpResponse.raw(200, "OK", nil, {
      
    if let stream:InputStream = InputStream(fileAtPath: path)
    {
        var buf:[UInt8] = [UInt8](repeating: 0, count: 35344)
        stream.open()
        
        let key: Array<UInt8> = [0x477, 0x71, 0x76, 0x71, 0x70, 0x7F, 0x77, 0x55, 0x44, 0x55, 0x77, 0x70, 0x8F, 0x9E, 0x34, 0x36]
        let iv: Array<UInt8> = [0x93,0x25,0x47,0x79,0xcb,0x2d,0x3f,0x02,0x18,0x26,0x14,0x42,0x90,0x1e,0x82,0xba]
        let aes = try! AES(key: key, iv: iv, blockMode: .CBC, padding: NoPadding())
        
        while true{
            let len = stream.read(&buf , maxLength: buf.count)
            
            let decrypted = try! aes.decrypt(buf)
            let cnt = decrypted.count
            try $0.write(decrypted)

            if len < buf.count
            {
                stream.close()
                break
            }
        }
    }
    
})
}

}

it;s code is bad ? Thanks

starqueen106 avatar Aug 02 '17 02:08 starqueen106