From 2af69af96f0730e60ea72c1a034fe879f8c209a4 Mon Sep 17 00:00:00 2001 From: p3k Date: Thu, 30 Aug 2007 12:38:33 +0000 Subject: [PATCH] Added support for content length and HTTP error messages --- helma/Http.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/helma/Http.js b/helma/Http.js index 30aea789..46abbe09 100644 --- a/helma/Http.js +++ b/helma/Http.js @@ -9,9 +9,9 @@ * Copyright 1998-2006 Helma Software. All Rights Reserved. * * $RCSfile: Http.js,v $ - * $Author: michi $ - * $Revision: 1.7 $ - * $Date: 2007/07/17 16:12:09 $ + * $Author: hannes $ + * $Revision: 1.8 $ + * $Date: 2007/07/18 12:05:12 $ */ @@ -546,12 +546,25 @@ helma.Http = function() { charset = charset.replace('"', ' ').trim(); result.charset = charset; } - if (result.length != 0 && result.code == 200) { responseHandler(conn, result); if (result.content) { result.length = result.content.length; } + result.length = result.content.length; + } else { + var errorStream = conn.getErrorStream(); + if (errorStream) { + var body = new java.io.ByteArrayOutputStream(); + var input = new java.io.BufferedInputStream(errorStream); + var buf = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024); + var str; + while ((str = input.read(buf)) > -1) { + body.write(buf, 0, str); + } + input.close(); + result.error = body.toString(); + } } conn.disconnect(); return result;