News for hackers. Stuff that matters.
Re:Httpstat.us: API for generating different HTTP codes. by elliottcarlson on Tuesday February 15, 2011 @11:46AM (#2221941)
18 lines of node.js to accomplish something similar - I use something similar as a function in my node.js scripts to be able to send a generic error template based on the code that I pass back to the function.

    var http = require('http');
    http.createServer(function (request, response)
    {
        var statusCode = request.url.substr(1, 3);
        response.writeHead(statusCode, { 'connection' : 'close', 'content-type' : 'text/html' });
        response.write('<html>');
        response.write('<head><title>' + statusCode + ' ' + http.STATUS_CODES[statusCode] + '</title></head>');
        response.write('<body bgcolor="white">');
        response.write('<center><h1>' + statusCode + ' ' + http.STATUS_CODES[statusCode] + '</h1></center>');
        response.write(' '.repeat(512));
        response.write('</body>');
        response.end('</html>');
    }).listen(8124, "0.0.0.0");

    String.prototype.repeat = function(num)
    {
        return new Array(num++).join(this);
    }
Re:Httpstat.us: API for generating different HTTP codes. by jsdalton on Tuesday February 15, 2011 @12:28PM (#2222184)
Here's a little something similar I whipped up using Flask (Python):

    import time
    from flask import Flask, make_response, request
    app = Flask(__name__)

    @app.route('/<int:status_code>')
    def return_status(status_code):
        response = make_response()
        response.status_code = status_code
        response.data = response.status
    
        sleep = request.args.get('sleep', None)
        if sleep is not None:
            time.sleep(int(sleep))
        return response

    if __name__ == '__main__':
        app.run(debug=True)
With a handy little feature, a "sleep" query string param that'll delay the response for the given number of seconds, which I've used to test how a client handles latency etc.

[BTW, looks like you're the Elliot Carlson I used to work with way back when. Hope life is treating you well these days! :)]

Re:Httpstat.us: API for generating different HTTP codes. by elliottcarlson on Tuesday February 15, 2011 @12:53PM (#2222311)
Hah, indeed! Email me some time - x at sublim dot nl
Re:Httpstat.us: API for generating different HTTP codes. by tatham on Monday February 21, 2011 @11:38PM (#2248762)
This will get you 80% of the way there, but some status codes require certain response headers too. We return these too.
Re:Httpstat.us: API for generating different HTTP codes. by johns on Tuesday February 22, 2011 @12:36AM (#2248907)
signatures are discouraged here: http://ycombinator.com/newsguidelines.html