Fossil SCM
Change redirect handling so that (1) status codes 307 and 308 are recognized as redirects in addition to 301 and 302 and (2) the remote URL is only changed if it encounters a permanent redirect (301 or 308).
Commit
f2ca44916cb474ff5e985d03b20ccd138f8e86707dac703974cc50c453589693
Parent
0f9b648f2b7dd0b…
1 file changed
+4
-4
+4
-4
| --- src/http.c | ||
| +++ src/http.c | ||
| @@ -286,11 +286,11 @@ | ||
| 286 | 286 | g.zHttpAuth = prompt_for_httpauth_creds(); |
| 287 | 287 | transport_close(&g.url); |
| 288 | 288 | return http_exchange(pSend, pReply, useLogin, maxRedirect); |
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | - if( rc!=200 && rc!=301 && rc!=302 ){ | |
| 291 | + if( rc!=200 && rc!=301 && rc!=302 && rc!=307 && rc!=308 ){ | |
| 292 | 292 | int ii; |
| 293 | 293 | for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){} |
| 294 | 294 | while( zLine[ii]==' ' ) ii++; |
| 295 | 295 | fossil_warning("server says: %s", &zLine[ii]); |
| 296 | 296 | goto write_err; |
| @@ -300,11 +300,11 @@ | ||
| 300 | 300 | }else{ |
| 301 | 301 | closeConnection = 0; |
| 302 | 302 | } |
| 303 | 303 | }else if( g.url.isSsh && fossil_strnicmp(zLine, "status:", 7)==0 ){ |
| 304 | 304 | if( sscanf(zLine, "Status: %d", &rc)!=1 ) goto write_err; |
| 305 | - if( rc!=200 && rc!=301 && rc!=302 ){ | |
| 305 | + if( rc!=200 && rc!=301 && rc!=302 && rc!=307 && rc!=308 ){ | |
| 306 | 306 | int ii; |
| 307 | 307 | for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){} |
| 308 | 308 | while( zLine[ii]==' ' ) ii++; |
| 309 | 309 | fossil_warning("server says: %s", &zLine[ii]); |
| 310 | 310 | goto write_err; |
| @@ -320,11 +320,11 @@ | ||
| 320 | 320 | if( c=='c' || c=='C' ){ |
| 321 | 321 | closeConnection = 1; |
| 322 | 322 | }else if( c=='k' || c=='K' ){ |
| 323 | 323 | closeConnection = 0; |
| 324 | 324 | } |
| 325 | - }else if( ( rc==301 || rc==302 ) && | |
| 325 | + }else if( ( rc==301 || rc==302 || rc==307 || rc==308 ) && | |
| 326 | 326 | fossil_strnicmp(zLine, "location:", 9)==0 ){ |
| 327 | 327 | int i, j; |
| 328 | 328 | |
| 329 | 329 | if ( --maxRedirect == 0){ |
| 330 | 330 | fossil_warning("redirect limit exceeded"); |
| @@ -345,11 +345,11 @@ | ||
| 345 | 345 | transport_close(&g.url); |
| 346 | 346 | transport_global_shutdown(&g.url); |
| 347 | 347 | fSeenHttpAuth = 0; |
| 348 | 348 | if( g.zHttpAuth ) free(g.zHttpAuth); |
| 349 | 349 | g.zHttpAuth = get_httpauth(); |
| 350 | - url_remember(); | |
| 350 | + if( rc==301 || rc==308 ) url_remember(); | |
| 351 | 351 | return http_exchange(pSend, pReply, useLogin, maxRedirect); |
| 352 | 352 | }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){ |
| 353 | 353 | if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){ |
| 354 | 354 | isCompressed = 0; |
| 355 | 355 | }else if( fossil_strnicmp(&zLine[14], |
| 356 | 356 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -286,11 +286,11 @@ | |
| 286 | g.zHttpAuth = prompt_for_httpauth_creds(); |
| 287 | transport_close(&g.url); |
| 288 | return http_exchange(pSend, pReply, useLogin, maxRedirect); |
| 289 | } |
| 290 | } |
| 291 | if( rc!=200 && rc!=301 && rc!=302 ){ |
| 292 | int ii; |
| 293 | for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){} |
| 294 | while( zLine[ii]==' ' ) ii++; |
| 295 | fossil_warning("server says: %s", &zLine[ii]); |
| 296 | goto write_err; |
| @@ -300,11 +300,11 @@ | |
| 300 | }else{ |
| 301 | closeConnection = 0; |
| 302 | } |
| 303 | }else if( g.url.isSsh && fossil_strnicmp(zLine, "status:", 7)==0 ){ |
| 304 | if( sscanf(zLine, "Status: %d", &rc)!=1 ) goto write_err; |
| 305 | if( rc!=200 && rc!=301 && rc!=302 ){ |
| 306 | int ii; |
| 307 | for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){} |
| 308 | while( zLine[ii]==' ' ) ii++; |
| 309 | fossil_warning("server says: %s", &zLine[ii]); |
| 310 | goto write_err; |
| @@ -320,11 +320,11 @@ | |
| 320 | if( c=='c' || c=='C' ){ |
| 321 | closeConnection = 1; |
| 322 | }else if( c=='k' || c=='K' ){ |
| 323 | closeConnection = 0; |
| 324 | } |
| 325 | }else if( ( rc==301 || rc==302 ) && |
| 326 | fossil_strnicmp(zLine, "location:", 9)==0 ){ |
| 327 | int i, j; |
| 328 | |
| 329 | if ( --maxRedirect == 0){ |
| 330 | fossil_warning("redirect limit exceeded"); |
| @@ -345,11 +345,11 @@ | |
| 345 | transport_close(&g.url); |
| 346 | transport_global_shutdown(&g.url); |
| 347 | fSeenHttpAuth = 0; |
| 348 | if( g.zHttpAuth ) free(g.zHttpAuth); |
| 349 | g.zHttpAuth = get_httpauth(); |
| 350 | url_remember(); |
| 351 | return http_exchange(pSend, pReply, useLogin, maxRedirect); |
| 352 | }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){ |
| 353 | if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){ |
| 354 | isCompressed = 0; |
| 355 | }else if( fossil_strnicmp(&zLine[14], |
| 356 |
| --- src/http.c | |
| +++ src/http.c | |
| @@ -286,11 +286,11 @@ | |
| 286 | g.zHttpAuth = prompt_for_httpauth_creds(); |
| 287 | transport_close(&g.url); |
| 288 | return http_exchange(pSend, pReply, useLogin, maxRedirect); |
| 289 | } |
| 290 | } |
| 291 | if( rc!=200 && rc!=301 && rc!=302 && rc!=307 && rc!=308 ){ |
| 292 | int ii; |
| 293 | for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){} |
| 294 | while( zLine[ii]==' ' ) ii++; |
| 295 | fossil_warning("server says: %s", &zLine[ii]); |
| 296 | goto write_err; |
| @@ -300,11 +300,11 @@ | |
| 300 | }else{ |
| 301 | closeConnection = 0; |
| 302 | } |
| 303 | }else if( g.url.isSsh && fossil_strnicmp(zLine, "status:", 7)==0 ){ |
| 304 | if( sscanf(zLine, "Status: %d", &rc)!=1 ) goto write_err; |
| 305 | if( rc!=200 && rc!=301 && rc!=302 && rc!=307 && rc!=308 ){ |
| 306 | int ii; |
| 307 | for(ii=7; zLine[ii] && zLine[ii]!=' '; ii++){} |
| 308 | while( zLine[ii]==' ' ) ii++; |
| 309 | fossil_warning("server says: %s", &zLine[ii]); |
| 310 | goto write_err; |
| @@ -320,11 +320,11 @@ | |
| 320 | if( c=='c' || c=='C' ){ |
| 321 | closeConnection = 1; |
| 322 | }else if( c=='k' || c=='K' ){ |
| 323 | closeConnection = 0; |
| 324 | } |
| 325 | }else if( ( rc==301 || rc==302 || rc==307 || rc==308 ) && |
| 326 | fossil_strnicmp(zLine, "location:", 9)==0 ){ |
| 327 | int i, j; |
| 328 | |
| 329 | if ( --maxRedirect == 0){ |
| 330 | fossil_warning("redirect limit exceeded"); |
| @@ -345,11 +345,11 @@ | |
| 345 | transport_close(&g.url); |
| 346 | transport_global_shutdown(&g.url); |
| 347 | fSeenHttpAuth = 0; |
| 348 | if( g.zHttpAuth ) free(g.zHttpAuth); |
| 349 | g.zHttpAuth = get_httpauth(); |
| 350 | if( rc==301 || rc==308 ) url_remember(); |
| 351 | return http_exchange(pSend, pReply, useLogin, maxRedirect); |
| 352 | }else if( fossil_strnicmp(zLine, "content-type: ", 14)==0 ){ |
| 353 | if( fossil_strnicmp(&zLine[14], "application/x-fossil-debug", -1)==0 ){ |
| 354 | isCompressed = 0; |
| 355 | }else if( fossil_strnicmp(&zLine[14], |
| 356 |