Module: AlittleLess::Util

Included in:
AlittleLess
Defined in:
lib/a_little_less/util.rb

Instance Method Summary collapse

Instance Method Details

#add_default_cors_headersObject



48
49
50
51
52
53
54
# File 'lib/a_little_less/util.rb', line 48

def add_default_cors_headers
    @req.resp.headers.merge!(
        'Access-Control-Allow-Origin'  => '*',
        'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS',
        'Access-Control-Max-Age'       => '1728000'
    )
end

#error_422(body) ⇒ Object



28
29
30
31
# File 'lib/a_little_less/util.rb', line 28

def error_422 body
    status 422
    with body
end

#http_options?Boolean

HTTP CORS

Returns:

  • (Boolean)


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

def http_options?
    @req.http_method == :options
end

#http_origin_allowed?Boolean

Returns:

  • (Boolean)


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

def http_origin_allowed?
    true
end

#not_foundObject



19
20
21
# File 'lib/a_little_less/util.rb', line 19

def not_found
    status 404
end

#paramsObject

Response



5
6
7
# File 'lib/a_little_less/util.rb', line 5

def params
    @req.params
end

#redir_301(url) ⇒ Object



33
34
35
36
# File 'lib/a_little_less/util.rb', line 33

def redir_301 url
    @req.resp.headers['Location'] = url
    @req.resp.status = 301
end

#send_file(file) ⇒ Object



9
10
11
12
# File 'lib/a_little_less/util.rb', line 9

def send_file file
    @req.resp.headers['X-Sendfile'] = file
    nil
end

#set_options_responseObject



56
57
58
59
60
61
62
# File 'lib/a_little_less/util.rb', line 56

def set_options_response
    @req.resp.headers.merge!(
        'Access-Control-Allow-Headers' => 'Accept, Cache-Control, Content-Type, X-Requested-With',
        'Content-Type'                 => 'text/plain'
    )
    @req.resp.body = ''
end

#status(code) ⇒ Object



14
15
16
17
# File 'lib/a_little_less/util.rb', line 14

def status code
    @req.resp.status = code
    nil
end

#with(body) ⇒ Object



23
24
25
26
# File 'lib/a_little_less/util.rb', line 23

def with body
    @req.resp.body = body
    nil
end