Last active
December 7, 2021 11:53
-
-
Save mikehouse/60ebee865faa4034fe0ea8b92a7dcbee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'webrick' | |
require 'webrick/https' | |
require 'openssl' | |
require 'json' | |
# curl https://localhost:port/test (pass '-k' to accept self signed certificate) | |
# openssl req -x509 -newkey rsa:4096 -keyout priv.pem -out cert.pem -days 365 -nodes | |
# cert = OpenSSL::X509::Certificate.new File.read 'cert.pem' | |
# pkey = OpenSSL::PKey::RSA.new File.read 'priv.pem' | |
class MyServlet < WEBrick::HTTPServlet::AbstractServlet | |
def do_POST(request, response) | |
case request.path | |
when '/test' | |
response.content_type = 'application/json' | |
response.body = '{ "test" : "ok" }' | |
response.status = 200 | |
when '/bundle' | |
path = '/Users/mike/Library/Developer/Xcode/DerivedData/MyFramework-egbmqipvgspqlmdibrprjinrpybh/Build/Products/Debug-iphoneos/MyFramework.framework.zip' | |
response.body = File.open(path, 'r') { |io| io.read } | |
response['Content-Disposition'] = 'form-data; name="myzip"; filename="myzip.zip"' | |
response['Content-Transfer-Encoding'] = 'binary' | |
response['Content-Type'] = 'multipart/form-data' | |
response.status = 200 | |
else | |
response.content_type = 'application/json' | |
response.body = '{ "error" : "no such method" }' | |
response.status = 401 | |
end | |
end | |
def do_GET (request, response) | |
case request.path | |
when '/test' | |
response.body = 'Test OK' | |
response.status = 200 | |
else | |
response.body = '{ "error" : "no such method" }' | |
response.status = 401 | |
end | |
end | |
end | |
server = WEBrick::HTTPServer.new(:Port => 1234) | |
# server = WEBrick::HTTPServer.new(:Port => 1234, :SSLEnable => true, :SSLCertificate => cert, :SSLPrivateKey => pkey) | |
server.mount '/', MyServlet | |
trap('INT') { | |
server.shutdown | |
} | |
server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment