Class: LD4L::WorksRDF::ResponseHeader
- Inherits:
-
Object
- Object
- LD4L::WorksRDF::ResponseHeader
- Defined in:
- lib/ld4l/works_rdf/services/negotiation_services/response_header.rb
Class Method Summary collapse
- .get_content_type(header) ⇒ Object
- .get_status(header) ⇒ Object
-
.parse(header) ⇒ Object
“HTTP/1.1 400 Bad Requestrn Date: Sat, 22 Aug 2015 18:49:49 GMTrn Last-Modified: Sat, 22 Aug 2015 18:49:49 GMTrn ETag: "14f56bed06e"rn Cache-Control: no-cache, no-storern Pragma: no-cachern Expires: Sat, 01 Jan 2000 01:00:00 GMTrn Content-Type: application/xml;charset=UTF-8rn Connection: closernrn”.
Class Method Details
.get_content_type(header) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/ld4l/works_rdf/services/negotiation_services/response_header.rb', line 5 def self.get_content_type( header ) parsed_header = self.parse(header) content_type = parsed_header["Content-Type"] content_type = content_type[0] if content_type && content_type.kind_of?(Array) && content_type.size > 0 content_type end |
.get_status(header) ⇒ Object
12 13 14 15 |
# File 'lib/ld4l/works_rdf/services/negotiation_services/response_header.rb', line 12 def self.get_status( header ) parsed_header = self.parse(header) parsed_header["Status"] end |
.parse(header) ⇒ Object
“HTTP/1.1 400 Bad Requestrn Date: Sat, 22 Aug 2015 18:49:49 GMTrn Last-Modified: Sat, 22 Aug 2015 18:49:49 GMTrn ETag: "14f56bed06e"rn Cache-Control: no-cache, no-storern Pragma: no-cachern Expires: Sat, 01 Jan 2000 01:00:00 GMTrn Content-Type: application/xml;charset=UTF-8rn Connection: closernrn”
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ld4l/works_rdf/services/negotiation_services/response_header.rb', line 27 def self.parse(header) parts_hash = {} parts_array = header.split("\r\n") parts_array.each do |p| match_data = p.match("(.*): (.*)") value = nil field = "Status" if p.start_with? "HTTP/1.1" value = p[9..11] if p.start_with? "HTTP/1.1" field = match_data[1] if match_data && match_data.size > 1 value = match_data[2] if match_data && match_data.size > 2 semicolon_split = value.split(";") if value comma_split = value.split(",") if value if semicolon_split && semicolon_split.size > 1 value = semicolon_split.collect { |v| v.strip } elsif comma_split && comma_split.size > 1 value = comma_split.collect { |v| v.strip } end parts_hash[field] = value if value end parts_hash end |