7 #include <Raym/HTTPURLResponse.h>
19 HTTPURLResponse::HTTPURLResponse()
21 DebugLog2("HTTPURLResponse::HTTPURLResponse()");
28 HTTPURLResponse::~HTTPURLResponse()
31 RELEASE(_HTTPVersion);
32 RELEASE(_headerFields);
34 DebugLog2("HTTPURLResponse::~HTTPURLResponse()\n");
37 HTTPURLResponse *HTTPURLResponse::alloc()
39 DebugLog2("HTTPURLResponse::alloc()");
41 return new HTTPURLResponse();
44 HTTPURLResponse *HTTPURLResponse::initWithURL(URL *url, Integer statusCode, String *HTTPVersion, Dictionary *headerFields)
46 DebugLog2("HTTPURLResponse::initWithURL()");
48 if ((url == NULL) || (statusCode == 0) || (HTTPVersion == NULL) || (headerFields == NULL))
50 DebugLog3("error: parameter check NG.");
54 String *MIMEType = NULL;
55 long long content_length = URLResponseUnknownLength;
56 String *encoding = NULL;
58 Array *keys = headerFields->allKeys();
59 for (uint i = 0; i < keys->count(); ++i)
61 String *key = (String *)keys->objectAtIndex(i);
62 String *val = headerFields->stringForKey(key);
64 if (key->lowercaseString()->isEqualToString("content-type"))
67 char *value = _strdup(val->lowercaseString()->cString());
69 char *value = strdup(val->lowercaseString()->cString());
73 char *p = strchr(value, ';');
83 MIMEType = String::stringWithUTF8String(value);
86 if (MIMEType->isEqualToString("text/html"))
88 if (strncmp("charset=", p, 8) == 0)
90 encoding = String::stringWithUTF8String(&p[8]);
97 if (key->lowercaseString()->isEqualToString("content-length"))
99 long long len = atoll(val->cString());
101 sprintf_s(tmp, sizeof(tmp), "%lld", len);
102 if (strcmp(tmp, val->cString()) == 0)
104 content_length = len;
109 if (MIMEType == NULL)
111 MIMEType = String::stringWithUTF8String("text/plain");
113 if (encoding == NULL)
115 encoding = String::stringWithUTF8String("us-ascii");
118 URLResponse *ret = URLResponse::initWithURL(url, MIMEType, content_length, encoding);
124 _statusCode = statusCode;
125 _HTTPVersion = HTTPVersion;
126 _HTTPVersion->retain();
127 _headerFields = headerFields;
128 _headerFields->retain();
133 Integer HTTPURLResponse::statusCode()
135 DebugLog2("HTTPURLResponse::statusCode()");
140 Dictionary *HTTPURLResponse::allHeaderFields()
142 DebugLog2("HTTPURLResponse::allHeaderFields()");
144 return _headerFields;
147 const char *HTTPURLResponse::className()
149 return "HTTPURLResponse";