Method: GitWit::GitController#service

Defined in:
app/controllers/git_wit/git_controller.rb

#serviceObject

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/git_wit/git_controller.rb', line 12

def service
  # Shell out to git-http-backend.
  out, err, status = Open3.capture3 shell_env, GitWit.git_http_backend_path, 
    stdin_data: request.raw_post, binmode: true

  # Bail if the backend failed.
  raise GitError, err unless status.success?

  # Split headers and body from response.
  headers, body = out.split("\r\n\r\n", 2)
  
  # Convert CGI headers to HTTP headers.
  headers = Hash[headers.split("\r\n").map { |l| l.split(/\s*\:\s*/, 2) }]

  # Set status from header if given, otherwise it's a 200.
  self.status = headers.delete("Status").to_i if headers.key? "Status"

  # Set response body if given, otherwise empty string.
  self.response_body = body.presence || ""
end