Skip to content

Commit 785ca59

Browse files
committed
Adding common protocol implementation
Created a class NativeProtocol which basically holds the common implementation of native protocols like HTTP , FTP and so on . It implements the URLProtocol and EashHandleDelegate.Moved enableLibcurlDebugOutput and enableDebugOutput debug flags from HTTPURLProtocol to NativeProtocol as these can be enabled on EasyHandle irrespective of the protocol.Moved _HTTPURLProtocol.InternalState from HTTPURLProtocol to _NativeProtocol.InternalState. Moved inits from HTTPURLProtocol to NativeProtocol.Moved easyHandle and tempFileURL instance variables to NativeProtocol.EasyHandleDelegate methods provides functionality for transfer irrespective of protocol to NativeProtocol- fill(writeBuffer buffer: UnsafeMutableBufferPointer) , notifyDelegate(aboutUploadedData), notifyDelegate(aboutReceivedData), didReceive(data). transferCompleted(withError error: NSError?) createTransferState() createTransferBodyDataDrain However few methods like below are protocol specific hence have been overridden in respective protocol classes . didReceive(headerData data: Data, contentLength: Int64) Though the headers basically ends with \r\n irrespective of protocol the header format in FTP is different from HTTP. For e.g.: Headers in FTP looks like a plain text header with status code and description unlike the key-value pair headers in HTTP. NativeProtocol has definition for configureEasyHandle(easyHandle) which needs concrete implementation which is protocol specific by sub-classes like FTP and HTTP. For e.g.:HTTP requires some more additional configurations like adding the headers, setting allowed protocols. Moved HTTPURLProtocol. _ParsedResponseHeader from HTTPMessage.swift to NativeProtocol.swift under _NativeProtocol._ParsedResponseHeader . This implementation basically does header parsing based on \r\n delimiters. Except the fact that empty header is received in case of HTTP to mark as Header completion and 150 status marks the open of data communication in FTP New Implementation : NativeProtocol.validateHeaderComplete Should not throw error incase of simple-responseshttps://github.com//pull/1097 isCompleteHeader -> Inner method In order to support both protocols this method has been introduced -> which returns to true when the header is empty in case of HTTP. -> Returns true if the header starts with 150
1 parent c2018e5 commit 785ca59

File tree

1 file changed

+755
-0
lines changed

1 file changed

+755
-0
lines changed

0 commit comments

Comments
 (0)