gopher2000 0.5.4 → 0.5.5
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.
- checksums.yaml +4 -4
- data/README.markdown +1 -1
- data/examples/simple.rb +2 -2
- data/lib/gopher2000/base.rb +56 -21
- data/lib/gopher2000/request.rb +10 -1
- data/lib/gopher2000/version.rb +1 -1
- data/spec/dispatching_spec.rb +21 -0
- data/spec/request_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 599d0bfe771be1795d77d08bd7fa8ef1df0b5c8ef89a6270d344aa9ad206e5ab
|
4
|
+
data.tar.gz: 64ee23ab4b4f63351c9572e19a995c5ca3da96919a79703e47a2830b9ddf6fba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c16b9f80341276ad4f93aacbbf505d01b3aea5264da1e3119d43a10ea0037984b4d423ca51ff9f174a9af805daf8e079a71686296b9baee12607c0767706c59
|
7
|
+
data.tar.gz: 20adee6253ced84ab8d4a8c4c7413874b6f034a0b3ae12a86418336fa04acf16ca81ffc19fef41c6c4bdb28c348c7960a1214a4d9563274a80075a81d72fffae
|
data/README.markdown
CHANGED
data/examples/simple.rb
CHANGED
data/lib/gopher2000/base.rb
CHANGED
@@ -169,12 +169,11 @@ module Gopher
|
|
169
169
|
#
|
170
170
|
def lookup(selector)
|
171
171
|
unless routes.nil?
|
172
|
-
|
173
|
-
|
172
|
+
routes.each do |pattern, keys, block|
|
174
173
|
if match = pattern.match(selector)
|
175
174
|
match = match.to_a
|
176
175
|
url = match.shift
|
177
|
-
|
176
|
+
|
178
177
|
params = to_params_hash(keys, match)
|
179
178
|
|
180
179
|
#
|
@@ -208,6 +207,9 @@ module Gopher
|
|
208
207
|
if ! @request.valid?
|
209
208
|
response.body = handle_invalid_request
|
210
209
|
response.code = :error
|
210
|
+
elsif @request.url?
|
211
|
+
response.body = handle_url(@request)
|
212
|
+
response.code = :success
|
211
213
|
else
|
212
214
|
begin
|
213
215
|
debug_log("do lookup for #{@request.selector}")
|
@@ -354,6 +356,15 @@ module Gopher
|
|
354
356
|
menus.include?(:error) ? :error : :'internal/error'
|
355
357
|
end
|
356
358
|
|
359
|
+
|
360
|
+
#
|
361
|
+
# get the id of the template that will be used when rendering an html page
|
362
|
+
# @return name of error template
|
363
|
+
#
|
364
|
+
def url_template
|
365
|
+
menus.include?(:html) ? :html : :'internal/url'
|
366
|
+
end
|
367
|
+
|
357
368
|
#
|
358
369
|
# get the id of the template that will be used when rendering an
|
359
370
|
# invalid request
|
@@ -438,20 +449,18 @@ module Gopher
|
|
438
449
|
|
439
450
|
class << self
|
440
451
|
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
#
|
452
|
+
#
|
453
|
+
# Sanitizes a gopher selector
|
454
|
+
#
|
455
|
+
def sanitize_selector(raw)
|
456
|
+
"/#{raw}".dup.
|
457
|
+
strip. # Strip whitespace
|
458
|
+
sub(/\/$/, ''). # Strip last rslash
|
459
|
+
sub(/^\/*/, '/'). # Strip extra lslashes
|
460
|
+
gsub(/\.+/, '.') # Don't want consecutive dots!
|
461
|
+
end
|
462
|
+
|
463
|
+
#
|
455
464
|
# generate a method which we will use to run routes. this is
|
456
465
|
# based on #generate_method as used by sinatra.
|
457
466
|
# @see https://github.com/sinatra/sinatra/blob/master/lib/sinatra/base.rb
|
@@ -464,7 +473,7 @@ module Gopher
|
|
464
473
|
method
|
465
474
|
end
|
466
475
|
end
|
467
|
-
|
476
|
+
|
468
477
|
#
|
469
478
|
# output a debugging message
|
470
479
|
#
|
@@ -481,15 +490,37 @@ module Gopher
|
|
481
490
|
#
|
482
491
|
def register_defaults
|
483
492
|
menu :'internal/not_found' do
|
484
|
-
|
493
|
+
error "Sorry, #{@request.selector} was not found"
|
485
494
|
end
|
486
495
|
|
487
496
|
menu :'internal/error' do |details|
|
488
|
-
|
497
|
+
error "Sorry, there was an error #{details}"
|
489
498
|
end
|
490
499
|
|
491
500
|
menu :'internal/invalid_request' do
|
492
|
-
|
501
|
+
error "invalid request"
|
502
|
+
end
|
503
|
+
|
504
|
+
menu :'internal/url' do
|
505
|
+
output = <<-EOHTML
|
506
|
+
<html>
|
507
|
+
<head>
|
508
|
+
<meta http-equiv="refresh" content="5;URL=#{@request.url}">
|
509
|
+
</head>
|
510
|
+
<body>
|
511
|
+
<p>
|
512
|
+
You are following a link from gopher to a website. If your browser supports it, you will be
|
513
|
+
automatically taken to the web site shortly. If you do not get
|
514
|
+
sent there, please click <a href="#{@request.url}">here</a>.
|
515
|
+
</p>
|
516
|
+
<p>
|
517
|
+
The URL linked is: <a href="#{@request.url}">#{@request.url}</a>.
|
518
|
+
</p>
|
519
|
+
<p>Have a nice day!</p>
|
520
|
+
</body>
|
521
|
+
</html>
|
522
|
+
EOHTML
|
523
|
+
output
|
493
524
|
end
|
494
525
|
end
|
495
526
|
|
@@ -497,6 +528,10 @@ module Gopher
|
|
497
528
|
render not_found_template
|
498
529
|
end
|
499
530
|
|
531
|
+
def handle_url(request)
|
532
|
+
render url_template, request
|
533
|
+
end
|
534
|
+
|
500
535
|
def handle_error(e)
|
501
536
|
render error_template, e
|
502
537
|
end
|
data/lib/gopher2000/request.rb
CHANGED
@@ -7,12 +7,21 @@ module Gopher
|
|
7
7
|
attr_accessor :selector, :input, :ip_address
|
8
8
|
|
9
9
|
def initialize(raw, ip_addr=nil)
|
10
|
-
@
|
10
|
+
@raw = raw
|
11
|
+
@selector, @input = @raw.chomp.split("\t")
|
11
12
|
|
12
13
|
@selector = Gopher::Application.sanitize_selector(@selector)
|
13
14
|
@ip_address = ip_addr
|
14
15
|
end
|
15
16
|
|
17
|
+
def url?
|
18
|
+
@raw =~ /^URL\:/
|
19
|
+
end
|
20
|
+
|
21
|
+
def url
|
22
|
+
@raw.chomp.split("\t").first.gsub(/^URL\:/, '')
|
23
|
+
end
|
24
|
+
|
16
25
|
# confirm that this is actually a valid gopher request
|
17
26
|
# @return [Boolean] true if the request is valid, false otherwise
|
18
27
|
def valid?
|
data/lib/gopher2000/version.rb
CHANGED
data/spec/dispatching_spec.rb
CHANGED
@@ -51,6 +51,7 @@ describe Gopher::Application do
|
|
51
51
|
|
52
52
|
@response = @server.dispatch(@request)
|
53
53
|
expect(@response.code).to eq(:missing)
|
54
|
+
expect(@response.body).to contain_any_error
|
54
55
|
end
|
55
56
|
|
56
57
|
it "should respond with error if invalid request" do
|
@@ -59,6 +60,7 @@ describe Gopher::Application do
|
|
59
60
|
|
60
61
|
@response = @server.dispatch(@request)
|
61
62
|
expect(@response.code).to eq(:error)
|
63
|
+
expect(@response.body).to contain_any_error
|
62
64
|
end
|
63
65
|
|
64
66
|
it "should respond with error if there's an exception" do
|
@@ -67,6 +69,7 @@ describe Gopher::Application do
|
|
67
69
|
|
68
70
|
@response = @server.dispatch(@request)
|
69
71
|
expect(@response.code).to eq(:error)
|
72
|
+
expect(@response.body).to contain_any_error
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
@@ -127,7 +130,17 @@ describe Gopher::Application do
|
|
127
130
|
end
|
128
131
|
end
|
129
132
|
|
133
|
+
describe 'dispatch for URL requests' do
|
134
|
+
let(:target) { 'URL:http://github.com/muffinista/gopher2000' }
|
135
|
+
let(:request) { Gopher::Request.new(target) }
|
136
|
+
let(:response) { @server.dispatch(request) }
|
130
137
|
|
138
|
+
it "should return web page" do
|
139
|
+
expect(response.body).to include('<meta http-equiv="refresh" content="5;URL=http://github.com/muffinista/gopher2000">')
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
|
131
144
|
describe "globs" do
|
132
145
|
before(:each) do
|
133
146
|
@server.route '/about/*' do
|
@@ -142,3 +155,11 @@ describe Gopher::Application do
|
|
142
155
|
end
|
143
156
|
end
|
144
157
|
end
|
158
|
+
|
159
|
+
RSpec::Matchers.define :contain_any_error do
|
160
|
+
match do |actual|
|
161
|
+
actual.split(/\r?\n/).any? do |line|
|
162
|
+
line.match(/^3.*?\tnull\t\(FALSE\)\t0$/)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
data/spec/request_spec.rb
CHANGED
@@ -32,4 +32,10 @@ describe Gopher::Request do
|
|
32
32
|
request = Gopher::Request.new("x" * 255, "bar")
|
33
33
|
expect(request.valid?).to eq(false)
|
34
34
|
end
|
35
|
+
|
36
|
+
it 'detects urls' do
|
37
|
+
request = Gopher::Request.new("URL:http://github.com/muffinista/gopher2000")
|
38
|
+
expect(request).to be_url
|
39
|
+
expect(request.url).to eql('http://github.com/muffinista/gopher2000')
|
40
|
+
end
|
35
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gopher2000
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Mitchell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|