Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Getting There on Chunked Encoding...

 and the other md5 GCI task is in here too.
  • Loading branch information...
commit bbf140fc8b786c6f79f83aeda2f0998d4b47c4eb 1 parent 31ca7a2
David Czech kapace authored
20 md5task/main_m.pir
... ... @@ -0,0 +1,20 @@
  1 +.sub main
  2 + .param pmc argv
  3 + load_bytecode "Digest/MD5.pbc"
  4 + .local pmc mba
  5 + .local string filename
  6 +
  7 + set filename, argv[1]
  8 + $S0 = "Creating new MappedByteArray, and opening " . filename
  9 + say $S0
  10 + mba = new 'MappedByteArray'
  11 + mba.'open'(filename)
  12 +
  13 + say 'getting the data from the Mapped Byte Array...'
  14 + $I1 = elements mba
  15 + $S0 = mba.'get_string'(0, $I1, 'binary')
  16 +
  17 + $P1 = _md5sum($S0)
  18 + $S0 = _md5_hex($P1)
  19 + say $S0
  20 + .end
21 md5task/main_nfio.pir
... ... @@ -0,0 +1,21 @@
  1 +.loadlib 'io_ops'
  2 +.sub main
  3 + .param pmc argv
  4 + load_bytecode "Digest/MD5.pbc"
  5 + .local pmc mba
  6 + .local string filename
  7 +
  8 + set filename, argv[1]
  9 + $S0 = "Creating new MappedByteArray, and opening " . filename
  10 + say $S0
  11 + say 'getting the data from the Mapped Byte Array...'
  12 +
  13 + $P0 = new 'FileHandle'
  14 + $P0.'open'(filename, 'r')
  15 + $P0.'encoding'('binary')
  16 + $S0 = $P0.'readall'()
  17 +
  18 + $P1 = _md5sum($S0)
  19 + $S0 = _md5_hex($P1)
  20 + say $S0
  21 + .end
47 runtime/parrot/library/LWP/Protocol.pir
@@ -299,6 +299,12 @@ see http://search.cpan.org/~gaas/libwww-perl/
299 299 .param pmc headers
300 300 .param pmc url
301 301 .param pmc proxy
  302 +
  303 + # FIXME:
  304 + # There should be no Connection header, because in HTTP/1.1 all
  305 + # connections are keep-alive by default.
  306 + headers['Connection'] = "Keep-Alive"
  307 +
302 308 # Extract 'Host' header
303 309 .local string host
304 310 host = url.'authority'()
@@ -412,19 +418,39 @@ see http://search.cpan.org/~gaas/libwww-perl/
412 418 .sub '_parse_response_content' :method
413 419 .param pmc response
414 420 .param string str
  421 + .param int chunked
415 422 $I0 = index str, "\r\n\r\n"
416 423 if $I0 < 0 goto L1
417 424 $I0 += 4
418 425 goto L2
419 426 L1:
420 427 $I0 = index str, "\n\n"
421   - if $I0 < 0 goto L3
  428 + if $I0 < 0 goto L4
422 429 $I0 += 2
423 430 L2:
  431 + if chunked == 0 goto L3
  432 + # Proccess chunks into a single block
  433 + say "Chunking together"
  434 + $S0 = substr str, $I0 # 1000\r\n.data etc
  435 + $I1 = index $S0, "\r\n"
  436 + $S1 = substr $S0, 0, $I1
  437 +
  438 + $P1 = box $S1
  439 + #$S3 = get_number $P1, 16
  440 + say $S3
  441 + $S2 = "Chunk " . $S1
  442 + say $S2
  443 +
  444 + $I2 = $P1.'to_int'(16)
  445 + say $I2
  446 + $I0 += $I2
  447 + if $I2 != 0 goto L2
  448 + L3:
424 449 $S0 = substr str, $I0
425 450 $P0 = box $S0
426 451 setattribute response, 'content', $P0
427   - L3:
  452 + .return ($S0)
  453 + L4:
428 454 .end
429 455
430 456 =item request
@@ -435,6 +461,8 @@ see http://search.cpan.org/~gaas/libwww-perl/
435 461 .param pmc request
436 462 .param pmc proxy
437 463
  464 + .local int chunked
  465 + chunked = 0
438 466 .local string method
439 467 method = request.'method'()
440 468 .local pmc url
@@ -511,6 +539,8 @@ see http://search.cpan.org/~gaas/libwww-perl/
511 539 header_length = self.'_parse_response_headers'(response, buf)
512 540 $I0 = response.'is_success'()
513 541 unless $I0 goto L22
  542 + $S0 = response.'get_header'('Transfer-Encoding')
  543 + if $S0 == 'chunked' goto Lchunked
514 544 $S0 = response.'get_header'('Content-Length')
515 545 if $S0 == '' goto L21
516 546 content_length = $S0
@@ -523,9 +553,20 @@ see http://search.cpan.org/~gaas/libwww-perl/
523 553 if $S0 == '' goto L22
524 554 push buf, $S0
525 555 goto L23
  556 + Lchunked:
  557 + # Chunked encoding, so we keep reading until we see a "0\r\n"
  558 + say "Handling Chunked Encoding..."
  559 + # Chunked=True
  560 + chunked = 1
  561 + $S0 = buf
  562 + $I0 = index $S0, "\r\n0\r\n"
  563 + # If it isn't found, keep recv'ing until we find it.
  564 + if $I0 == -1 goto L21
  565 + # Ok, the data has been all sent (except for the footer-headers).
  566 + goto L22
526 567 L22:
527 568 sock.'close'()
528   - self.'_parse_response_content'(response, buf)
  569 + self.'_parse_response_content'(response, buf, chunked)
529 570 .return (response)
530 571 .end
531 572
1  test_data
... ... @@ -0,0 +1 @@
  1 +blah

0 comments on commit bbf140f

Please sign in to comment.
Something went wrong with that request. Please try again.