Class: Safrano::Batch::PartRequest

Inherits:
Request
  • Object
show all
Defined in:
lib/odata/batch.rb

Overview

Part-Request part of a Batch-Request

Constant Summary

Constants inherited from Request

Request::DATASERVICEVERSION, Request::DATASERVICEVERSION_RGX, Request::DTSV_PARSE_ERROR, Request::HEADER_PARAM, Request::HEADER_VAL_RAW, Request::HEADER_VAL_WITH_PAR, Request::MAX_DTSV_PARSE_ERROR, Request::MAX_LT_MIN_DTSV_ERROR, Request::METHODS_REGEXP, Request::MIN_DTSV_PARSE_ERROR, Request::NOCACHE_HDRS, Request::ON_CGST_ERROR

Instance Attribute Summary

Attributes inherited from Request

#content_id, #content_id_references, #in_changeset, #service, #service_base, #walker

Instance Method Summary collapse

Methods inherited from Request

#accept, #accept?, #batch_call, #create_odata_walker, #db, #dispatch, #dispatch_error, #dispatch_with_walker, #get_maxversion, #get_minversion, #get_version, #headers, #negotiate_service_version, #parse_multipart, #parseable_data?, #preferred_type, #register_content_id_ref, #with_media_data, #with_parsed_data

Methods included from MethodHandlers

#odata_delete, #odata_get, #odata_head, #odata_options, #odata_patch, #odata_post, #odata_put

Constructor Details

#initialize(part_req, full_req) ⇒ PartRequest

Returns a new instance of PartRequest.



36
37
38
39
40
41
42
# File 'lib/odata/batch.rb', line 36

def initialize(part_req, full_req)
  batch_env(part_req, full_req)
  @env['HTTP_HOST'] = full_req.env['HTTP_HOST']
  super(@env, full_req.service_base)
  @full_req = full_req
  @part_req = part_req
end

Instance Method Details

#batch_env(mime_req, full_req) ⇒ Object



92
93
94
95
96
97
98
99
100
101
# File 'lib/odata/batch.rb', line 92

def batch_env(mime_req, full_req)
  @env = ::Rack::MockRequest.env_for(mime_req.uri,
                                     method: mime_req.http_method,
                                     input: mime_req.content)
  # Logging of sub-requests
  @env[Rack::RACK_ERRORS] = full_req.env[Rack::RACK_ERRORS]
  @env.merge! headers_for_env(mime_req.hd)

  @env
end

#beforeObject

redefined for $batch



45
46
47
48
49
# File 'lib/odata/batch.rb', line 45

def before
  headers 'Cache-Control' => 'no-cache'
  @service = @full_req.service
  headers 'DataServiceVersion' => @service.data_service_version
end

#headers_for_env(headers) ⇒ Object

shamelessely copied from Rack::TEST:Session



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/odata/batch.rb', line 80

def headers_for_env(headers)
  converted_headers = {}

  headers.each do |name, value|
    env_key = name.upcase.tr('-', '_')
    env_key = "HTTP_#{env_key}" unless env_key == 'CONTENT_TYPE'
    converted_headers[env_key] = value
  end

  converted_headers
end

#processObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/odata/batch.rb', line 51

def process
  began_at = Rack::Utils.clock_time

  @response = Safrano::Response.new

  if @part_req.level == 2
    @in_changeset = true
    @content_id = @part_req.content_id
    @content_id_references = @part_req.content_id_references
  end

  before

  dispatch

  status, header, body = @response.finish

  # Logging of sub-requests with ODataCommonLogger.
  # A bit hacky but working
  # TODO: test ?
  if (logga = @full_req.env['safrano.logger_mw'])
    logga.batch_log(env, status, header, began_at)
    # TODO: check why/if we need Rack::Utils::HeaderHash.new(header)
    # and Rack::BodyProxy.new(body) ?
  end
  [status, header, body]
end