Class: Net::HTTP::SPDY

Inherits:
Net::HTTP
  • Object
show all
Defined in:
lib/net/http/spdy.rb,
lib/net/http/spdy/stream_session.rb,
lib/net/http/spdy/version.rb

Overview

A SPDY HTTP Client with Net::HTTP

Net::HTTP::SPDY has created with extending Net::HTTP. See Net::HTTP, if you want to know major usages.

Different points from Net::HTTP to Net::HTTP::SPDY are here.

A TCP socket per multi-streams

A TCP Socket conneted with Net::HTTP::SPDY will not close usually until you call Net::HTTP#finish. And, you can use multi-thread to send HTTP requests continuously.

Example:

require 'net/http/spdy'

flag_uris = %w(
   images_sm/ad_flag.png images_sm/ae_flag.png
   images_sm/af_flag.png images_sm/ag_flag.png
   images_sm/ai_flag.png images_sm/am_flag.png
   images_sm/ao_flag.png images_sm/ar_flag.png
   images_sm/as_flag.png images_sm/at_flag.png).map do |path|
  URI('https://www.modspdy.com/world-flags/' + path)
end
fetch_threads = []
uri = URI('https://www.modspdy.com/world-flags/')
Net::HTTP::SPDY.start(uri.host, uri.port, use_ssl: true) do |http|
  flag_uris.each do |uri|
    req = Net::HTTP::Get.new(uri)
    fetch_threads << Thread.start do
      http.request(req)
    end
  end
  fetch_threads.each(&:join)
end

Server push

You can check to exist HTTP responses pushed by a server by Net::HTTPResponse#has_associatd_response? and you can take it by Net::HTTPResponse#associated_responses .

Defined Under Namespace

Classes: StreamError, StreamSession

Constant Summary collapse

VERSION =
'0.0.3'

Instance Method Summary collapse

Constructor Details

#initialize(address, port = nil) ⇒ SPDY

Returns a new instance of SPDY.



51
52
53
54
55
56
57
58
59
60
# File 'lib/net/http/spdy.rb', line 51

def initialize(address, port = nil)
  super
  @npn_select_cb = ->(protocols) do
    prot = protocols.detect{|pr| pr == "spdy/2"}
    if prot.nil?
      raise "This server doesn't support SPDYv2"
    end
    prot
  end
end