by pbreit · 15y ago · 0 comments
Why do you find `start_response` unpythonic?
> We could remove start_response and the writer that it implies.
I searched for `wsgi start_response issues` and didn't get anything useful. Care to point out what's the fuss with start_response and why it's unpythonic?
In the Ruby world if I want to use the awesome library Sass all I have to do is:
gem install sass
Because it functions as a Rack plugin it automatically works with any Ruby web framework & Ruby web server combo I choose. No special setup required.-----
# WSGI
def app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
yield 'Hello World\n'
# Rack
app = proc do |env|
[ 200, {'Content-Type' => 'text/plain'}, "a" ]
end
WSGI is the Rack for Python. In fact, WSGI predates Rack, and Rack is WSGI inspired. # Pump
def app(request):
return {
"status": 200,
"headers": {"content_type": "text/plain"},
"body": "Hello World"} public class App extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
response.getWriter().println("Hello world");
}
} # hello.cgi
print "Hello World\n";
I wasn't trying to claim WSGI is the first web server to application server interface. I was just showing Rack and WSGI are similar, and Rack was WSGI inspired.I don't think anyone other than wsgi library implementors code to WSGI. WSGI would be a problem if that's how python web programming was to be done - but that's not the case.