Created
February 12, 2012 23:20
-
-
Save jpoz/1811712 to your computer and use it in GitHub Desktop.
Goliath File Upload Proxy Server
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 'goliath' | |
require 'em-synchrony/em-http' | |
class UploadProxy < Goliath::API | |
def on_headers(env, headers) | |
env.logger.info 'received headers: ' + headers.inspect | |
env['async-headers'] = headers | |
end | |
def on_body(env, data) | |
env.logger.info "received data #{data.size}" | |
(env['async-body'] ||= '') << data | |
end | |
def on_close(env) | |
env.logger.info 'closing connection' | |
end | |
def response(env) | |
gh = EM::HttpRequest.new("http://localhost:8080/upload") | |
.post(:head => env['async-headers'], | |
:body => env['async-body']) | |
gh.callback { | |
logger.info "Received #{gh.response_header.status} from Upstream" | |
env.stream_send gh.response | |
env.stream_close | |
} | |
gh.error { | |
env.stream_close | |
} | |
streaming_response(200, {'X-Stream' => 'Uploaddddd'}) | |
end | |
end |
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 'goliath' | |
require 'em-synchrony/em-http' | |
require './upload_proxy' | |
class HealthCheck < Goliath::API | |
def response(env) | |
[200, {}, ["OK"]] | |
end | |
end | |
class WithRoutes < Goliath::API | |
get "/healthcheck", HealthCheck | |
post "/upload", UploadProxy | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment