00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef __HTTP_CONNECTION_H__
00037 #define __HTTP_CONNECTION_H__
00038
00039 #include "base/fscapi.h"
00040
00041 #if defined(FUN_IPHONE)
00042 #include <SystemConfiguration/SystemConfiguration.h>
00043 #include <SystemConfiguration/SCNetworkReachability.h>
00044 #include <CFNetwork/CFNetwork.h>
00045 #else
00046 #include <Foundation/Foundation.h>
00047 #include <CoreFoundation/CoreFoundation.h>
00048 #endif
00049
00050 #include "http/URL.h"
00051 #include "http/Proxy.h"
00052 #include "http/TransportAgent.h"
00053 #include "base/Log.h"
00054 #include "http/HttpAuthentication.h"
00055 #include "http/AbstractHttpConnection.h"
00056 #include "inputStream/AppleInputStream.h"
00057
00058 #define ERR_HTTP_TIME_OUT ERR_TRANSPORT_BASE+ 7
00059 #define ERR_HTTP_NOT_FOUND ERR_TRANSPORT_BASE+60
00060 #define ERR_HTTP_REQUEST_TIMEOUT ERR_TRANSPORT_BASE+61
00061 #define ERR_HTTP_INFLATE ERR_TRANSPORT_BASE+70
00062 #define ERR_HTTP_DEFLATE ERR_TRANSPORT_BASE+71
00063 #define ERR_HTTP_INVALID_URL ERR_TRANSPORT_BASE+72
00064
00065 BEGIN_FUNAMBOL_NAMESPACE
00066
00067 class HttpConnection : public AbstractHttpConnection
00068 {
00069 private:
00070 CFHTTPMessageRef clientRequest;
00071 CFReadStreamRef responseStream;
00072
00073 bool gotflags;
00074 bool isReachable;
00075 bool noConnectionRequired;
00076 CFStringRef http_verb;
00077
00078 public:
00079 HttpConnection(const char* user_agent);
00080 ~HttpConnection();
00081
00088 int open(const URL& url, RequestMethod method = MethodPost);
00089
00096 int close();
00097
00107 int request(InputStream& data, OutputStream& response);
00108 int request(const char* data, OutputStream& response);
00109
00110 private:
00111 bool addHttpAuthentication(CFHTTPMessageRef* request);
00112 int sendData(CFReadStreamRef requestBodyStream, OutputStream& os);
00113
00120 int getResponse();
00121
00128 int readResponseHeaders(CFHTTPMessageRef response);
00129 };
00130
00131 END_FUNAMBOL_NAMESPACE
00132
00133 #endif