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
|
# encoding: utf-8
require "spec_helper"
require "acceptance/webmock_shared"
require "acceptance/http_rb/http_rb_spec_helper"
describe "HTTP.rb" do
include HttpRbSpecHelper
include_examples "with WebMock", :no_status_message
context "streaming body" do
let(:response) { HTTP.get "http://example.com" }
before { stub_simple_request "example.com", 302, {}, "abc" }
it "works as if it was streamed from socket" do
expect(response.body.readpartial 1).to eq "a"
end
it "fails if body was already streamed" do
response.body.to_s
expect { response.body.readpartial 1 }.to raise_error
end
end
context "without following redirects" do
let(:response) { http_request(:get, "http://example.com") }
let(:headers) { response.headers }
it "stops on first request" do
stub_simple_request("example.com", 302, "Location" => "http://www.example.com")
stub_simple_request("www.example.com")
expect(headers).to include "Host" => "example.com"
end
end
context "following redirects" do
let(:options) { { :follow => true } }
let(:response) { http_request(:get, "http://example.com", options) }
let(:headers) { response.headers }
it "returns response of destination" do
stub_simple_request("example.com", 302, "Location" => "http://www.example.com")
stub_simple_request("www.example.com")
expect(headers).to include "Host" => "www.example.com"
end
end
context "restored request uri on replayed response object" do
it "keeps non-default port" do
stub_request :get, "example.com:1234/foo"
response = HTTP.get "http://example.com:1234/foo"
expect(response.uri.to_s).to eq "http://example.com:1234/foo"
end
it "does not injects default port" do
stub_request :get, "example.com/foo"
response = HTTP.get "http://example.com/foo"
expect(response.uri.to_s).to eq "http://example.com/foo"
end
it "strips out default port even if it was explicitly given" do
stub_request :get, "example.com/foo"
response = HTTP.get "http://example.com:80/foo"
expect(response.uri.to_s).to eq "http://example.com/foo"
end
end
end if begin gem 'HTTP'; true; rescue LoadError; false; end
|