WaterSweet / mochiweb

Automatically exported from code.google.com/p/mochiweb
Other
0 stars 0 forks source link

range_parts function failed when call ok("...", chunked). #54

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. call: ok({"text/plain", chunked}
2. error raised as followed.
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
trunk version.

Please provide any additional information below.
may match valid data type before iolist_to_binary(Body0)

=CRASH REPORT==== 29-Dec-2009::16:34:47 ===
  crasher:
    initial call: mochiweb_socket_server:acceptor_loop/1
    pid: <0.82.0>
    registered_name: []
    exception error: bad argument
      in function  iolist_to_binary/1
         called as iolist_to_binary(chunked)
      in call from mochiweb_request:range_parts/3
      in call from mochiweb_request:ok/2
      in call from ice_web:loop/2
      in call from mochiweb_http:headers/5
    ancestors: [ice_web,ice_sup,<0.53.0>]
    messages: []
    links: [<0.55.0>,#Port<0.1064>]
    dictionary: [{mochiweb_request_path,"/timer"}]
    trap_exit: false
    status: running
    heap_size: 1597
    stack_size: 24
    reductions: 955
  neighbours:

Original issue reported on code.google.com by gary.x...@gmail.com on 29 Dec 2009 at 8:53

GoogleCodeExporter commented 8 years ago
I can't reproduce this problem, please provide a full example.

Original comment by bob.ippo...@gmail.com on 2 Jan 2010 at 9:28

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Generate test project by: escript scripts/new_mochiweb.erl test
2. In test_web.erl, add new Req Handler /timer.
3. Access http://testserver:8000/timer. Close browser and try again.

Original comment by gary.x...@gmail.com on 3 Jan 2010 at 8:00

Attachments:

GoogleCodeExporter commented 8 years ago
(server)
$ ./scripts/new_mochiweb.erl  ice
$ cp ~/Downloads/ice_web.erl ice/src/ice_web.erl 
$ cd ice/
$ ./start-dev.sh

(curl client)
$ curl http://127.0.0.1:8000/timer
The time is: {{2010,1,3},{0,6,33}}
The time is: {{2010,1,3},{0,6,34}}
The time is: {{2010,1,3},{0,6,35}}
The time is: {{2010,1,3},{0,6,36}}
...

Also tested with Safari, Firefox and Chrome. All work as expected, no errors. 
Still can't reproduce, even with 
your code.

Original comment by bob.ippo...@gmail.com on 3 Jan 2010 at 8:09

GoogleCodeExporter commented 8 years ago
Just tested it both in Firefox and Chrome. Running in Firefoxy is fine, but 
failed test 
in Chrome. My chrome version is v4.0.249.43
Test the timer handler by refreshing page.

Original comment by gary.x...@gmail.com on 3 Jan 2010 at 8:32

GoogleCodeExporter commented 8 years ago
Ok. Let me capture the packets by different browsers.

First time access by Chrome:
GET /timer HTTP/1.1

Host: vbox:8000

Connection: keep-alive

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.5 
(KHTML, 
like Gecko) Chrome/4.0.249.43 Safari/532.5

Accept: 
application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png
,*/*;
q=0.5

Accept-Encoding: gzip,deflate

Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6

Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3

HTTP/1.1 200 OK

Transfer-Encoding: chunked

Server: MochiWeb/1.0 (Any of you quaids got a smint?)

Date: Sun, 03 Jan 2010 08:53:23 GMT

Content-Type: text/plain

25

The time is: {{2010,1,3},{16,53,23}}

25

The time is: {{2010,1,3},{16,53,24}}

25

The time is: {{2010,1,3},{16,53,25}}

25

The time is: {{2010,1,3},{16,53,26}}

25

The time is: {{2010,1,3},{16,53,27}}

25

The time is: {{2010,1,3},{16,53,28}}

25

The time is: {{2010,1,3},{16,53,29}}

===================================================
Let me reload the page by click the refresh button:
GET /timer HTTP/1.1

Host: vbox:8000

Connection: keep-alive

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.5 
(KHTML, 
like Gecko) Chrome/4.0.249.43 Safari/532.5

Cache-Control: max-age=0

Accept: 
application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png
,*/*;
q=0.5

Accept-Encoding: gzip,deflate

Accept-Language: en-US,en;q=0.8,zh-CN;q=0.6

Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3

Range: bytes=0-221

==================================================================
Yes, Got it. The new request sent by Chrome has a Range field. Range: 
bytes=0-221. It  
cause the case of:
ok({ContentType, ResponseHeaders, Body}) ->
...
Ranges ->
            {PartList, Size} = range_parts(Body, Ranges),

and calling of range_parts(chunked, Ranges) failed by:
range_parts(Body0, Ranges) ->
    Body = iolist_to_binary(Body0),
========================================================
    exception error: bad argument
      in function  iolist_to_binary/1
         called as iolist_to_binary(chunked)
      in call from mochiweb_request:range_parts/3
      in call from mochiweb_request:ok/2

Original comment by gary.x...@gmail.com on 3 Jan 2010 at 9:03

GoogleCodeExporter commented 8 years ago
r124

Original comment by bob.ippo...@gmail.com on 3 Jan 2010 at 11:06