Questions tagged [content-length]

Entity-header field indicates the size of the entity-body.

The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.

374 questions
153
votes
6 answers

Count, size, length...too many choices in Ruby?

I can't seem to find a definitive answer on this and I want to make sure I understand this to the "n'th level" :-) a = { "a" => "Hello", "b" => "World" } a.count # 2 a.size # 2 a.length # 2 a = [ 10, 20 ] a.count # 2 …
cbmeeks
  • 11,248
  • 22
  • 85
  • 136
49
votes
3 answers

Content-Length header versus chunked encoding

I'm trying to weigh the pros and cons of setting the Content-Length HTTP header versus using chunked encoding to return [possibly] large files from my server. One or the other is needed to be compliant with HTTP 1.1 specs using persistent…
Gandalf
  • 9,648
  • 8
  • 53
  • 88
43
votes
1 answer

HTTP POST: content-length header required?

I'm currently trying to optimize http-based data transfer between several applications. Our current approach, downloading first and then creating the post-request, obviously add extra IO/memory load and latencies, which I'd like to circumvent. The…
34
votes
13 answers

How to expand 'select' option width after the user wants to select an option

Maybe this is an easy question, maybe not. I have a select box where I hardcode with width. Say 120px. I…
Berlin Brown
  • 11,504
  • 37
  • 135
  • 203
33
votes
1 answer

Node Express Content-Length

I use node.js and express at a small project. I set response header like blow: res.set({'Content-Type':'text/plain;charset=utf-8', 'Content-Length': Buffer.byteLength(data, 'utf-8')}); I can use console.log print data's length is 317.…
Allen Heavey
  • 530
  • 2
  • 5
  • 16
21
votes
4 answers

How is an HTTP multipart "Content-length" header value calculated?

I've read conflicting and somewhat ambiguous replies to the question "How is a multipart HTTP request content length calculated?". Specifically I wonder: What is the precise content range for which the "Content-length" header is calculated? Are…
Moshe Rubin
  • 1,944
  • 1
  • 17
  • 37
19
votes
1 answer

What is the correct Content-Length to set for a GET request?

When I make a POST request using the following code: string body = "Hello World"; byte[] bytes = Encoding.ASCII.GetBytes(body); WebRequest request = WebRequest.Create("http://internalurl"); request.Method = "POST"; request.ContentLength =…
merlin2011
  • 71,677
  • 44
  • 195
  • 329
17
votes
1 answer

what is relation between content-length and byte ranges in HTTP/1.1?

I am not grasping the idea behind content-length and byte ranges as specified by HTTP 1.1 Is there are connection between the two of some sort? If a client requests in terms of byte ranges, say 0-100 out of 200, will the first response contain the…
user349026
17
votes
3 answers

System.Net.ProtocolViolationException: You must write ContentLength bytes to the request stream before calling [Begin]GetResponse

I am getting the "System.Net.ProtocolViolationException: You must write ContentLength bytes to the request stream before calling [Begin]GetResponse" error when calling to the "BeginGetResponse" method of the web request. This is my code: try { …
user3815821
  • 397
  • 2
  • 3
  • 12
16
votes
2 answers

How to set content-length in Spring MVC REST for JSON?

I have some code: @RequestMapping(value = "/products/get", method = RequestMethod.GET) public @ResponseBody List getProducts(@RequestParam(required = true, value = "category_id") Long categoryId) { // some code here return new…
ruslanys
  • 1,183
  • 2
  • 13
  • 25
15
votes
4 answers

Javascript Get length of list of items in object?

I currently have a Javascript object that looks like this: Object {0: 8, 1: 9, 2: 10} I am trying to get the number of individual items in the object (i.e. 3) but can't figure out how to do so. Since the object isn't an array, I can't just call…
user3802348
  • 2,502
  • 11
  • 36
  • 49
14
votes
3 answers

Java, HttpURLConnection and setting the content length

I'm setting the length of the content in my HttpURLConnection, for a PUT. urlConnection.setRequestProperty("Content-Length", "" + responseJSONArray.toString(2).getBytes("UTF8").length); The actual number of bytes is 74. However, when I query the…
Ken
  • 30,811
  • 34
  • 116
  • 155
13
votes
9 answers

Most efficient way to determine if a string length != 0?

I'm trying to speed up the following: string s; //--> s is never null if (s.Length != 0) { } Problem is, it appears the .Length actually counts the characters in the string, and this is way more work than I need. Anybody have an…
Eric
  • 131
  • 1
  • 1
  • 3
13
votes
4 answers

Intermittent failure to load images - ERR_CONTENT_LENGTH_MISMATCH

The problem My website fails to load random images at random times. Intermittent failure to load image with the following error in console: "GET example.com/image.jpg net::ERR_CONTENT_LENGTH_MISMATCH" Image either doesn't load at all and gives…
user3100907
  • 255
  • 3
  • 13
13
votes
2 answers

Get file size from multipart form upload Content-Length header

So, I'm uploading a file, and then downloading it... but the Content-Length in the upload headers do not match the file size. I'm guessing there is some other data involved with this calculation and transfer, but what exactly? How do I get an…
williamcotton
  • 1,129
  • 2
  • 7
  • 6
1
2 3
24 25