Module: Git::Webby::HttpBackendHelpers

Includes:
GitHelpers
Defined in:
lib/git/webby/http_backend.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from GitHelpers

#content_type_for_git, #git, #repository

Instance Method Details

#header_cache_foreverObject

hdr_cache_forever feature



37
38
39
40
41
42
# File 'lib/git/webby/http_backend.rb', line 37

def header_cache_forever
  now = Time.now
  headers "Date"          => now.to_s,
          "Expires"       => (now + 31536000).to_s,
          "Cache-Control" => "public, max-age=31536000"
end

#header_nocacheObject

hdr_nocache feature



30
31
32
33
34
# File 'lib/git/webby/http_backend.rb', line 30

def header_nocache
  headers "Expires"       => "Fri, 01 Jan 1980 00:00:00 GMT",
          "Pragma"        => "no-cache",
          "Cache-Control" => "no-cache, max-age=0, must-revalidate"
end

#packet_flushObject

pkt_flush feature



25
26
27
# File 'lib/git/webby/http_backend.rb', line 25

def packet_flush
  "0000"
end

#packet_write(line) ⇒ Object

pkt_write feature



20
21
22
# File 'lib/git/webby/http_backend.rb', line 20

def packet_write(line)
  (line.size + 4).to_s(16).rjust(4, "0") + line
end

#read_any_fileObject

select_getanyfile feature



45
46
47
48
49
# File 'lib/git/webby/http_backend.rb', line 45

def read_any_file
  unless settings.get_any_file
    halt 403, "Unsupported service: getanyfile"
  end
end

#read_text_file(*file) ⇒ Object

get_text_file feature



52
53
54
55
56
57
# File 'lib/git/webby/http_backend.rb', line 52

def read_text_file(*file)
  read_any_file
  header_nocache
  content_type "text/plain"
  repository.read_file(*file)
end

#run_advertisement(service) ⇒ Object

run_service feature



83
84
85
86
87
88
89
90
91
# File 'lib/git/webby/http_backend.rb', line 83

def run_advertisement(service)
  header_nocache
  content_type_for_git service, :advertisement
  response.body.clear
  response.body << packet_write("# service=git-#{service}\n")
  response.body << packet_flush
  response.body << repository.run(service, "--stateless-rpc --advertise-refs .")
  response.finish
end

#run_process(service) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/git/webby/http_backend.rb', line 93

def run_process(service)
  content_type_for_git service, :result
  input   = request.body.read
  command = repository.cli(service, "--stateless-rpc #{git.repository}")
  # This source has extracted from Grack written by Scott Chacon.
  IO.popen(command, File::RDWR) do |pipe|
    pipe.write(input)
    while !pipe.eof?
      block = pipe.read(8192) # 8M at a time
      response.write block    # steam it to the client
    end
  end # IO
  response.finish
end

#send_info_packsObject



75
76
77
78
79
80
# File 'lib/git/webby/http_backend.rb', line 75

def send_info_packs
  read_any_file
  header_nocache
  content_type "text/plain; charset=utf-8"
  send_file(repository.info_packs_path)
end

#send_loose_object(prefix, suffix) ⇒ Object

get_loose_object feature



60
61
62
63
64
65
# File 'lib/git/webby/http_backend.rb', line 60

def send_loose_object(prefix, suffix)
  read_any_file
  header_cache_forever
  content_type_for_git :loose, :object
  send_file(repository.loose_object_path(prefix, suffix))
end

#send_pack_idx_file(pack, idx = false) ⇒ Object

get_pack_file and get_idx_file



68
69
70
71
72
73
# File 'lib/git/webby/http_backend.rb', line 68

def send_pack_idx_file(pack, idx = false)
  read_any_file
  header_cache_forever
  content_type_for_git :packed, :objects, (idx ? :toc : nil)
  send_file(repository.pack_idx_path(pack))
end

#serviceObject

select_service feature



12
13
14
15
16
17
# File 'lib/git/webby/http_backend.rb', line 12

def service
  @service = params[:service]
  return false if @service.nil?
  return false if @service[0, 4] != "git-"
  @service = @service.gsub("git-", "")
end

#service_request?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/git/webby/http_backend.rb', line 7

def service_request?
  not params[:service].nil?
end