Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Printing all http headers in Phobos JavaScript server side (See related posts)

Printing all http headers in Phobos JavaScript server side

// prints all http headers
 
function get_headers() {    
    var a = []
    var hEnum = request.headerNames;
    while (hEnum.hasMoreElements()) {
        var n = hEnum.nextElement();
        a.push({name: n, value: request.getHeader(n)});
    }
    return a;
}

response.contentType = 'text/html';
writer = response.writer;

writer.println('<html><head><title>Sample header script</title></head><body>');
var headers = get_headers();
for (var i = 0; i < headers.length; ++i) {
    var header = headers[i];
    writer.print(header.name);
    writer.print(' => ');
    writer.print(header.value);
    writer.println('<br/>');
}
writer.println('</body></html>');
writer.flush();


You need to create an account or log in to post comments to this site.


Click here to browse all 4834 code snippets

Related Posts