diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-03-12 17:38:08 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-03-12 17:38:08 +0000 |
commit | 826bc72c12cde117c52bfc4b2acb59254a24eff9 (patch) | |
tree | ce1a0fd9387a606c955e1cf29b0f8774baf7c3cf /lib | |
parent | a3b626bf2544a1ad98651a2a2c5cdd13dc934e12 (diff) | |
parent | 380a67ad4c635ca6fbfc4e8845f97788873f4e36 (diff) | |
download | gitlab-ce-826bc72c12cde117c52bfc4b2acb59254a24eff9.tar.gz |
Merge branch 'support-go-subpackages' into 'master'
Support Golang subpackage fetching
Closes #13805
See merge request !3191
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/middleware/go.rb | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/gitlab/middleware/go.rb b/lib/gitlab/middleware/go.rb new file mode 100644 index 00000000000..50b0dd32380 --- /dev/null +++ b/lib/gitlab/middleware/go.rb @@ -0,0 +1,50 @@ +# A dumb middleware that returns a Go HTML document if the go-get=1 query string +# is used irrespective if the namespace/project exists +module Gitlab + module Middleware + class Go + def initialize(app) + @app = app + end + + def call(env) + request = Rack::Request.new(env) + + if go_request?(request) + render_go_doc(request) + else + @app.call(env) + end + end + + private + + def render_go_doc(request) + body = go_body(request) + response = Rack::Response.new(body, 200, { 'Content-Type' => 'text/html' }) + response.finish + end + + def go_request?(request) + request["go-get"].to_i == 1 && request.env["PATH_INFO"].present? + end + + def go_body(request) + base_url = Gitlab.config.gitlab.url + # Go subpackages may be in the form of namespace/project/path1/path2/../pathN + # We can just ignore the paths and leave the namespace/project + path_info = request.env["PATH_INFO"] + path_info.sub!(/^\//, '') + project_path = path_info.split('/').first(2).join('/') + request_url = URI.join(base_url, project_path) + domain_path = strip_url(request_url.to_s) + + "<!DOCTYPE html><html><head><meta content='#{domain_path} git #{request_url}.git' name='go-import'></head></html>\n"; + end + + def strip_url(url) + url.gsub(/\Ahttps?:\/\//, '') + end + end + end +end |