gpt4 book ai didi

ruby - "Error bad URI"试图让 WEBrick 接受 HTTPS

转载 作者:数据小太阳 更新时间:2023-10-29 08:12:57 26 4
gpt4 key购买 nike

所以我有一个简单的 Sinatra 站点:

# app.rb         
require 'sinatra'

get '/' do
'Hello world!'
end

我可以设置 Rack 通过 HTTP 为它提供服务:

# config.ru              
require './app'
run Sinatra::Application

# vim: ft=ruby

当我浏览到 http://localhost:9292 时它工作正常:

% rackup
[2013-01-22 10:27:52] INFO WEBrick 1.3.1
[2013-01-22 10:27:52] INFO ruby 1.9.2 (2011-02-18) [x86_64-darwin10.7.4]
[2013-01-22 10:27:52] INFO WEBrick::HTTPServer#start: pid=7525 port=9292
127.0.0.1 - - [22/Jan/2013 10:28:05] "GET / HTTP/1.1" 200 12 0.0177
127.0.0.1 - - [22/Jan/2013 10:28:06] "GET /favicon.ico HTTP/1.1" 404 447 0.0007

我已经 generated a self-signed certificate ,经过一些谷歌搜索,我以为我找到了a way of setting up my rack file to use the cert and serve HTTPS :

# config.ru                                                                     
require './app'
require 'webrick'

Rack::Server.start(
:Port => 9292,
:Logger => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG),
:app => Sinatra::Application,
:SSLEnable => true,
:SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
:SSLPrivateKey => OpenSSL::PKey::RSA.new( File.read "server.key" ),
:SSLCertificate => OpenSSL::X509::Certificate.new( File.read "server.crt" ),
:SSLCertName => [["CN", WEBrick::Utils::getservername]]
)

# vim: ft=ruby

但是当我访问 https://localhost:9292 时,我得到了 Error code: ssl_error_rx_record_too_long 并且 webrick 是......不开心:

% rackup
[2013-01-22 10:46:28] DEBUG TCPServer.new(0.0.0.0, 9292)
[2013-01-22 10:46:28] DEBUG TCPServer.new(::, 9292)
[2013-01-22 10:46:28] DEBUG Rack::Handler::WEBrick is mounted on /.
[2013-01-22 10:46:28] INFO WEBrick::HTTPServer#start: pid=7660 port=9292
[2013-01-22 10:46:33] DEBUG accept: 127.0.0.1:62185
[2013-01-22 10:46:33] ERROR bad URI `?w~Rx03I?\x06?\x00\x00H\x00??'.
localhost - - [22/Jan/2013:10:46:33 EST] "\x16\x03\x01\x00?\x01\x00\x00?\x03\x01P??Y?KOƛ\x0Ew/yO;P\x1E\x13 ?w~Rx03I?\x06?\x00\x00H\x00??" 400 316
- -> ?w~Rx03I?\x06?\x00\x00H\x00??
[2013-01-22 10:46:33] DEBUG close: 127.0.0.1:62185

请自行尝试,运行它所需的所有文件(config.ru、app.rb、server.crt、server.key)都在this gist中。 .

所以我显然做错了什么。我该如何解决?

最佳答案

你需要添加

require "webrick/https"

让它工作

关于ruby - "Error bad URI"试图让 WEBrick 接受 HTTPS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14462558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com