File: auto_inflate_spec.rb

package info (click to toggle)
ruby-http 4.4.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 704 kB
  • sloc: ruby: 5,388; makefile: 9
file content (85 lines) | stat: -rw-r--r-- 2,440 bytes parent folder | download | duplicates (3)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# frozen_string_literal: true

RSpec.describe HTTP::Features::AutoInflate do
  subject(:feature) { HTTP::Features::AutoInflate.new }

  let(:connection) { double }
  let(:headers)    { {} }

  let(:response) do
    HTTP::Response.new(
      :version    => "1.1",
      :status     => 200,
      :headers    => headers,
      :connection => connection
    )
  end

  describe "#wrap_response" do
    subject(:result) { feature.wrap_response(response) }

    context "when there is no Content-Encoding header" do
      it "returns original request" do
        expect(result).to be response
      end
    end

    context "for identity Content-Encoding header" do
      let(:headers) { {:content_encoding => "identity"} }

      it "returns original request" do
        expect(result).to be response
      end
    end

    context "for unknown Content-Encoding header" do
      let(:headers) { {:content_encoding => "not-supported"} }

      it "returns original request" do
        expect(result).to be response
      end
    end

    context "for deflate Content-Encoding header" do
      let(:headers) { {:content_encoding => "deflate"} }

      it "returns a HTTP::Response wrapping the inflated response body" do
        expect(result.body).to be_instance_of HTTP::Response::Body
      end
    end

    context "for gzip Content-Encoding header" do
      let(:headers) { {:content_encoding => "gzip"} }

      it "returns a HTTP::Response wrapping the inflated response body" do
        expect(result.body).to be_instance_of HTTP::Response::Body
      end
    end

    context "for x-gzip Content-Encoding header" do
      let(:headers) { {:content_encoding => "x-gzip"} }

      it "returns a HTTP::Response wrapping the inflated response body" do
        expect(result.body).to be_instance_of HTTP::Response::Body
      end
    end

    # TODO(ixti): We should refactor API to either make uri non-optional,
    #   or add reference to request into response object (better).
    context "when response has uri" do
      let(:response) do
        HTTP::Response.new(
          :version    => "1.1",
          :status     => 200,
          :headers    => {:content_encoding => "gzip"},
          :connection => connection,
          :uri        => "https://example.com"
        )
      end

      it "preserves uri in wrapped response" do
        expect(result.uri).to eq HTTP::URI.parse("https://example.com")
      end
    end
  end
end