Http Protocol Content Length

I am working on a simple downloadable application. When I request the next file, firefox and my application do not receive the content length field. But if I make a request using the wget server, send the content length field. I changed the wgets user agent string to check and it still got the content length field.

Any ideas why this is happening?

wget request

---request begin---
GET /dc-13/video/2005_Defcon_V2-P_Zimmerman-Unveiling_My_Next_Big_Project.mp4 HTTP/1.0
User-Agent: test
Accept: */*
Host: media.defcon.org
Connection: Keep-Alive

---request end---
HTTP request sent, awaiting response... 
---response begin---
HTTP/1.0 200 OK
Server: lighttpd
Date: Sun, 05 Apr 2009 04:40:08 GMT
Last-Modified: Tue, 23 May 2006 22:18:19 GMT
Content-Type: video/mp4
Content-Length: 104223909
Connection: keep-alive

firefox request

GET /dc-13/video/2005_Defcon_V2-P_Zimmerman-Unveiling_My_Next_Big_Project.mp4 HTTP/1.1
Host: media.defcon.org
User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.0.8) Gecko/2009032608 Firefox/3.0.8
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.defcon.org/html/links/defcon-media-archives.html
Pragma: no-cache
Cache-Control: no-cache

HTTP/1.x 200 OK
Server: lighttpd
Date: Sun, 05 Apr 2009 05:20:12 GMT
Last-Modified: Tue, 23 May 2006 22:18:19 GMT
Content-Type: video/mp4
Transfer-Encoding: chunked

Update:

Is there a header that I can send that tells Lighthttpd not to use chunked encoding. My initial problem is that I use urlConnectionjava to capture the file in my application, which automatically sends an HTTP 1.1 request.

I would like to know the file size in order to update my percentage.

+3
3

GET /dc -13/video/2005_Defcon_V2-P_Zimmerman-Unveiling_My_Next_Big_Project.mp4 HTTP/1.1

Firefox HTTP 1.1 GET. Lighthttpd , , .

GET /dc -13/video/2005_Defcon_V2-P_Zimmerman-Unveiling_My_Next_Big_Project.mp4 HTTP/1.0

, Wget HTTP 1.0 GET. Lighthttpd, , HTTP 1.1 (, , ), , .

+13

, - chunked :

Transfer-Encoding: chunked

, . HTTP 1.1, Firefox, wget HTTP 1.0, , .

+4

, HTTP:

  • HEAD , HTTP- . Content-Length: .
  • GET ( GET Content-length).

Objective-C:

NSString *zipURL = @"http://1.bp.blogspot.com/_6-cw84gcURw/TRNb3PDWneI/AAAAAAAAAYM/YFCZP1foTiM/s1600/paragliding1.jpg";

NSURL *url = [NSURL URLWithString:zipURL];

// Configure the HTTP request for HEAD header fetch
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
urlRequest.HTTPMethod = @"HEAD";  // Default is "GET"

// Define response class
__autoreleasing NSHTTPURLResponse *response;

// Send HEAD request to server
NSData *contentsData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];

// Header response field
NSDictionary *headerDeserialized = response.allHeaderFields;

// The contents length
int contents_length = [(NSString*)headerDeserialized[@"Content-Length"] intValue];

//printf("HEAD Response header: %s\n",headerDeserialized.description.UTF8String);
printf("HEAD:\ncontentsData.length: %d\n",contentsData.length);
printf("contents_length = %d\n\n",contents_length);

urlRequest.HTTPMethod = @"GET";

// Send "GET" to download file
contentsData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];

// Header response field
headerDeserialized = response.allHeaderFields;

// The contents length
contents_length = [(NSString*)headerDeserialized[@"Content-Length"] intValue];

printf("GET Response header: %s\n",headerDeserialized.description.UTF8String);
printf("GET:\ncontentsData.length: %d\n",contentsData.length);
printf("contents_length = %d\n",contents_length);

return;

:

HEAD:
contentsData.length: 0
contents_length = 146216

GET:
contentsData.length: 146216
contents_length = 146216

(. URL- Content-Length GET, , )

+1
source

Source: https://habr.com/ru/post/1705917/


All Articles