| 54 | | if response.class == String |
| 55 | | res.header['Content-Type'] = 'text/html; charset=utf-8' |
| 56 | | page = NKF.nkf('-w', response.dup.untaint) |
| 57 | | elsif response.code == '302' || response.code == '301' |
| 58 | | response_header = response.header |
| 59 | | res.header['Content-Type'] = 'text/html; charset=utf-8' |
| 60 | | renderable = true |
| 61 | | redirect = response.header['location'].to_s.dup.untaint |
| 62 | | page = "<html><head></head><body><p style=\"background-color: #f0f000; color: navy\">[SSB]リダイレクトされました</p>" |
| 63 | | page += "<p style=\"font-size:x-small\">#{redirect}</p><a href=\"#{redirect}\">リダイレクト先へ</a></body></html>" |
| 64 | | |
| 65 | | source = CGI.escapeHTML(page.dup) |
| 66 | | |
| 67 | | #cgi.header('location'=>'./?q='+CGI.escape(response.header['location']).to_s) |
| 68 | | #exit |
| 69 | | else |
| 70 | | response_header = response.header |
| 71 | | renderable = true |
| 72 | | content_type = 'text/html' |
| 73 | | if response.header['content-type'].nil? |
| 74 | | content_type = 'text/plain' |
| 75 | | elsif response.header['content-type'].include?('text/') |
| 76 | | content_type = 'text/html' |
| 77 | | elsif response.header['content-type'].include?('application/xhtml') |
| 78 | | content_type = 'text/html' |
| 79 | | else |
| 80 | | renderable = false |
| 81 | | content_type = response.header['content-type'] |
| 82 | | end |
| 83 | | |
| 84 | | unless renderable |
| 85 | | res.header['Content-Type'] = content_type |
| 86 | | res.body = response.body |
| 87 | | return |
| 88 | | else |
| 89 | | res.header['Content-Type'] = "#{content_type}; charset=utf-8" |
| 90 | | end |
| 91 | | |
| 92 | | page = response.body.dup.untaint |
| 93 | | source = CGI.escapeHTML(NKF::nkf('-w', page)) |
| 94 | | end |
| 95 | | end |
| 96 | | |
| 97 | | [page,source] |
| 98 | | end |
| 99 | | |
| 100 | | def run(req, res) |
| | 57 | ok_response(cgi_response, ssb_response) |
| | 58 | end |
| | 59 | end |
| | 60 | |
| | 61 | def ok_response(cgi_response, ssb_response) |
| | 62 | raw_content_type = ssb_response.header['content-type'] |
| | 63 | case |
| | 64 | when raw_content_type.nil? |
| | 65 | cgi_response.header['Content-Type'] = "text/plain; charset=utf-8" |
| | 66 | when raw_content_type.include?('text/') |
| | 67 | cgi_response.header['Content-Type'] = "text/html; charset=utf-8" |
| | 68 | when raw_content_type.include?('application/xhtml') |
| | 69 | cgi_response.header['Content-Type'] = "text/html; charset=utf-8" |
| | 70 | else |
| | 71 | cgi_response.header['Content-Type'] = raw_content_type |
| | 72 | cgi_response.body = ssb_response.body |
| | 73 | return |
| | 74 | end |
| | 75 | page = ssb_response.body.dup.untaint |
| | 76 | [page, CGI.escapeHTML(NKF::nkf('-w', page))] |
| | 77 | end |
| | 78 | |
| | 79 | def redirect_response(cgi_response, ssb_response) |
| | 80 | cgi_response.header['Content-Type'] = 'text/html; charset=utf-8' |
| | 81 | redirect = ssb_response.header['location'].to_s.dup.untaint |
| | 82 | page = "<html><head></head><body><p style=\"background-color: #f0f000; color: navy\">[SSB]リダイレクトされました</p>" |
| | 83 | page += "<p style=\"font-size:x-small\">#{redirect}</p><a href=\"#{redirect}\">リダイレクト先へ</a></body></html>" |
| | 84 | source = CGI.escapeHTML(page.dup) |
| | 85 | [page, source] |
| | 86 | end |
| | 87 | |
| | 88 | def string_response(cgi_response, ssb_response) |
| | 89 | cgi_response.header['Content-Type'] = 'text/html; charset=utf-8' |
| | 90 | [NKF.nkf('-w', ssb_response.dup.untaint), 'N/A'] |
| | 91 | end |
| | 92 | |
| | 93 | def run(cgi_request, cgi_response) |