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());
102 sprintf_s(tmp, sizeof(tmp), "%lld", len);
104 sprintf(tmp, "%lld", len);
106 if (strcmp(tmp, val->cString()) == 0)
108 content_length = len;
113 if (MIMEType == NULL)
115 MIMEType = String::stringWithUTF8String("text/plain");
117 if (encoding == NULL)
119 encoding = String::stringWithUTF8String("us-ascii");
122 URLResponse *ret = URLResponse::initWithURL(url, MIMEType, content_length, encoding);
128 _statusCode = statusCode;
129 _HTTPVersion = HTTPVersion;
130 _HTTPVersion->retain();
131 _headerFields = headerFields;
132 _headerFields->retain();
137 Integer HTTPURLResponse::statusCode()
139 DebugLog2("HTTPURLResponse::statusCode()");
144 Dictionary *HTTPURLResponse::allHeaderFields()
146 DebugLog2("HTTPURLResponse::allHeaderFields()");
148 return _headerFields;
151 const char *HTTPURLResponse::className()
153 return "HTTPURLResponse";