Source Code Java Help

Source Code

The implementation of this HTTP server is presented here in five classes and one interface. A more complete implementation would likely split many of the methods out of the main class, httpd, in order to abstract more of the components. For space considerations in this book, most of the functionality is in the single class, and the-small support classes are only acting as data structures. We will take a close look at each class and method to examine how this server works, starting with the support classes and ending with the main program.

MimeHeader .java

MIME is an Internet standard for communicating multimedia content over e-mail
systems. This standard was created by Nat Eisenstein in 1992. The HITP protocol uses, and extends the notion of MIME headers to pass general attribute/value pairs between the I-IITP client and server

CONSTRUCTORS This class is a subclass of Hash table so that it can conveniently
storeand retrieve the key /value pairs associated with a MIME header. It has two ‘
constructors. One creates a blank Mime Header with no keys. The other takes a string formatted as a MIME”header and parses it for the initial contents of the object. See  next.

parse() The method is used to take a raw MIME-formatted string and enter its key/value pairs into a given instance of Mime Header. It uses a String Tenderizer to split the input data into individual lines, marked by the CRLF (rn) sequence. It then iterates through breadline using the canonical while …  sequence. For each line of the MIME header, the parses ) method splits the line into two strings separated by a colon (:). The two variables key and val are set by the stringing  method to extract the characters before the colon, those after the colon, and its following space character. Once these two strings have been extracted, the put method is used to store this association between the key and value in the Hash table.

put( ), get( ), AND flx() The put() and get() methods in Hashtable would work fine for this application if not for one rather odd thing. The MIME specification defin ed several important keys, such as Content-Type and Content-Length. Some early implements of MIME systems, notably web browsers, took liberties with the
capitalization of these fields. Some use Content-type, others content-type. To avoid
mishaps, our HTIP server tries to convert all incoming and outgoing Mime Header
keys to be in the ‘canonical form, Content-Type. Thus, we override put( ) and get( ) to convert the values’ capitalization, using the method fix( ), before entering them int o the Hash table and before looking up a given key.

CONSTRUCTORS ‘If you construct an Http Response with a string argument, this is taken to be a raw response from an HTIP server and is passed to parset ), described next, to initialize the object. Alternatively, you can pass in a precomputed status code, reason phrase, and MIME header. parse() ,The parsemethod takes the raw data that was read from the HITP server, parses the status Code and reasonPhrase from the first line, and then constructs a MimcHeader out of the remaining lines.  to String The to String method is the inverse of parse It takes the current values of the Http Response object and returns a string that an HTIP client would expect to read back from a server.

  • Feel free to send us an inquiry, we will reply back in hours.


Posted on September 17, 2014 in Networking

Share the Story

About the Author

Back to Top