Class: HttpResponse
- Inherits:
-
Object
- Object
- HttpResponse
- Defined in:
- lib/action/module/http_pack_helper.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#status ⇒ Object
Returns the value of attribute status.
-
#status_message ⇒ Object
Returns the value of attribute status_message.
Instance Method Summary collapse
- #charset ⇒ Object
-
#initialize(status = 200) ⇒ HttpResponse
constructor
A new instance of HttpResponse.
- #to_http_pack(status_code = nil, status_message = nil, header = nil, body = nil) ⇒ Object
Constructor Details
#initialize(status = 200) ⇒ HttpResponse
Returns a new instance of HttpResponse.
35 36 37 38 39 |
# File 'lib/action/module/http_pack_helper.rb', line 35 def initialize(status=200) @status = status @status_message = nil @header = Table.new end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
33 34 35 |
# File 'lib/action/module/http_pack_helper.rb', line 33 def body @body end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
32 33 34 |
# File 'lib/action/module/http_pack_helper.rb', line 32 def header @header end |
#status ⇒ Object
Returns the value of attribute status.
33 34 35 |
# File 'lib/action/module/http_pack_helper.rb', line 33 def status @status end |
#status_message ⇒ Object
Returns the value of attribute status_message.
33 34 35 |
# File 'lib/action/module/http_pack_helper.rb', line 33 def @status_message end |
Instance Method Details
#charset ⇒ Object
41 42 43 44 45 46 |
# File 'lib/action/module/http_pack_helper.rb', line 41 def charset return nil if @header["Content-Type"]==nil charset_array=@header["Content-Type"].scan(/charset=([^; ]*)/)[0] return nil if charset_array==nil return charset_array[0] end |
#to_http_pack(status_code = nil, status_message = nil, header = nil, body = nil) ⇒ Object
48 49 50 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 78 |
# File 'lib/action/module/http_pack_helper.rb', line 48 def to_http_pack(status_code=nil, =nil, header=nil, body=nil) _status_code_=(status_code==nil) ? @status : status_code =(==nil) ? StatusCodeMapping[_status_code_] : _header_=(header==nil) ? @header : header _body_=(body==nil) ? @body : body # _status_message_ ||= StatusCodeMapping[_status_code_] #encoding body. unless _body_.nil? if charset==nil _body_=_body_.force_encoding("gbk") else encod=charset.downcase if encod=="gbk" or encod=="gb2312" _body_=_body_.force_encoding("gbk") else _body_=_body_.force_encoding("gbk").encode(encod) end end end #to pack. http_pack = "" http_pack << "#{HTTP_PROTO} #{_status_code_} #{}" << CRLF http_header(_header_, _body_).writeTo(http_pack) http_pack << CRLF http_pack << _body_ unless _body_.nil? http_pack end |