Class: FCGI::RecordBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/cgialt/fcgi/core.rb

Instance Method Summary collapse

Constructor Details

#initialize(rec) ⇒ RecordBuffer

Returns a new instance of RecordBuffer.



216
217
218
219
220
221
# File 'lib/cgialt/fcgi/core.rb', line 216

def initialize(rec)
  @begin_request = rec
  @envs = []
  @stdins = []
  @datas = []
end

Instance Method Details

#dataObject



271
272
273
# File 'lib/cgialt/fcgi/core.rb', line 271

def data
  StringIO.new(@datas.inject('') {|buf, rec| buf << rec.flagment })
end

#envObject



261
262
263
264
265
# File 'lib/cgialt/fcgi/core.rb', line 261

def env
  h = {}
  @envs.each {|rec| h.update rec.values }
  h
end

#new_requestObject



257
258
259
# File 'lib/cgialt/fcgi/core.rb', line 257

def new_request
  Request.new(@begin_request.request_id, env(), stdin(), nil, nil, data())
end

#push(rec) ⇒ Object



223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/cgialt/fcgi/core.rb', line 223

def push(rec)
  case rec
  when ParamsRecord
    @envs.push rec
  when StdinDataRecord
    @stdins.push rec
  when DataRecord
    @datas.push rec
  else
    raise "got unknown record: #{rec.class}"
  end
end

#ready?Boolean

Returns:

  • (Boolean)


236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/cgialt/fcgi/core.rb', line 236

def ready?
  case @begin_request.role
  when FCGI_RESPONDER
    completed?(@envs) and
    completed?(@stdins)
  when FCGI_AUTHORIZER
    completed?(@envs)
  when FCGI_FILTER
    completed?(@envs) and
    completed?(@stdins) and
    completed?(@datas)
  else
    raise "unknown role: #{@begin_request.role}"
  end
end

#stdinObject



267
268
269
# File 'lib/cgialt/fcgi/core.rb', line 267

def stdin
  StringIO.new(@stdins.inject('') {|buf, rec| buf << rec.flagment })
end