middleman 2.0.0.rc93 → 2.0.0.rc95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/bin/mm-build +9 -2
- data/bin/mm-init +9 -2
- data/bin/mm-server +9 -2
- data/features/directory_index.feature +2 -0
- data/features/sprockets_gems.feature +7 -0
- data/fixtures/indexable-app/source/regular/index.html +1 -0
- data/fixtures/test-app/source/javascripts/jquery_base.js +5 -0
- data/lib/middleman.rb +0 -3
- data/lib/middleman/cli.rb +5 -3
- data/lib/middleman/core_extensions/sprockets.rb +10 -3
- data/lib/middleman/features/directory_indexes.rb +9 -3
- data/lib/middleman/templates/default/source/stylesheets/site.css.scss +0 -4
- data/lib/middleman/version.rb +1 -1
- data/middleman.gemspec +6 -7
- metadata +27 -22
- data/lib/middleman/features/proxy.rb +0 -194
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# middleman
|
2
2
|
|
3
|
-
The Middleman is ever-vigilant against tag-soup, unreadable CSS and repetition. He stands-watch over your Haml, Sass, and CoffeeScript producing only the cleanest and efficient markup.
|
3
|
+
The Middleman is ever-vigilant against tag-soup, unreadable CSS and repetition. He stands-watch over your Haml, Sass, and CoffeeScript producing only the cleanest and most efficient markup.
|
4
4
|
|
5
5
|
## Getting Started
|
6
6
|
|
data/bin/mm-build
CHANGED
@@ -1,2 +1,9 @@
|
|
1
|
-
#!/bin/
|
2
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "rubygems"
|
3
|
+
|
4
|
+
libdir = File.join(File.dirname(File.dirname(__FILE__)), "lib")
|
5
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
6
|
+
|
7
|
+
require 'middleman'
|
8
|
+
args = ARGV.dup.unshift("build")
|
9
|
+
Middleman::CLI.start(args)
|
data/bin/mm-init
CHANGED
@@ -1,2 +1,9 @@
|
|
1
|
-
#!/bin/
|
2
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "rubygems"
|
3
|
+
|
4
|
+
libdir = File.join(File.dirname(File.dirname(__FILE__)), "lib")
|
5
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
6
|
+
|
7
|
+
require 'middleman'
|
8
|
+
args = ARGV.dup.unshift("init")
|
9
|
+
Middleman::CLI.start(args)
|
data/bin/mm-server
CHANGED
@@ -1,2 +1,9 @@
|
|
1
|
-
#!/bin/
|
2
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "rubygems"
|
3
|
+
|
4
|
+
libdir = File.join(File.dirname(File.dirname(__FILE__)), "lib")
|
5
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
6
|
+
|
7
|
+
require 'middleman'
|
8
|
+
args = ARGV.dup.unshift("server")
|
9
|
+
Middleman::CLI.start(args)
|
@@ -6,6 +6,8 @@ Feature: Directory Index
|
|
6
6
|
Then "needs_index/index.html" should exist at "indexable-app" and include "Indexable"
|
7
7
|
Then "a_folder/needs_index/index.html" should exist at "indexable-app" and include "Indexable"
|
8
8
|
Then "leave_me_alone.html" should exist at "indexable-app" and include "Stay away"
|
9
|
+
Then "regular/index.html" should exist at "indexable-app" and include "Regular"
|
10
|
+
Then "regular/index/index.html" should not exist at "indexable-app"
|
9
11
|
Then "needs_index.html" should not exist at "indexable-app"
|
10
12
|
Then "a_folder/needs_index.html" should not exist at "indexable-app"
|
11
13
|
Then "leave_me_alone/index.html" should not exist at "indexable-app"
|
@@ -0,0 +1 @@
|
|
1
|
+
Regular
|
data/lib/middleman.rb
CHANGED
@@ -140,9 +140,6 @@ module Middleman
|
|
140
140
|
|
141
141
|
# Treat project as a blog
|
142
142
|
autoload :Blog, "middleman/features/blog"
|
143
|
-
|
144
|
-
# Proxy web services requests in dev mode only
|
145
|
-
autoload :Proxy, "middleman/features/proxy"
|
146
143
|
|
147
144
|
# guard-livereload
|
148
145
|
autoload :LiveReload, "middleman/features/live_reload"
|
data/lib/middleman/cli.rb
CHANGED
@@ -34,7 +34,7 @@ module Middleman
|
|
34
34
|
method_option "livereload", :default => false, :type => :boolean, :desc => "Whether to enable Livereload or not"
|
35
35
|
method_option "livereload-port", :default => "35729", :desc => "The port Livereload will listen on"
|
36
36
|
def server
|
37
|
-
config_check
|
37
|
+
config_check && v1_check
|
38
38
|
if options["livereload"]
|
39
39
|
livereload_options = {:port => options["livereload-port"]}
|
40
40
|
end
|
@@ -48,7 +48,7 @@ module Middleman
|
|
48
48
|
desc "build", "Builds the static site for deployment"
|
49
49
|
method_option "relative", :type => :boolean, :aliases => "-r", :default => false, :desc => 'Override the config.rb file and force relative urls'
|
50
50
|
def build
|
51
|
-
config_check
|
51
|
+
config_check && v1_check
|
52
52
|
thor_group = Middleman::Builder.new([], options).invoke_all
|
53
53
|
end
|
54
54
|
|
@@ -68,7 +68,9 @@ module Middleman
|
|
68
68
|
$stderr.puts "== Error: Could not find a Middleman project config, perhaps you are in the wrong folder?"
|
69
69
|
exit 1
|
70
70
|
end
|
71
|
-
|
71
|
+
end
|
72
|
+
|
73
|
+
def v1_check
|
72
74
|
if File.exists?("views") || File.exists?("public")
|
73
75
|
$stderr.puts "== Error: The views and public folders are have been combined. Create a new 'source' folder, add the contents of views and public to it and then remove the empty views and public folders."
|
74
76
|
exit 1
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require "sprockets"
|
2
|
-
|
2
|
+
|
3
3
|
module Middleman::CoreExtensions::Sprockets
|
4
4
|
class << self
|
5
|
-
def registered(app)
|
5
|
+
def registered(app)
|
6
6
|
app.set :js_compressor, false
|
7
7
|
|
8
8
|
app.map "/#{app.js_dir}" do
|
@@ -15,7 +15,7 @@ module Middleman::CoreExtensions::Sprockets
|
|
15
15
|
alias :included :registered
|
16
16
|
end
|
17
17
|
|
18
|
-
class MiddlemanEnvironment < Sprockets::Environment
|
18
|
+
class MiddlemanEnvironment < ::Sprockets::Environment
|
19
19
|
def initialize(app)
|
20
20
|
full_path = app.views
|
21
21
|
full_path = File.join(app.root, app.views) unless app.views.include?(app.root)
|
@@ -35,6 +35,13 @@ module Middleman::CoreExtensions::Sprockets
|
|
35
35
|
|
36
36
|
# configure search paths
|
37
37
|
append_path app.js_dir
|
38
|
+
|
39
|
+
# jQuery for Sprockets
|
40
|
+
# begin
|
41
|
+
# require "jquery-rails"
|
42
|
+
# jquery-rails / vendor / assets / javascripts
|
43
|
+
# rescue LoadError
|
44
|
+
# end
|
38
45
|
end
|
39
46
|
end
|
40
47
|
|
@@ -12,6 +12,8 @@ module Middleman::Features::DirectoryIndexes
|
|
12
12
|
|
13
13
|
if app.settings.ignored_directory_indexes.include?(request_path)
|
14
14
|
false
|
15
|
+
elsif request_path =~ /#{new_index_path}$/
|
16
|
+
false
|
15
17
|
else
|
16
18
|
[
|
17
19
|
destination.gsub(/#{index_ext.gsub(".", "\\.")}$/, new_index_path),
|
@@ -21,16 +23,20 @@ module Middleman::Features::DirectoryIndexes
|
|
21
23
|
end
|
22
24
|
|
23
25
|
app.before do
|
24
|
-
indexed_path = request.path_info.gsub(/\/$/, "") +
|
26
|
+
indexed_path = request.path_info.gsub(/\/$/, "") + "/" + app.settings.index_file
|
27
|
+
indexed_exists = resolve_template(indexed_path, :raise_exceptions => false)
|
28
|
+
|
29
|
+
extensioned_path = request.path_info.gsub(/\/$/, "") + File.extname(app.settings.index_file)
|
30
|
+
is_ingored = settings.ignored_directory_indexes.include?(extensioned_path)
|
25
31
|
|
26
|
-
if !
|
32
|
+
if !indexed_exists && !is_ingored
|
27
33
|
parts = request.path_info.split("/")
|
28
34
|
last_part = parts.last
|
29
35
|
last_part_ext = File.extname(last_part)
|
30
36
|
|
31
37
|
if last_part_ext.blank?
|
32
38
|
# This is a folder, redirect to index
|
33
|
-
request.path_info =
|
39
|
+
request.path_info = extensioned_path
|
34
40
|
end
|
35
41
|
end
|
36
42
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
@import "compass";
|
2
|
-
@import "susy";
|
3
2
|
|
4
3
|
$link-color: #0388a6;
|
5
4
|
$link-hover-color: #009ce0;
|
@@ -18,7 +17,6 @@ $gutter-width: 1em;
|
|
18
17
|
$side-gutter-width: $gutter-width;
|
19
18
|
|
20
19
|
@include global-reset;
|
21
|
-
@include establish-baseline;
|
22
20
|
|
23
21
|
body {
|
24
22
|
font-family: $font-family;
|
@@ -31,6 +29,4 @@ a {
|
|
31
29
|
|
32
30
|
#main {
|
33
31
|
padding: 50px;
|
34
|
-
@include container;
|
35
|
-
@include susy-grid-background;
|
36
32
|
}
|
data/lib/middleman/version.rb
CHANGED
data/middleman.gemspec
CHANGED
@@ -11,8 +11,6 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.homepage = "http://middlemanapp.com"
|
12
12
|
s.summary = "A static site generator based on Sinatra. Providing Haml, Sass, Compass, CoffeeScript and including minification, compression and cache busting."
|
13
13
|
|
14
|
-
s.rubyforge_project = "middleman"
|
15
|
-
|
16
14
|
s.files = `git ls-files`.split("\n")
|
17
15
|
s.test_files = `git ls-files -- {fixtures,features}/*`.split("\n")
|
18
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -24,21 +22,22 @@ Gem::Specification.new do |s|
|
|
24
22
|
s.add_runtime_dependency("tilt", ["~> 1.3.1"])
|
25
23
|
s.add_runtime_dependency("rdiscount", ["~> 1.6.8"])
|
26
24
|
s.add_runtime_dependency("sinatra", ["~> 1.2.6"])
|
27
|
-
s.add_runtime_dependency("padrino-core", ["~> 0.10.
|
28
|
-
s.add_runtime_dependency("padrino-helpers", ["~> 0.10.
|
25
|
+
s.add_runtime_dependency("padrino-core", ["~> 0.10.1"])
|
26
|
+
s.add_runtime_dependency("padrino-helpers", ["~> 0.10.1"])
|
29
27
|
s.add_runtime_dependency("rack-test", ["~> 0.6.1"])
|
30
28
|
s.add_runtime_dependency("uglifier", ["~> 1.0.0"])
|
31
29
|
s.add_runtime_dependency("slim", ["~> 0.9.0"])
|
32
30
|
s.add_runtime_dependency("haml", ["~> 3.1.0"])
|
33
|
-
s.add_runtime_dependency("sass", ["~> 3.1.
|
31
|
+
s.add_runtime_dependency("sass", ["~> 3.1.6"])
|
34
32
|
s.add_runtime_dependency("coffee-script", ["~> 2.2.0"])
|
35
33
|
s.add_runtime_dependency("compass", ["~> 0.11.3"])
|
36
34
|
s.add_runtime_dependency("sprockets", ["2.0.0.beta.12"])
|
37
35
|
s.add_runtime_dependency("httparty", ["~> 0.7.0"])
|
38
36
|
s.add_runtime_dependency("guard", ["~> 0.5.1"])
|
39
|
-
s.add_runtime_dependency("guard-livereload", ["~> 0.2.
|
37
|
+
s.add_runtime_dependency("guard-livereload", ["~> 0.2.1"])
|
40
38
|
s.add_development_dependency("coffee-filter", ["~> 0.1.1"])
|
41
|
-
s.add_development_dependency("
|
39
|
+
# s.add_development_dependency("jquery-rails", ["~> 1.0.12"])
|
40
|
+
s.add_development_dependency("cucumber", ["~> 1.0.2"])
|
42
41
|
s.add_development_dependency("rake", ["0.8.7"])
|
43
42
|
s.add_development_dependency("rspec", ["~> 2.6.0"])
|
44
43
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15424235
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
9
|
- 0
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 2.0.0.
|
11
|
+
- 95
|
12
|
+
version: 2.0.0.rc95
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Thomas Reynolds
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-08-
|
20
|
+
date: 2011-08-03 00:00:00 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: rack
|
@@ -123,12 +123,12 @@ dependencies:
|
|
123
123
|
requirements:
|
124
124
|
- - ~>
|
125
125
|
- !ruby/object:Gem::Version
|
126
|
-
hash:
|
126
|
+
hash: 53
|
127
127
|
segments:
|
128
128
|
- 0
|
129
129
|
- 10
|
130
|
-
-
|
131
|
-
version: 0.10.
|
130
|
+
- 1
|
131
|
+
version: 0.10.1
|
132
132
|
type: :runtime
|
133
133
|
version_requirements: *id007
|
134
134
|
- !ruby/object:Gem::Dependency
|
@@ -139,12 +139,12 @@ dependencies:
|
|
139
139
|
requirements:
|
140
140
|
- - ~>
|
141
141
|
- !ruby/object:Gem::Version
|
142
|
-
hash:
|
142
|
+
hash: 53
|
143
143
|
segments:
|
144
144
|
- 0
|
145
145
|
- 10
|
146
|
-
-
|
147
|
-
version: 0.10.
|
146
|
+
- 1
|
147
|
+
version: 0.10.1
|
148
148
|
type: :runtime
|
149
149
|
version_requirements: *id008
|
150
150
|
- !ruby/object:Gem::Dependency
|
@@ -219,12 +219,12 @@ dependencies:
|
|
219
219
|
requirements:
|
220
220
|
- - ~>
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
hash:
|
222
|
+
hash: 15
|
223
223
|
segments:
|
224
224
|
- 3
|
225
225
|
- 1
|
226
|
-
-
|
227
|
-
version: 3.1.
|
226
|
+
- 6
|
227
|
+
version: 3.1.6
|
228
228
|
type: :runtime
|
229
229
|
version_requirements: *id013
|
230
230
|
- !ruby/object:Gem::Dependency
|
@@ -317,12 +317,12 @@ dependencies:
|
|
317
317
|
requirements:
|
318
318
|
- - ~>
|
319
319
|
- !ruby/object:Gem::Version
|
320
|
-
hash:
|
320
|
+
hash: 21
|
321
321
|
segments:
|
322
322
|
- 0
|
323
323
|
- 2
|
324
|
-
-
|
325
|
-
version: 0.2.
|
324
|
+
- 1
|
325
|
+
version: 0.2.1
|
326
326
|
type: :runtime
|
327
327
|
version_requirements: *id019
|
328
328
|
- !ruby/object:Gem::Dependency
|
@@ -349,12 +349,12 @@ dependencies:
|
|
349
349
|
requirements:
|
350
350
|
- - ~>
|
351
351
|
- !ruby/object:Gem::Version
|
352
|
-
hash:
|
352
|
+
hash: 19
|
353
353
|
segments:
|
354
|
+
- 1
|
354
355
|
- 0
|
355
|
-
-
|
356
|
-
|
357
|
-
version: 0.10.0
|
356
|
+
- 2
|
357
|
+
version: 1.0.2
|
358
358
|
type: :development
|
359
359
|
version_requirements: *id021
|
360
360
|
- !ruby/object:Gem::Dependency
|
@@ -435,6 +435,7 @@ files:
|
|
435
435
|
- features/sinatra.feature
|
436
436
|
- features/slim.feature
|
437
437
|
- features/sprockets.feature
|
438
|
+
- features/sprockets_gems.feature
|
438
439
|
- features/step_definitions/asset_host_steps.rb
|
439
440
|
- features/step_definitions/builder_steps.rb
|
440
441
|
- features/step_definitions/generator_steps.rb
|
@@ -446,6 +447,7 @@ files:
|
|
446
447
|
- fixtures/indexable-app/source/a_folder/needs_index.html
|
447
448
|
- fixtures/indexable-app/source/leave_me_alone.html
|
448
449
|
- fixtures/indexable-app/source/needs_index.html
|
450
|
+
- fixtures/indexable-app/source/regular/index.html
|
449
451
|
- fixtures/test-app/config.rb
|
450
452
|
- fixtures/test-app/data/test.yml
|
451
453
|
- fixtures/test-app/source/_partial.haml
|
@@ -480,6 +482,7 @@ files:
|
|
480
482
|
- fixtures/test-app/source/javascripts/broken-coffee.js.coffee
|
481
483
|
- fixtures/test-app/source/javascripts/coffee_test.js.coffee
|
482
484
|
- fixtures/test-app/source/javascripts/jquery.plugin.with.dots.js
|
485
|
+
- fixtures/test-app/source/javascripts/jquery_base.js
|
483
486
|
- fixtures/test-app/source/javascripts/sprockets_base.js
|
484
487
|
- fixtures/test-app/source/javascripts/sprockets_sub.js
|
485
488
|
- fixtures/test-app/source/layout.haml
|
@@ -534,7 +537,6 @@ files:
|
|
534
537
|
- lib/middleman/features/lorem.rb
|
535
538
|
- lib/middleman/features/minify_css.rb
|
536
539
|
- lib/middleman/features/minify_javascript.rb
|
537
|
-
- lib/middleman/features/proxy.rb
|
538
540
|
- lib/middleman/features/relative_assets.rb
|
539
541
|
- lib/middleman/features/tiny_src.rb
|
540
542
|
- lib/middleman/guard.rb
|
@@ -617,7 +619,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
617
619
|
version: 1.3.1
|
618
620
|
requirements: []
|
619
621
|
|
620
|
-
rubyforge_project:
|
622
|
+
rubyforge_project:
|
621
623
|
rubygems_version: 1.8.6
|
622
624
|
signing_key:
|
623
625
|
specification_version: 3
|
@@ -645,6 +647,7 @@ test_files:
|
|
645
647
|
- features/sinatra.feature
|
646
648
|
- features/slim.feature
|
647
649
|
- features/sprockets.feature
|
650
|
+
- features/sprockets_gems.feature
|
648
651
|
- features/step_definitions/asset_host_steps.rb
|
649
652
|
- features/step_definitions/builder_steps.rb
|
650
653
|
- features/step_definitions/generator_steps.rb
|
@@ -656,6 +659,7 @@ test_files:
|
|
656
659
|
- fixtures/indexable-app/source/a_folder/needs_index.html
|
657
660
|
- fixtures/indexable-app/source/leave_me_alone.html
|
658
661
|
- fixtures/indexable-app/source/needs_index.html
|
662
|
+
- fixtures/indexable-app/source/regular/index.html
|
659
663
|
- fixtures/test-app/config.rb
|
660
664
|
- fixtures/test-app/data/test.yml
|
661
665
|
- fixtures/test-app/source/_partial.haml
|
@@ -690,6 +694,7 @@ test_files:
|
|
690
694
|
- fixtures/test-app/source/javascripts/broken-coffee.js.coffee
|
691
695
|
- fixtures/test-app/source/javascripts/coffee_test.js.coffee
|
692
696
|
- fixtures/test-app/source/javascripts/jquery.plugin.with.dots.js
|
697
|
+
- fixtures/test-app/source/javascripts/jquery_base.js
|
693
698
|
- fixtures/test-app/source/javascripts/sprockets_base.js
|
694
699
|
- fixtures/test-app/source/javascripts/sprockets_sub.js
|
695
700
|
- fixtures/test-app/source/layout.haml
|
@@ -1,194 +0,0 @@
|
|
1
|
-
# ===========================================================================
|
2
|
-
# Original Project: Abbot - SproutCore Build Tools
|
3
|
-
# Copyright: ©2009 Apple Inc.
|
4
|
-
# portions copyright @2006-2011 Strobe Inc.
|
5
|
-
# and contributors
|
6
|
-
# ===========================================================================
|
7
|
-
|
8
|
-
begin
|
9
|
-
require 'net/https'
|
10
|
-
Middleman::HTTPS_ENABLED = true
|
11
|
-
rescue LoadError => e
|
12
|
-
require 'net/http'
|
13
|
-
Middleman::HTTPS_ENABLED = false
|
14
|
-
end
|
15
|
-
|
16
|
-
module Middleman::Features::Proxy
|
17
|
-
class << self
|
18
|
-
def registered(app)
|
19
|
-
app.extend ClassMethods
|
20
|
-
app.use Middleman::Features::Proxy::Rack
|
21
|
-
end
|
22
|
-
alias :included :registered
|
23
|
-
end
|
24
|
-
|
25
|
-
class Collection
|
26
|
-
def initialize(app)
|
27
|
-
@app = app
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.proxies
|
31
|
-
@@proxies ||= {}
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.add(path, options={})
|
35
|
-
@@proxies ||= {}
|
36
|
-
@@proxies[path] = options[:to]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
module ClassMethods
|
41
|
-
# Proxies requests to the path
|
42
|
-
#
|
43
|
-
# proxy '/twitter', "http://twitter/web/service"
|
44
|
-
def proxy(path, options={})
|
45
|
-
Middleman::Features::Proxy::Collection.add(path, options)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Rack application proxies requests as needed for the given project.
|
50
|
-
module Rack
|
51
|
-
|
52
|
-
def initialize(app)
|
53
|
-
@app = app
|
54
|
-
end
|
55
|
-
|
56
|
-
def call(env)
|
57
|
-
url = env['PATH_INFO']
|
58
|
-
|
59
|
-
@proxies = Middleman::Features::Proxy::Collection.proxies
|
60
|
-
@proxies.each do |proxy, value|
|
61
|
-
if url.match(/^#{Regexp.escape(proxy.to_s)}/)
|
62
|
-
return handle_proxy(value, proxy.to_s, env)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
return [404, {}, "not found"]
|
67
|
-
end
|
68
|
-
|
69
|
-
def handle_proxy(proxy, proxy_url, env)
|
70
|
-
if proxy[:secure] && !Middleman::HTTPS_ENABLED
|
71
|
-
$stderr.puts "~ WARNING: HTTPS is not supported on your system, using HTTP instead.\n"
|
72
|
-
$stderr.puts" If you are using Ubuntu, you can run `apt-get install libopenssl-ruby`\n"
|
73
|
-
proxy[:secure] = false
|
74
|
-
end
|
75
|
-
|
76
|
-
origin_host = env['SERVER_NAME'] # capture the origin host for cookies
|
77
|
-
http_method = env['REQUEST_METHOD'].to_s.downcase
|
78
|
-
url = env['PATH_INFO']
|
79
|
-
params = env['QUERY_STRING']
|
80
|
-
|
81
|
-
# collect headers...
|
82
|
-
headers = {}
|
83
|
-
env.each do |key, value|
|
84
|
-
next unless key =~ /^HTTP_/
|
85
|
-
key = key.gsub(/^HTTP_/,'').downcase.sub(/^\w/){|l| l.upcase}.gsub(/_(\w)/){|l| "-#{$1.upcase}"} # remove HTTP_, dasherize and titleize
|
86
|
-
if !key.eql? "Version"
|
87
|
-
headers[key] = value
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
# Rack documentation says CONTENT_TYPE and CONTENT_LENGTH aren't prefixed by HTTP_
|
92
|
-
headers['Content-Type'] = env['CONTENT_TYPE'] if env['CONTENT_TYPE']
|
93
|
-
|
94
|
-
length = env['CONTENT_LENGTH']
|
95
|
-
headers['Content-Length'] = length if length
|
96
|
-
|
97
|
-
http_host, http_port = proxy[:to].split(':')
|
98
|
-
http_port = proxy[:secure] ? '443' : '80' if http_port.nil?
|
99
|
-
|
100
|
-
# added 4/23/09 per Charles Jolley, corrects problem
|
101
|
-
# when making requests to virtual hosts
|
102
|
-
headers['Host'] = "#{http_host}:#{http_port}"
|
103
|
-
|
104
|
-
if proxy[:url]
|
105
|
-
url = url.sub(/^#{Regexp.escape proxy_url}/, proxy[:url])
|
106
|
-
end
|
107
|
-
|
108
|
-
http_path = [url]
|
109
|
-
http_path << params if params && params.size>0
|
110
|
-
http_path = http_path.join('?')
|
111
|
-
|
112
|
-
response = nil
|
113
|
-
no_body_method = %w(get copy head move options trace)
|
114
|
-
|
115
|
-
done = false
|
116
|
-
tries = 0
|
117
|
-
until done
|
118
|
-
http = ::Net::HTTP.new(http_host, http_port)
|
119
|
-
|
120
|
-
if proxy[:secure]
|
121
|
-
http.use_ssl = true
|
122
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
123
|
-
end
|
124
|
-
|
125
|
-
http.start do |web|
|
126
|
-
if no_body_method.include?(http_method)
|
127
|
-
response = web.send(http_method, http_path, headers)
|
128
|
-
else
|
129
|
-
http_body = env['rack.input']
|
130
|
-
http_body.rewind # May not be necessary but can't hurt
|
131
|
-
|
132
|
-
req = Net::HTTPGenericRequest.new(http_method.upcase,
|
133
|
-
true, true, http_path, headers)
|
134
|
-
req.body_stream = http_body if length.to_i > 0
|
135
|
-
response = web.request(req)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
status = response.code # http status code
|
140
|
-
protocol = proxy[:secure] ? 'https' : 'http'
|
141
|
-
|
142
|
-
$stderr.puts "~ PROXY: #{http_method.upcase} #{status} #{url} -> #{protocol}://#{http_host}:#{http_port}#{http_path}\n"
|
143
|
-
|
144
|
-
# display and construct specific response headers
|
145
|
-
response_headers = {}
|
146
|
-
ignore_headers = ['transfer-encoding', 'keep-alive', 'connection']
|
147
|
-
response.each do |key, value|
|
148
|
-
next if ignore_headers.include?(key.downcase)
|
149
|
-
# If this is a cookie, strip out the domain. This technically may
|
150
|
-
# break certain scenarios where services try to set cross-domain
|
151
|
-
# cookies, but those services should not be doing that anyway...
|
152
|
-
value.gsub!(/domain=[^\;]+\;? ?/,'') if key.downcase == 'set-cookie'
|
153
|
-
# Location headers should rewrite the hostname if it is included.
|
154
|
-
value.gsub!(/^http:\/\/#{http_host}(:[0-9]+)?\//, "http://#{http_host}/") if key.downcase == 'location'
|
155
|
-
# content-length is returning char count not bytesize
|
156
|
-
if key.downcase == 'content-length'
|
157
|
-
if response.body.respond_to?(:bytesize)
|
158
|
-
value = response.body.bytesize.to_s
|
159
|
-
elsif response.body.respond_to?(:size)
|
160
|
-
value = response.body.size.to_s
|
161
|
-
else
|
162
|
-
value = '0'
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
$stderr.puts << " #{key}: #{value}\n"
|
167
|
-
response_headers[key] = value
|
168
|
-
end
|
169
|
-
|
170
|
-
if [301, 302, 303, 307].include?(status.to_i) && proxy[:redirect] != false
|
171
|
-
$stderr.puts '~ REDIRECTING: '+response_headers['location']+"\n"
|
172
|
-
|
173
|
-
uri = URI.parse(response_headers['location']);
|
174
|
-
http_host = uri.host
|
175
|
-
http_port = uri.port
|
176
|
-
http_path = uri.path
|
177
|
-
http_path += '?'+uri.query if uri.query
|
178
|
-
|
179
|
-
tries += 1
|
180
|
-
if tries > 10
|
181
|
-
raise "Too many redirects!"
|
182
|
-
end
|
183
|
-
else
|
184
|
-
done = true
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
# Thin doesn't like null bodies
|
189
|
-
response_body = response.body || ''
|
190
|
-
|
191
|
-
return [status, ::Rack::Utils::HeaderHash.new(response_headers), [response_body]]
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|