2 Commits
55e87603e5
...
000e53e742
Author | SHA1 | Message | Date |
---|---|---|---|
Yessiest | 000e53e742 |
Fixed import function, fixed documentation warnings issued by YARD
|
7 months ago |
Yessiest | 447f51570a |
Added directory bouncing, status code handlers and pipelining
|
7 months ago |
25 changed files with 223 additions and 41 deletions
-
18examples/dirbounce.ru
-
27examples/errorpages.ru
-
3examples/uploader/files/.bash_logout
-
5examples/uploader/files/.bash_profile
-
10examples/uploader/files/.bashrc
-
BINexamples/uploader/files/lab5.zip
-
27examples/uploader/form.ru
-
31examples/uploader/index.rhtml
-
1examples/uploader/lib
-
1examples/uploader/readme.txt
-
2landline.gemspec
-
4lib/landline/dsl/constructors_probe.rb
-
21lib/landline/dsl/methods_path.rb
-
11lib/landline/dsl/methods_template.rb
-
2lib/landline/node.rb
-
62lib/landline/path.rb
-
2lib/landline/pattern_matching/glob.rb
-
2lib/landline/pattern_matching/rematch.rb
-
6lib/landline/probe/handler.rb
-
1lib/landline/probe/serve_handler.rb
-
11lib/landline/template.rb
-
2lib/landline/template/erb.rb
-
2lib/landline/template/erubi.rb
-
2lib/landline/util/mime.rb
-
11lib/landline/util/multipart.rb
@ -0,0 +1,18 @@ |
|||
# frozen_string_literal: true |
|||
|
|||
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib") |
|||
require 'landline' |
|||
|
|||
app = Landline::Server.new do |
|||
path "/hello" do |
|||
bounce |
|||
get "/world" do |
|||
"Hello world!" |
|||
end |
|||
end |
|||
get "/hello/user" do |
|||
"Hello user!" |
|||
end |
|||
end |
|||
|
|||
run app |
@ -0,0 +1,27 @@ |
|||
# frozen_string_literal: true |
|||
|
|||
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib") |
|||
require 'landline' |
|||
|
|||
app = Landline::Server.new do |
|||
get "/hello" do |
|||
header "content-type", "text/plain" |
|||
"Hello World!" |
|||
end |
|||
get "/error" do |
|||
raise StandardError, "I raised an error! (and that's very sad)" |
|||
end |
|||
handle do |status, backtrace: nil| |
|||
page = ([Landline::Util::HTTP_STATUS[status]] + |
|||
(backtrace || [""])).join("\n") |
|||
[ |
|||
{ |
|||
"content-length": page.bytesize, |
|||
"content-type": "text/plain" |
|||
}, |
|||
page |
|||
] |
|||
end |
|||
end |
|||
|
|||
run app |
@ -0,0 +1,3 @@ |
|||
# |
|||
# ~/.bash_logout |
|||
# |
@ -0,0 +1,5 @@ |
|||
# |
|||
# ~/.bash_profile |
|||
# |
|||
|
|||
[[ -f ~/.bashrc ]] && . ~/.bashrc |
@ -0,0 +1,10 @@ |
|||
# |
|||
# ~/.bashrc |
|||
# |
|||
|
|||
# If not running interactively, don't do anything |
|||
[[ $- != *i* ]] && return |
|||
|
|||
# alias ls='ls --color=auto' |
|||
# alias grep='grep --color=auto' |
|||
# PS1='[\u@\h \W]\$ ' |
@ -0,0 +1,27 @@ |
|||
# frozen_string_literal: true |
|||
|
|||
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib") |
|||
require 'landline' |
|||
|
|||
app = Landline::Server.new do |
|||
root ENV["PWD"] |
|||
index ["index.html"] |
|||
post "/" do |
|||
formdata = form if form? |
|||
files = {} |
|||
if formdata |
|||
formdata["form_files"].each do |file| |
|||
filename = file.filename.split("/").last |
|||
`mv #{file.tempfile.path} $PWD/files/#{filename}` |
|||
files[file.filename] = "<a href=\"files/#{filename}\">#{filename}</a>" |
|||
end |
|||
end |
|||
erubi(file("index.rhtml"), { formdata: files }).run |
|||
end |
|||
serve "/files/*" |
|||
get "/" do |
|||
erubi(file("index.rhtml")).run |
|||
end |
|||
end |
|||
|
|||
run app |
@ -0,0 +1,31 @@ |
|||
<!DOCTYPE> |
|||
<html> |
|||
<head> |
|||
<title>Form upload test</title> |
|||
<style> |
|||
.form { display: flex; flex-direction: column } |
|||
</style> |
|||
</head> |
|||
<body> |
|||
<h1>File uploader</h1> |
|||
<hr/> |
|||
<p> Add files here: <p> |
|||
<form method="post" |
|||
class="form" |
|||
enctype="multipart/form-data"> |
|||
<input id="form_files" type="file" name="form_files[]" multiple> |
|||
<label for="form_files">Attach file</label> |
|||
<input type="submit" value="Send form"> |
|||
</form> |
|||
<% if (defined? formdata) and formdata %> |
|||
<hr> |
|||
<ul> |
|||
<% formdata.each do |key, part| %> |
|||
<li><%= key %>: <%= part %></li> |
|||
<% end %> |
|||
</ul> |
|||
<% end %> |
|||
</body> |
|||
</html> |
|||
|
|||
|
@ -0,0 +1 @@ |
|||
../../lib |
@ -0,0 +1 @@ |
|||
Example of handling forms in Landline |
Write
Preview
Loading…
Cancel
Save
Reference in new issue