SRHttpBasedTransport Class Reference
| Inherits from | NSObject |
| Conforms to | SRClientTransport |
| Declared in | SRHttpBasedTransport.h |
Overview
SRHttpBasedTransport is an abstract class intended to be subclassed. It publishes a programmatic interface that all subclasses must adopt and provide implementations for.
SRHttpBasedTransport is responsible for starting, sending data, processing server responses, and stopping the http based transports.
Tasks
Properties
-
transportReturns an
propertyNSStringobject with the name of the activeSRHttpBasedTransport
Initializing an SRHttpBasedTransport Object
-
– initWithTransport:Initializes a new
SRHttpBasedTransport. -
– onStart:data:initializeCallback:errorCallback:Important: this method should only be called from a subclass of
SRHttpBasedTransport
Preparing requests
-
– prepareRequest:forConnection:Prepares http requests to be sent to the server
-
– getReceiveQueryString:data:Generates a query string for request made to receive data from the server
-
– getSendQueryString:Generates a query string for request made to send data from the server
-
– isRequestAborted:Performs a check to see if the underlying HTTP request was cancelled
-
– onBeforeAbort:Subclasses of
SRHttpBasedTransportshould override this method if theSRHttpBasedTransportneeds to perform cleanup before closing
Processing a response
-
– processResponse:response:timedOut:disconnected:Processes a successful server response by updating relevant connection properties and dispatching calls to [SRConnection didReceiveData]
Properties
transport
Returns an NSString object with the name of the active SRHttpBasedTransport
@property (strong, nonatomic, readonly) NSString *transportDeclared In
SRHttpBasedTransport.hInstance Methods
getReceiveQueryString:data:
Generates a query string for request made to receive data from the server
- (NSString *)getReceiveQueryString:(SRConnection *)connection data:(NSString *)dataParameters
- connection
the
SRConnectionobject that initialized theSRHttpBasedTransport
- data
the additional data to be sent to the server
Return Value
an URL encoded NSString object of the form ?transport=
Declared In
SRHttpBasedTransport.hgetSendQueryString:
Generates a query string for request made to send data from the server
- (NSString *)getSendQueryString:(SRConnection *)connectionParameters
- connection
the
SRConnectionobject that initialized theSRHttpBasedTransport
Return Value
an URL encoded NSString object of the form ?transport=
Declared In
SRHttpBasedTransport.hinitWithTransport:
Initializes a new SRHttpBasedTransport.
- (id)initWithTransport:(NSString *)transportParameters
- transport
the name of the transport
Discussion
transport name is included in the query string of all SRHttpBasedTransport
some acceptible transport names include “serverSentEvents” and “longPolling”
Declared In
SRHttpBasedTransport.hisRequestAborted:
Performs a check to see if the underlying HTTP request was cancelled
- (BOOL)isRequestAborted:(NSError *)errorParameters
- error
an error returned from the underlying HTTP request
SRHttpHelper
Return Value
YES if the request was aborted, NO if not
Declared In
SRHttpBasedTransport.honBeforeAbort:
Subclasses of SRHttpBasedTransport should override this method if the SRHttpBasedTransport needs to perform cleanup before closing
- (void)onBeforeAbort:(SRConnection *)connectionParameters
- connection
the
SRConnectionobject that initialized theSRHttpBasedTransport
Declared In
SRHttpBasedTransport.honStart:data:initializeCallback:errorCallback:
Important: this method should only be called from a subclass of SRHttpBasedTransport
- (void)onStart:(SRConnection *)connection data:(NSString *)data initializeCallback:(void ( ^ ) ( void ))initializeCallback errorCallback:(void ( ^ ) ( SRErrorByReferenceBlock ))errorCallbackParameters
- connection
the
SRConnectionobject that initialized theSRHttpBasedTransport
- data
the additional data to be sent to the server
- initializeCallback
a block to call when the
SRHttpBasedTransporthas been initialized successfully
- errorCallback
a block to call when the
SRHttpBasedTransportfailed to initialize successfully
Discussion
Important: this method should only be called from a subclass of SRHttpBasedTransport
Declared In
SRHttpBasedTransport.hprepareRequest:forConnection:
Prepares http requests to be sent to the server
- (void)prepareRequest:(id)request forConnection:(SRConnection *)connectionParameters
- request
will either be an
NSMutableURLRequestor anAFHTTPRequestOperation
- connection
the
SRConnectionobject that initialized theSRHttpBasedTransport
Discussion
if the request is an NSMutableURLRequest, [SRConneciton prepareRequest] is called
if the request is an AFHTTPRequestOperation the request object is stored in SRConnection.items as a value for the key kHttpRequest
theAFHTTPRequestOperationis stored so it can be easily retreived when theSRHttpBasedTransport` is stopped and the underlying request cancelled
Declared In
SRHttpBasedTransport.hprocessResponse:response:timedOut:disconnected:
Processes a successful server response by updating relevant connection properties and dispatching calls to [SRConnection didReceiveData]
- (void)processResponse:(SRConnection *)connection response:(NSString *)response timedOut:(BOOL *)timedOut disconnected:(BOOL *)disconnectedParameters
- connection
the
SRConnectionobject that initialized theSRHttpBasedTransport
- response
an
NSStringrepresentation of the server’s JSON response object
- timedOut
a
BOOLrespresenting if the connection received a server side timeout
- disconnected
a
BOOLrespresenting if the connection received a disconnect from the server
Declared In
SRHttpBasedTransport.h