Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
A respond_to style Rails block for baked-in web service support in Sinatra
format
parameter, extension, accept header, default content.Allows urls of the form /posts, /posts.rss, and /posts?format=atom to route to the same Sinatra block and format specific respond_to block.
require 'sinatra'
require 'sinatra/respond_to'
Sinatra::Application.register Sinatra::RespondTo
get '/posts' do
@posts = Post.recent
respond_to do |wants|
wants.html { haml :posts } # => views/posts.html.haml, also sets content_type to text/html
wants.rss { haml :posts } # => views/posts.rss.haml, also sets content_type to application/rss+xml
wants.atom { haml :posts } # => views/posts.atom.haml, also sets content_type to appliation/atom+xml
end
end
get '/post/:id' do
@post = Post.find(params[:id])
respond_to do |wants|
wants.html { haml :post } # => views/post.html.haml, also sets content_type to text/html
wants.xhtml { haml :post } # => views/post.xhtml.haml, also sets content_type to application/xhtml+xml
wants.xml { @post.to_xml } # => sets content_type to application/xml
wants.js { erb :post } # => views/post.js.erb, also sets content_type to application/javascript
end
end
get '/comments/:id' do
@comment = Comment.find(params[:id])
respond_to do |wants|
wants.html { haml :comment } # => views/comment.html.haml, also sets content_type to text/html
wants.json { @comment.to_json } # => sets content_type to application/json
wants.js { erb :comment } # => views/comment.js.erb, also sets content_type to application/javascript
end
end
To change the character set of the response, there is a charset
helper. For example
get '/iso-8859-1' do
charset 'iso-8859-1'
"This is now sent using iso-8859-1 character set"
end
get '/respond_to-mixed' do
respond_to do |wants|
wants.html { charset 'iso-8859-1'; "Some html in iso-8859-1" }
wants.xml { builder :utf-8-xml } # => this is returned in the default character set
end
end
There a few options available for configuring the default behavior of respond_to using Sinatra's set
utility.
If you would like to use Sinatra 1.2, use version 0.7.0
.
$ gem install sinatra-respond_to
Due to the way respond_to works, all incoming requests have the extension striped from the request.path_info. This causes routes like the following to fail.
get '/style.css' do
sass :style # => renders views/style.sass
end
They need to be changed to the following.
get '/style' do
sass :style # => renders views/style.css.sass
end
If you want to ensure the route only gets called for css requests try this. This will use sinatra's built in accept header matching.
get '/style', :provides => :css do
sass :style
end
After checking out the source, run:
$ bundle install
$ rake spec
This task will install any missing dependencies, run the tests/specs, and generate the RDoc.
(The MIT License)
Copyright (c) 2009-2013 Chris Hoffman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Unknown package
We found that sinatra-respond_to demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.