Can anyone know how to fill the blanks please?

HttpRequest.java

This is the code for the HttpRequest class that you will need to complete for part 2. The code for the other classes is provided on this page.

/*************************************
* Filename: HttpRequest.java
* Names:
* Student-IDs:
* Date:
*************************************/

import java.net.*;
import java.io.*;
import java.util.*;

/**
* Class for downloading one object from a http server.
*
*/
public class HttpRequest {

private String host;
private String path;
private String requestMessage;


private static final int HTTP_PORT = 80;
private static final String CRLF = "\r\n";
private static final int BUF_SIZE = 8192;
private static final int MAX_OBJECT_SIZE = 102400;

/* Create an HttpRequest object. */
public HttpRequest(String url) {

/* Split "URL" into "host name" and "path name", and
* set host and path class variables.
* if URL is only a host, use "/" as path
*/

/* Fill in */


/* Construct requestMessage, add a header line so that
* server closes connection after one response. */

/* Fill in */

return;
}


/* Send Http request, parse response and return requested object
* as String (if no error),
* otherwise return meaningfull error message.
* Don't catch IOExceptions. Just throw them to MailClient*/
public String sendRequest() throws IOException {

/* buffer to read object in 8kB chunks */
char[] buf = new char[BUF_SIZE];

/* Maximum size of object is 100kB, which should be enough for most objects.
* Change constant if you need more. */
char[] body = new char[MAX_OBJECT_SIZE];

String statusLine=""; // status line
int status; // status code
String headers=""; // headers
int bodyLength=-1; // lenghth of body

String[] tmp;

/* The socket to the server */
Socket connection;

/* Streams for reading and writing the socket */
BufferedReader fromServer;
DataOutputStream toServer;

System.out.println("Connecting server: " + host+CRLF);

/* Connect to http server on port 80.
* Assign input and output streams to connection. */
connection = /* Fill in */;
fromServer = /* Fill in */;
toServer = /* Fill in */;

System.out.println("Send request:\n" + requestMessage);


/* Send requestMessage to http server */
/* Fill in */

/* Read the status line from response message */
statusLine= /* Fill in */;
System.out.println("Status Line:\n"+statusLine+CRLF);

/* Extract status code from status line and assign it to
* "status" variable". */
/* Fill in */

/* Check if status code is correct, i.e. response hold
* the requested object. If status code is not 200,
* close connection and return an error message. */
/* Fill in */

/* Read header lines from response message. Assign String
* of headers to "headers" variable.
* Recall that an empty line indicates end of headers.
* Extract length from "Content-Length:" (or "Content-length:")
* header line, if present, and assign to "bodyLength" variable.
*/
/* Fill in */ // about 10 lines of code
System.out.println("Headers:\n"+headers+CRLF);


/* No Content-Length header */
boolean noLength=false;
if (bodyLength==-1) {
noLength=true;
}

/* If object is larger than MAX_OBJECT_SIZE, close the connection and
* return meaningful message. */
if (/* Fill in */) {
/* Fill in */
return(/* Fill in */ +bodyLength);
}

/* Read the body in chunks of BUF_SIZE using buf[] and copy the chunk
* into body[]. Stop when either we have
* read Content-Length bytes or when the connection is
* closed (when there is no Connection-Length in the response).
* Use one of the read() methods of BufferedReader here, NOT readLine().
* Also make sure not to read more than MAX_OBJECT_SIZE characters.
*/
int bytesRead = 0;

/* Fill in */ // Requires 10-20 lines of code

/* At this points body[] should hold to body of the downloaded object and
* bytesRead should hold the number of bytes read from the BufferedReader
*/

/* Close connection and return object as String. */
System.out.println("Done reading file. Closing connection.");
connection.close();
return(new String(body, 0, bytesRead));
}
}