Class: YNHttp

Inherits:
Object
  • Object
show all
Defined in:
lib/yn_http.rb

Constant Summary collapse

@@status_hash =
{
	100 => "CONTINUE",
	200 => "OK",
	201 => "CREATED",
	202 => "ACCEPTED",
	204 => "NO CONTENT",
	302 => "MOVED TEMPORARILY",
	400 => "BAD REQUEST",
	401 => "UNAUTHORIZED",
	402 => "PAYMENT REQUIRED",
	403 => "FORBIDDEN",
	404 => "NOT FOUND",
	408 => "REQUEST TIMEOUT",
	409 => "CONFLICT",
	410 => "GONE",
	500 => "INTERNAL SERVER ERROR"
}

Instance Method Summary collapse

Constructor Details

#initialize(_status = 200, _server = "Apache-Coyote/1.1", _pragma = "no-cache", _control = "no-cache", _content_type = "text/json", _charset = "UTF-8", _body = "") ⇒ YNHttp

Returns a new instance of YNHttp.



3
4
5
6
7
8
9
10
11
12
# File 'lib/yn_http.rb', line 3

def initialize(_status=200,_server="Apache-Coyote/1.1",_pragma="no-cache",_control="no-cache",_content_type="text/json",_charset="UTF-8",_body="")
	@status = _status
	@server = _server
	@pragma = _pragma
	@cache_control = _control
	@content_type = _content_type
	@charset = _charset
	@body = _body
	@content_length = _body.length
end

Instance Method Details

#body=(result) ⇒ Object



56
57
58
59
# File 'lib/yn_http.rb', line 56

def body=(result)
	@content_length=result.size
	@body=result
end

#cache_control=(_control) ⇒ Object



44
45
46
# File 'lib/yn_http.rb', line 44

def cache_control=(_control)
	@cache_control=_control
end

#charset=(_charset) ⇒ Object



52
53
54
# File 'lib/yn_http.rb', line 52

def charset=(_charset)
	@charset=_charset
end

#content_type=(_content_type) ⇒ Object



48
49
50
# File 'lib/yn_http.rb', line 48

def content_type=(_content_type)
	@content_type=_content_type
end

#pragma=(_pragma) ⇒ Object



40
41
42
# File 'lib/yn_http.rb', line 40

def pragma=(_pragma)
	@pragma=_pragma
end

#responseObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/yn_http.rb', line 61

def response
	"HTTP/1.1 #{@status} #{@@status_hash[@status]}\r\n" +
	"Server:#{@server}\r\n" + 
	"Pragma:#{@pragma}\r\n" + 
	"Cache-Control:#{@cache_control}\r\n" + 
	"Content-Type:#{@content_type};charset=#{@charset}\r\n" + 
	"Content-Length:#{@content_length}\r\n" + 
	"\r\n" + 
	"#{@body}"
end

#server=(_server) ⇒ Object



36
37
38
# File 'lib/yn_http.rb', line 36

def server=(_server)
	@server=_server
end

#status=(_status) ⇒ Object



32
33
34
# File 'lib/yn_http.rb', line 32

def status=(_status)
	@status=_status
end