/***************************************************************************
 *   Copyright (C) 2008 by Fabrizio Montesi                                *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 *                                                                         *
 *   For details about the authors of this software, see the AUTHORS file. *
 ***************************************************************************/

package jolie.net.http;

import jolie.net.CommChannel;

/**
 * Utilities for handling HTTP messages.
 * @author Fabrizio Montesi
 */
public class HttpUtils
{
	// Checks if the message requests the channel to be closed or kept open
	static public void recv_checkForChannelClosing( HttpMessage message, CommChannel channel )
	{
		HttpMessage.Version version = message.version();
		if ( version == null || version.equals( HttpMessage.Version.HTTP_1_1 ) ) {
			// The default is to keep the connection open, unless Connection: close is specified
			if ( message.getPropertyOrEmptyString( "connection" ).equalsIgnoreCase( "close" ) ) {
				channel.setToBeClosed( true );
			} else {
				channel.setToBeClosed( false );
			}
		} else if ( version.equals( HttpMessage.Version.HTTP_1_0 ) ) {
			// The default is to close the connection, unless Connection: Keep-Alive is specified
			if ( message.getPropertyOrEmptyString( "connection" ).equalsIgnoreCase( "keep-alive" ) ) {
				channel.setToBeClosed( false );
			} else {
				channel.setToBeClosed( true );
			}
		}
	}
}

@@ -1861,16 +1861,44 @@
 el )%0A%09%7B%0A
+%09%09if ( channel != null ) %7B%0A%09
 %09%09HttpMe
@@ -1940,16 +1940,17 @@
 sion();%0A
+%09
 %09%09if ( v
@@ -2014,24 +2014,25 @@
 P_1_1 ) ) %7B%0A
+%09
 %09%09%09// The de
@@ -2102,32 +2102,33 @@
 is specified%0A%09%09%09
+%09
 if ( message.get
@@ -2193,32 +2193,33 @@
 lose%22 ) ) %7B%0A%09%09%09%09
+%09
 channel.setToBeC
@@ -2228,32 +2228,33 @@
 sed( true );%0A%09%09%09
+%09
 %7D else %7B%0A%09%09%09%09cha
@@ -2238,32 +2238,33 @@
 );%0A%09%09%09%09%7D else %7B%0A
+%09
 %09%09%09%09channel.setT
@@ -2286,18 +2286,20 @@
 e );%0A%09%09%09
+%09
 %7D%0A
+%09
 %09%09%7D else
@@ -2358,16 +2358,17 @@
  ) %7B%0A%09%09%09
+%09
 // The d
@@ -2445,16 +2445,17 @@
 ecified%0A
+%09
 %09%09%09if ( 
@@ -2536,24 +2536,25 @@
 live%22 ) ) %7B%0A
+%09
 %09%09%09%09channel.
@@ -2576,24 +2576,25 @@
 false );%0A%09%09%09
+%09
 %7D else %7B%0A%09%09%09
@@ -2586,24 +2586,25 @@
 %09%09%09%7D else %7B%0A
+%09
 %09%09%09%09channel.
@@ -2626,16 +2626,22 @@
 true );%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%7D

Check for null channel.