aboutsummaryrefslogtreecommitdiffstats
path: root/examples/non_tls_server.rb
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2015-11-08 18:18:33 +0900
committerKazuki Yamaguchi <k@rhe.jp>2015-11-08 18:18:33 +0900
commit2b23faa53b254bb20b5f3604f8bd8a42dab4f8d0 (patch)
tree49296e60a8222897b85562078da9c2d5d8765bc8 /examples/non_tls_server.rb
parent939a1c014add6e938b31c19dd9a74332e0691bde (diff)
downloadplum-2b23faa53b254bb20b5f3604f8bd8a42dab4f8d0.tar.gz
stream_utils: remove #respond
Diffstat (limited to 'examples/non_tls_server.rb')
-rw-r--r--examples/non_tls_server.rb18
1 files changed, 11 insertions, 7 deletions
diff --git a/examples/non_tls_server.rb b/examples/non_tls_server.rb
index ae8d692..e7bad41 100644
--- a/examples/non_tls_server.rb
+++ b/examples/non_tls_server.rb
@@ -77,28 +77,31 @@ loop do
<input type=submit>
</form>
EOF
- stream.respond({
+ stream.send_headers({
":status": "200",
"server": "plum",
"content-type": "text/html",
"content-length": body.bytesize
- }, body)
+ }, end_stream: false)
+ stream.send_data(body, end_stream: true)
when ["POST", "/post.page"]
body = "Posted value is: #{CGI.unescape(data).gsub("<", "&lt;").gsub(">", "&gt;")}<br> <a href=/>Back to top page</a>"
- stream.respond({
+ stream.send_headers({
":status": "200",
"server": "plum",
"content-type": "text/html",
"content-length": body.bytesize
- }, body)
+ }, end_stream: false)
+ stream.send_data(body, end_stream: true)
else
body = "Page not found! <a href=/>Back to top page</a>"
- stream.respond({
+ stream.send_headers({
":status": "404",
"server": "plum",
"content-type": "text/html",
"content-length": body.bytesize
- }, body)
+ }, end_stream: false)
+ stream.send_data(body, end_stream: true)
end
end
end
@@ -109,12 +112,13 @@ loop do
plum << sock.readpartial(1024)
end
rescue Plum::LegacyHTTPError
+ data = "Use modern web browser with HTTP/2 support."
resp = "HTTP/1.1 505 HTTP Version Not Supported\r\n"
"Content-Type: text/plain\r\n"
"Content-Length: #{data.bytesize}\r\n"
"Server: plum/#{Plum::VERSION}\r\n"
"\r\n"
- "Use modern web browser with HTTP/2 support."
+ "#{data}"
sock.write(resp)
rescue