src/GetRequest.java
@Override
	public void ReturnResponse() throws IOException {
		OutputStream outputStream = m_Socket.getOutputStream();
		File fileToReturn;
		fileToReturn = openFileAccordingToUrl(m_Url);
		if (!fileToReturn.exists()) {
			ReturnNotFoundResponse();
		} 
		// Create chunk response
		else if (m_ShouldSendChunked) {
			m_Headers = Tools.SetupChunkedResponseHeaders(m_Type);
			StringBuilder responseString = new StringBuilder(createHeaders());
			responseString.append(CRLF);
			writeChunked(new DataOutputStream(outputStream), responseString.toString().getBytes(), fileToReturn);
		} else {
			// Create and send regular response
			m_Content = Tools.ReadFile(fileToReturn);
			m_Headers = Tools.SetupResponseHeaders(m_Content, m_Type);
			StringBuilder responseString = new StringBuilder(createHeaders());

			System.out.println(responseString);
			responseString.append(CRLF);

			try {
				outputStream.write(responseString.toString().getBytes());
				outputStream.write(m_Content);
				outputStream.flush();
				outputStream.close();
			} catch (IOException e) {
				System.out.println("No socket to write the respone to.");
			}
		}
	}
/*
	 * Build the response for GET request
	 */
Build the response for GET request
Build the response for GET request
@Override
	public void ReturnResponse() throws IOException {
		OutputStream outputStream = m_Socket.getOutputStream();
		File fileToReturn;
		fileToReturn = openFileAccordingToUrl(m_Url);
		if (!fileToReturn.exists()) {
			ReturnNotFoundResponse();
		} 
		else if (m_ShouldSendChunked) {
			m_Headers = Tools.SetupChunkedResponseHeaders(m_Type);
			StringBuilder responseString = new StringBuilder(createHeaders());
			responseString.append(CRLF);
			writeChunked(new DataOutputStream(outputStream), responseString.toString().getBytes(), fileToReturn);
		} else {
			m_Content = Tools.ReadFile(fileToReturn);
			m_Headers = Tools.SetupResponseHeaders(m_Content, m_Type);
			StringBuilder responseString = new StringBuilder(createHeaders());
			System.out.println(responseString);
			responseString.append(CRLF);
			try {
				outputStream.write(responseString.toString().getBytes());
				outputStream.write(m_Content);
				outputStream.flush();
				outputStream.close();
			} catch (IOException e) {
				System.out.println("No socket to write the respone to.");
			}
		}
	}
@ Override public void ReturnResponse ( ) throws IOException { OutputStream outputStream = m_Socket . getOutputStream ( ) ; File fileToReturn ; fileToReturn = openFileAccordingToUrl ( m_Url ) ; if ( ! fileToReturn . exists ( ) ) { ReturnNotFoundResponse ( ) ; } else if ( m_ShouldSendChunked ) { m_Headers = Tools . SetupChunkedResponseHeaders ( m_Type ) ; StringBuilder responseString = new StringBuilder ( createHeaders ( ) ) ; responseString . append ( CRLF ) ; writeChunked ( new DataOutputStream ( outputStream ) , responseString . toString ( ) . getBytes ( ) , fileToReturn ) ; } else { m_Content = Tools . ReadFile ( fileToReturn ) ; m_Headers = Tools . SetupResponseHeaders ( m_Content , m_Type ) ; StringBuilder responseString = new StringBuilder ( createHeaders ( ) ) ; System . out . println ( responseString ) ; responseString . append ( CRLF ) ; try { outputStream . write ( responseString . toString ( ) . getBytes ( ) ) ; outputStream . write ( m_Content ) ; outputStream . flush ( ) ; outputStream . close ( ) ; } catch ( IOException e ) { System . out . println ( "No socket to write the respone to." ) ; } } }
Build the response for GET request
Build the response for GET request
// Create chunk response // Create and send regular response