File: processing_spec.rb

package info (click to toggle)
thin 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,356 kB
  • sloc: javascript: 6,108; ruby: 5,126; ansic: 1,738; sh: 21; makefile: 8
file content (63 lines) | stat: -rw-r--r-- 2,107 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'spec_helper'

describe Request, 'processing' do
  it 'should parse in chunks' do
    request = Request.new
    expect(request.parse("POST / HTTP/1.1\r\n")).to be_falsey
    expect(request.parse("Host: localhost\r\n")).to be_falsey
    expect(request.parse("Content-Length: 9\r\n")).to be_falsey
    expect(request.parse("\r\nvery ")).to be_falsey
    expect(request.parse("cool")).to be_truthy

    expect(request.env['CONTENT_LENGTH']).to eq('9')
    expect(request.body.read).to eq('very cool')
    expect(request).to validate_with_lint
  end

  it "should move body to tempfile when too big" do
    len = Request::MAX_BODY + 2
    request = Request.new
    request.parse("POST /postit HTTP/1.1\r\nContent-Length: #{len}\r\n\r\n#{'X' * (len/2)}")
    request.parse('X' * (len/2))

    expect(request.body.size).to eq(len)
    expect(request).to be_finished
    expect(request.body.class).to eq(Tempfile)
  end

  it "should delete body tempfile when closing" do
    body = 'X' * (Request::MAX_BODY + 1)

    request = Request.new
    request.parse("POST /postit HTTP/1.1\r\n")
    request.parse("Content-Length: #{body.size}\r\n\r\n")
    request.parse(body)

    expect(request.body.path).not_to be_nil
    request.close
    expect(request.body.path).to be_nil
  end

  it "should close body tempfile when closing" do
    body = 'X' * (Request::MAX_BODY + 1)

    request = Request.new
    request.parse("POST /postit HTTP/1.1\r\n")
    request.parse("Content-Length: #{body.size}\r\n\r\n")
    request.parse(body)

    expect(request.body.closed?).to be_falsey
    request.close
    expect(request.body.closed?).to be_truthy
  end

  it "should raise error when header is too big" do
    big_headers = "X-Test: X\r\n" * (1024 * (80 + 32))
    expect { R("GET / HTTP/1.1\r\n#{big_headers}\r\n") }.to raise_error(InvalidRequest)
  end

  it "should set body external encoding to ASCII_8BIT" do
    pending("Ruby 1.9 compatible implementations only") unless StringIO.instance_methods.include? :external_encoding
    expect(Request.new.body.external_encoding).to eq(Encoding::ASCII_8BIT)
  end
end