/[classpath]/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java
ViewVC logotype

Diff of /classpath/gnu/java/net/protocol/http/HTTPURLConnection.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by mark, Wed Apr 27 08:55:56 2005 UTC revision 1.9 by gnu_andrew, Thu May 26 16:53:36 2005 UTC
# Line 233  public class HTTPURLConnection Line 233  public class HTTPURLConnection
233            {            {
234              // Follow redirect              // Follow redirect
235              String location = response.getHeader("Location");              String location = response.getHeader("Location");
236              String connectionUri = connection.getURI();              if (location != null)
             int start = connectionUri.length();  
             if (location.startsWith(connectionUri) &&  
                 location.charAt(start) == '/')  
               {  
                 file = location.substring(start);  
                 retry = true;  
               }  
             else if (location.startsWith("http:"))  
               {  
                 connection.close();  
                 connection = null;  
                 secure = false;  
                 start = 7;  
                 int end = location.indexOf('/', start);  
                 host = location.substring(start, end);  
                 int ci = host.lastIndexOf(':');  
                 if (ci != -1)  
                   {  
                     port = Integer.parseInt(host.substring (ci + 1));  
                     host = host.substring(0, ci);  
                   }  
                 else  
                   {  
                     port = HTTPConnection.HTTP_PORT;  
                   }  
                 file = location.substring(end);  
                 retry = true;  
               }  
             else if (location.startsWith("https:"))  
               {  
                 connection.close();  
                 connection = null;  
                 secure = true;  
                 start = 8;  
                 int end = location.indexOf('/', start);  
                 host = location.substring(start, end);  
                 int ci = host.lastIndexOf(':');  
                 if (ci != -1)  
                   {  
                     port = Integer.parseInt(host.substring (ci + 1));  
                     host = host.substring(0, ci);  
                   }  
                 else  
                   {  
                     port = HTTPConnection.HTTPS_PORT;  
                   }  
                 file = location.substring(end);  
                 retry = true;  
               }  
             else if (location.length() > 0)  
237                {                {
238                  // Malformed absolute URI, treat as file part of URI                  String connectionUri = connection.getURI();
239                  if (location.charAt(0) == '/')                  int start = connectionUri.length();
240                    if (location.startsWith(connectionUri) &&
241                        location.charAt(start) == '/')
242                    {                    {
243                      // Absolute path                      file = location.substring(start);
244                      file = location;                      retry = true;
245                    }                    }
246                  else                  else if (location.startsWith("http:"))
247                    {                    {
248                      // Relative path                      connection.close();
249                      int lsi = file.lastIndexOf('/');                      connection = null;
250                      file = (lsi == -1) ? "/" : file.substring(0, lsi + 1);                      secure = false;
251                        start = 7;
252                        int end = location.indexOf('/', start);
253                        host = location.substring(start, end);
254                        int ci = host.lastIndexOf(':');
255                        if (ci != -1)
256                          {
257                            port = Integer.parseInt(host.substring (ci + 1));
258                            host = host.substring(0, ci);
259                          }
260                        else
261                          {
262                            port = HTTPConnection.HTTP_PORT;
263                          }
264                        file = location.substring(end);
265                        retry = true;
266                      }
267                    else if (location.startsWith("https:"))
268                      {
269                        connection.close();
270                        connection = null;
271                        secure = true;
272                        start = 8;
273                        int end = location.indexOf('/', start);
274                        host = location.substring(start, end);
275                        int ci = host.lastIndexOf(':');
276                        if (ci != -1)
277                          {
278                            port = Integer.parseInt(host.substring (ci + 1));
279                            host = host.substring(0, ci);
280                          }
281                        else
282                          {
283                            port = HTTPConnection.HTTPS_PORT;
284                          }
285                        file = location.substring(end);
286                        retry = true;
287                      }
288                    else if (location.length() > 0)
289                      {
290                        // Malformed absolute URI, treat as file part of URI
291                        if (location.charAt(0) == '/')
292                          {
293                            // Absolute path
294                            file = location;
295                          }
296                        else
297                          {
298                            // Relative path
299                            int lsi = file.lastIndexOf('/');
300                            file = (lsi == -1) ? "/" : file.substring(0, lsi + 1);
301                      file += location;                      file += location;
302                          }
303                        retry = true;
304                    }                    }
                 retry = true;  
305                }                }
306            }            }
307          else          else
308            {            {
309              responseSink = new ByteArrayInputStream(reader.toByteArray ());              responseSink = new ByteArrayInputStream(reader.toByteArray ());
310              if (response.getCode() == 404)              if (response.getCode() == 404)
311                {                errorSink = responseSink;
                 errorSink = responseSink;  
                 throw new FileNotFoundException(url.toString());  
               }  
312            }            }
313        }        }
314      while (retry);      while (retry);

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26