summaryrefslogtreecommitdiffstats
path: root/libmpdemux/http.c
diff options
context:
space:
mode:
authorbertrand <bertrand@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-12-14 23:50:57 +0000
committerbertrand <bertrand@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-12-14 23:50:57 +0000
commitea70f366b1d88a32b1c1ae741be4e8fb8a7587b2 (patch)
tree0a64226898252f33abaf1c2ae37655920bcd74da /libmpdemux/http.c
parent24c6f11c8b8d08cb98648b324098f7f8c3f0bd03 (diff)
downloadmpv-ea70f366b1d88a32b1c1ae741be4e8fb8a7587b2.tar.bz2
mpv-ea70f366b1d88a32b1c1ae741be4e8fb8a7587b2.tar.xz
Made the HTTP request escaped the url.
This now allow for example the spaces in the URL. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@3498 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux/http.c')
-rw-r--r--libmpdemux/http.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/libmpdemux/http.c b/libmpdemux/http.c
index 20ade3b099..563db5f160 100644
--- a/libmpdemux/http.c
+++ b/libmpdemux/http.c
@@ -172,47 +172,66 @@ http_response_parse( HTTP_header_t *http_hdr ) {
char *
http_build_request( HTTP_header_t *http_hdr ) {
- char *ptr;
+ char *ptr, *uri=NULL;
int len;
HTTP_field_t *field;
if( http_hdr==NULL ) return NULL;
if( http_hdr->method==NULL ) http_set_method( http_hdr, "GET");
if( http_hdr->uri==NULL ) http_set_uri( http_hdr, "/");
+ else {
+ uri = (char*)malloc(strlen(http_hdr->uri)*2);
+ if( uri==NULL ) {
+ printf("Memory allocation failed\n");
+ return NULL;
+ }
+ url_escape_string( uri, http_hdr->uri );
+ }
- // Compute the request length
- len = strlen(http_hdr->method)+strlen(http_hdr->uri)+12; // Method line
- field = http_hdr->first_field; // Fields
+ //**** Compute the request length
+ // Add the Method line
+ len = strlen(http_hdr->method)+strlen(uri)+12;
+ // Add the fields
+ field = http_hdr->first_field;
while( field!=NULL ) {
len += strlen(field->field_name)+2;
field = field->next;
}
- len += 2; // CRLF
+ // Add the CRLF
+ len += 2;
+ // Add the body
if( http_hdr->body!=NULL ) {
len += http_hdr->body_size;
}
+ // Free the buffer if it was previously used
if( http_hdr->buffer!=NULL ) {
free( http_hdr->buffer );
http_hdr->buffer = NULL;
}
- http_hdr->buffer = (char*)malloc(len);
+ http_hdr->buffer = (char*)malloc(len+1);
if( http_hdr->buffer==NULL ) {
printf("Memory allocation failed\n");
return NULL;
}
http_hdr->buffer_size = len;
+ //*** Building the request
ptr = http_hdr->buffer;
- ptr += sprintf( ptr, "%s %s HTTP/1.%d\r\n", http_hdr->method, http_hdr->uri, http_hdr->http_minor_version );
+ // Add the method line
+ ptr += sprintf( ptr, "%s %s HTTP/1.%d\r\n", http_hdr->method, uri, http_hdr->http_minor_version );
field = http_hdr->first_field;
+ // Add the field
while( field!=NULL ) {
ptr += sprintf( ptr, "%s\r\n", field->field_name );
field = field->next;
}
ptr += sprintf( ptr, "\r\n" );
+ // Add the body
if( http_hdr->body!=NULL ) {
memcpy( ptr, http_hdr->body, http_hdr->body_size );
}
+
+ if( uri ) free( uri );
return http_hdr->buffer;
}