em-net-http 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ group :development do
5
5
  gem 'rspec', '>= 1.2.9'
6
6
  gem 'weary'
7
7
  gem 'right_aws'
8
+ gem 'tumblr-rb'
8
9
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/em-net-http.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{em-net-http}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Fairbairn"]
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "em-net-http.gemspec",
28
28
  "lib/em-net-http.rb",
29
+ "lib/em-net-http/weary.rb",
29
30
  "lib/test.rb",
30
31
  "lib/test_weary.rb",
31
32
  "spec/em-net-http_spec.rb",
data/lib/em-net-http.rb CHANGED
@@ -64,6 +64,7 @@ module Net
64
64
  def request(req, body = nil, &block)
65
65
  f=Fiber.current
66
66
  uri = Addressable::URI.parse("#{use_ssl? ? 'https://' : 'http://'}#{addr_port}#{req.path}")
67
+ body = body || req.body
67
68
  opts = body.nil? ? {} : {:body => body}
68
69
  if use_ssl?
69
70
  sslopts = opts[:ssl] = {}
@@ -71,6 +72,11 @@ module Net
71
72
  sslopts[:private_key_file] = key if key
72
73
  sslopts[:cert_chain_file] = ca_file if ca_file
73
74
  end
75
+ headers = opts[:head] = {}
76
+ req.each do |k, v|
77
+ headers[k] = v
78
+ end
79
+ headers['content-type'] ||= "application/x-www-form-urlencoded"
74
80
  httpreq = EM::HttpRequest.new(uri).send(req.class::METHOD.downcase.to_sym, opts)
75
81
  httpreq.callback {|res|f.resume(EM::NetHTTPResponse.new(res))}
76
82
  httpreq.errback {|res|f.resume(EM::NetHTTPResponse.new(res))}
@@ -82,3 +88,6 @@ module Net
82
88
  end
83
89
  end
84
90
 
91
+ # Other bits and bobs.
92
+
93
+
@@ -0,0 +1,24 @@
1
+ module Weary
2
+ class Response
3
+ # Weary doesn't like Content-Type headers with extra bits on the end, like '; encoding=utf-8'.
4
+ def content_type ; @content_type.split(';').first ; end
5
+
6
+ def value ; self ; end
7
+ end
8
+
9
+ # Weary runs multi-threaded by default. The thread is spawned in perform!(). Let's not do that.
10
+ class Request
11
+ def perform!(&block)
12
+ @on_complete = block if block_given?
13
+ before_send.call(self) if before_send
14
+ req = http.request(request)
15
+ response = Response.new(req, self)
16
+ if response.redirected? && follows?
17
+ response.follow_redirect
18
+ else
19
+ on_complete.call(response) if on_complete
20
+ response
21
+ end
22
+ end
23
+ end
24
+ end
data/lib/test_weary.rb CHANGED
@@ -1,29 +1,7 @@
1
- $: << '.'
2
- require File.dirname(__FILE__) + '/em-net-http'
1
+ $: << File.dirname(__FILE__)
2
+ require 'em-net-http'
3
3
  require 'weary'
4
-
5
- module Weary
6
- class Response
7
- def content_type ; @content_type.split(';').first ; end
8
-
9
- def value ; self ; end
10
- end
11
-
12
- class Request
13
- def perform!(&block)
14
- @on_complete = block if block_given?
15
- before_send.call(self) if before_send
16
- req = http.request(request)
17
- response = Response.new(req, self)
18
- if response.redirected? && follows?
19
- response.follow_redirect
20
- else
21
- on_complete.call(response) if on_complete
22
- response
23
- end
24
- end
25
- end
26
- end
4
+ require 'em-net-http/weary'
27
5
 
28
6
  EM.run do
29
7
  Fiber.new do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - James Fairbairn
@@ -77,6 +77,7 @@ files:
77
77
  - VERSION
78
78
  - em-net-http.gemspec
79
79
  - lib/em-net-http.rb
80
+ - lib/em-net-http/weary.rb
80
81
  - lib/test.rb
81
82
  - lib/test_weary.rb
82
83
  - spec/em-net-http_spec.rb