diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2015-12-18 11:02:33 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2015-12-18 11:02:33 +0900 |
commit | dcff9005d8c3a99b1d820f7f5891bc500b5e9bc6 (patch) | |
tree | 6b85d1304ab05bb25832c1e76f3eae8c31563f0f | |
parent | 11175ba2dccac382ad1721cc09cf36b9d799a98e (diff) | |
download | plum-dcff9005d8c3a99b1d820f7f5891bc500b5e9bc6.tar.gz |
refactor
-rw-r--r-- | lib/plum/rack/session.rb | 58 |
1 files changed, 32 insertions, 26 deletions
diff --git a/lib/plum/rack/session.rb b/lib/plum/rack/session.rb index 84f4869..24830d3 100644 --- a/lib/plum/rack/session.rb +++ b/lib/plum/rack/session.rb @@ -91,47 +91,53 @@ module Plum end def extract_push(reqheaders, extheaders) - if @config[:server_push] && @plum.push_enabled? && pushs = extheaders["plum.serverpush"] - authority = reqheaders.find { |k, v| k == ":authority" }[1] - scheme = reqheaders.find { |k, v| k == ":scheme" }[1] - - pushs.split(";").map { |push| - method, path = push.split(" ", 2) - { - ":authority" => authority, - ":method" => method.upcase, - ":scheme" => scheme, - ":path" => path - } + pushs = extheaders["plum.serverpush"] + return nil unless pushs + + authority = reqheaders.find { |k, v| k == ":authority" }[1] + scheme = reqheaders.find { |k, v| k == ":scheme" }[1] + + pushs.split(";").map { |push| + method, path = push.split(" ", 2) + { + ":authority" => authority, + ":method" => method.upcase, + ":scheme" => scheme, + ":path" => path } - else - [] - end + } end def handle_request(stream, headers, data) env = new_env(headers, data) r_status, r_rawheaders, r_body = @app.call(env) r_headers, r_extheaders = extract_headers(r_status, r_rawheaders) + if @config[:server_push] && @plum.push_enabled? + push_preqs = extract_push(headers, r_extheaders) + end no_body = r_body.respond_to?(:empty?) && r_body.empty? stream.send_headers(r_headers, end_stream: no_body) - push_sts = extract_push(headers, r_extheaders).map { |preq| - [stream.promise(preq), preq] - } + if push_preqs + push_preqs.map! { |preq| + [stream.promise(preq), preq] + } + end send_body(stream, r_body) unless no_body - push_sts.each { |st, preq| - penv = new_env(preq, "".b) - p_status, p_h, p_body = @app.call(penv) - p_headers, _ = extract_headers(p_status, p_h) - pno_body = p_body.respond_to?(:empty?) && p_body.empty? - st.send_headers(p_headers, end_stream: pno_body) - send_body(st, p_body) unless pno_body - } + if push_preqs + push_preqs.each { |st, preq| + penv = new_env(preq, "".b) + p_status, p_h, p_body = @app.call(penv) + p_headers, _ = extract_headers(p_status, p_h) + pno_body = p_body.respond_to?(:empty?) && p_body.empty? + st.send_headers(p_headers, end_stream: pno_body) + send_body(st, p_body) unless pno_body + } + end @request_thread.delete(stream) end |