-
-
Save losingle/5265820 to your computer and use it in GitHub Desktop.
This file contains 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 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