File: tc_curl_easy_request_target.rb

package info (click to toggle)
ruby-curb 1.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 860 kB
  • sloc: ansic: 5,798; ruby: 4,466; makefile: 4
file content (41 lines) | stat: -rw-r--r-- 1,120 bytes parent folder | download
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
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))

class TestCurbCurlEasyRequestTarget < Test::Unit::TestCase
  include TestServerMethods

  def setup
    server_setup
  end

  def test_request_target_absolute_form
    unless Curl.const_defined?(:CURLOPT_REQUEST_TARGET)
      omit('libcurl lacks CURLOPT_REQUEST_TARGET support')
    end

    tmp = Tempfile.new('curb_test_request_target')
    path = tmp.path
    fd = IO.sysopen(path, 'w')
    io = IO.new(fd, 'w')
    io.sync = true

    easy = Curl::Easy.new(TestServlet.url)
    easy.verbose = true
    easy.setopt(Curl::CURLOPT_STDERR, io)

    # Force absolute-form request target, different from the URL host
    easy.request_target = "http://localhost:#{TestServlet.port}#{TestServlet.path}"
    easy.headers = { 'Host' => "example.com" }

    easy.perform

    io.flush
    io.close
    output = File.read(path)

    assert_match(/GET\s+http:\/\/localhost:#{TestServlet.port}#{Regexp.escape(TestServlet.path)}\s+HTTP\/1\.1/, output)
    assert_match(/Host:\s+example\.com/, output)
  ensure
    tmp.close! if defined?(tmp) && tmp
  end
end