ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/Search/HttpHandler.cpp
(Generate patch)

Comparing trunk/Search/HttpHandler.cpp (file contents):
Revision 17 by douglas, 2002-12-09T18:31:11-08:00 vs.
Revision 18 by douglas, 2002-12-09T21:40:12-08:00

# Line 63 | Line 63 | HttpHandler::HttpHandler()
63   #endif // _WIN32
64  
65          begin = 0;
66 +        length = 0;
67 +        chunked = false;
68   }
69  
70   HttpHandler::~HttpHandler()
# Line 131 | Line 133 | bool HttpHandler::handle(URL &url, bool
133                  delete [] port;
134          }
135  
136 +        putline("Connection: close");
137          putline();
138  
139 <        string line = getline();
139 >        code response;
140 >        string line;
141  
142 <        if (line.find("HTTP/") != 0)
142 >        do
143          {
144 <                return answer;
141 <        }
144 >                line = getline();
145  
146 <        unsigned dot = line.find('.');
147 <        unsigned space = line.find(' ');
146 >                if (line.find("HTTP/") != 0)
147 >                {
148 >                        return answer;
149 >                }
150  
151 <        unsigned major = strtoul(line.substr(5, dot - 5).c_str(), 0, 0);
152 <        unsigned minor = strtoul(line.substr(dot + 1, space - dot - 1).c_str(), 0,
148 <                0);
151 >                unsigned dot = line.find('.');
152 >                unsigned space = line.find(' ');
153  
154 <        if (major > 1 || minor < 1)
155 <        {
156 <                cerr << program << ": Potentially Incompatible Server: HTTP/" << major
153 <                        << "." << minor << "\n";
154 >                unsigned major = strtoul(line.substr(5, dot - 5).c_str(), 0, 0);
155 >                unsigned minor = strtoul(line.substr(dot + 1, space - dot - 1).c_str(), 0,
156 >                        0);
157  
158 <                return answer;
159 <        }
158 >                if (major > 1 || minor < 1)
159 >                {
160 >                        cerr << program << ": Potentially Incompatible Server: HTTP/" << major
161 >                                << "." << minor << "\n";
162 >
163 >                        return answer;
164 >                }
165 >
166 >                response = code(strtoul(line.substr(space + 1).c_str(), 0, 0));
167  
168 <        code response = code(strtoul(line.substr(space + 1).c_str(), 0, 0));
168 >                if (response < ok) do line = getline(); while (line != "");
169 >        }
170 >        while (response < ok);
171  
172          do
173          {
174                  line = getline();
175 +
176 +                if (line != "")
177 +                {
178 +                        unsigned colon = line.find(':');
179 +
180 +                        string field = line.substr(0, colon);
181 +                        string value = line.substr(colon + 1);
182 +
183 +                        while (isspace(value[0])) value.erase(0, 1);
184 +
185 + //                      if (field =
186 +                }
187          }
188          while (line != "");
189  
190          switch (response)
191          {
192          case ok:
193 +                if (debug) cerr << "response = " << response << "\n";
194                  answer = true;
195                  break;
196 <        case choices:
172 <                break;
196 >        case choices:
197          case moved:
174                break;
198          case found:
199 +                if (debug) cerr << "response = " << response << "\n"
200 +                        << "location = " << location << "\n";
201 +                location = getLink(location, url);
202                  break;
203          case notfound:
178                break;
204          case internal:
205 +                if (debug) cerr << "response = " << response << "\n";
206                  break;
207          default:
208 +                if (debug) cerr << "response = " << response << "\n";
209 +                if (response <= 299)
210 +                {
211 +                        answer = true;
212 +                }
213 +                else if (response <= 399)
214 +                {
215 +                        location = getLink(location, url);
216 +                }
217                  break;
218          }
219  
# Line 227 | Line 262 | bool HttpHandler::good()
262  
263   void HttpHandler::clear()
264   {
265 +        closesocket(http);
266 +
267          type = "";
268          length = 0;
269          location = "";
270          begin = 0;
271          page = "";
272 +        chunked = false;
273   }
274  
275   void HttpHandler::putline(const string line)
# Line 266 | Line 304 | string HttpHandler::getline()
304          return line;
305   }
306  
307 < void HttpHandler::error(const string prefix, bool host)
307 > void HttpHandler::error(const string& prefix, bool host)
308   {
309   #ifdef _WIN32
310          string error;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines