- Timestamp:
- 2011-11-13T01:41:42Z (13 years ago)
- Branches:
- master
- Children:
- 80acb6d
- Parents:
- dff732d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/http_client.c
rdff732d r03a8f8e 2 2 * BitlBee -- An IRC to other IM-networks gateway * 3 3 * * 4 * Copyright 2002-20 05Wilmer van der Gaast and others *4 * Copyright 2002-2011 Wilmer van der Gaast and others * 5 5 \********************************************************************/ 6 6 … … 354 354 url_t *url; 355 355 char *s; 356 const char *new_method; 356 357 357 358 s = strstr( loc, "\r\n" ); … … 369 370 } 370 371 371 /* Okay, this isn't fun! We have to rebuild the request... :-( */ 372 new_request = g_malloc( req->request_length + strlen( url->file ) ); 373 374 /* So, now I just allocated enough memory, so I'm 375 going to use strcat(), whether you like it or not. :-) */ 376 377 *s = 0; 378 sprintf( new_request, "%s %s HTTP/1.0\r\nHost: %s", 379 req->status_code == 303 || req->request[0] == 'G' ? "GET" : "POST", url->file, url->host ); 380 *s = ' '; 381 372 /* Find all headers and, if necessary, the POST request contents. 373 Skip the old Host: header though. This crappy code here means 374 anything using this http_client MUST put the Host: header at 375 the top. */ 382 376 if( !( ( s = strstr( req->request, "\r\nHost: " ) ) && 383 377 ( s = strstr( s + strlen( "\r\nHost: " ), "\r\n" ) ) ) ) 384 378 { 385 379 req->status_string = g_strdup( "Error while rebuilding request string" ); 386 g_free( new_request );387 380 g_free( url ); 388 381 goto cleanup; 389 382 } 390 383 391 strcat( new_request, s ); 384 /* More or less HTTP/1.0 compliant, from my reading of RFC 2616. 385 Always perform a GET request unless we received a 301. 303 was 386 meant for this but it's HTTP/1.1-only and we're specifically 387 speaking HTTP/1.0. */ 388 new_method = req->status_code != 301 || req->request[0] == 'G' ? "GET" : "POST"; 389 390 /* Okay, this isn't fun! We have to rebuild the request... :-( */ 391 new_request = g_strdup_printf( "%s %s HTTP/1.0\r\nHost: %s%s", 392 new_method, url->file, url->host, s ); 393 392 394 new_host = g_strdup( url->host ); 393 395 new_port = url->port; 394 396 new_proto = url->proto; 397 398 /* If we went from POST to GET, truncate the request content. */ 399 if( new_request[0] != req->request[0] && new_request[0] == 'G' && 400 ( s = strstr( new_request, "\r\n\r\n" ) ) ) 401 s[4] = '\0'; 395 402 396 403 g_free( url );
Note: See TracChangeset
for help on using the changeset viewer.