Simple cache proxy HTTP Server

Source: Internet
Author: User

HTTP, demo client and server sockets. HTTP supports only a small subset of the get operations and hard-coded MIME types (MIME types are type descriptors for multimedia content). The proxy HTTP server is single-threaded, and each request in the thread is processed sequentially, and other requests wait. When HTTP is used as a proxy server, it also copies every file it obtains into the local cache.   For the local cache, it does not have a policy for flushing and garbage cell recycling. The HTTP server is implemented through 5 classes and an interface.   A more sophisticated implementation might split many methods outside of the main class HTTP to make the composition structure more abstract. Mimeheader.java MIME is an Internet standard that communicates multimedia content through an e-mail system. The HTTP protocol uses and expands the concept of MIME headers to transfer regular attribute/value pairs between HTTP clients and servers. P410 This class is a subclass of Hashtable, which conveniently stores and retrieves key-value pairs related to MIME headers. The parse method is used to get a string in the original MIME format and to get its keyword/value pairs into a given mimeheader instance. It uses StringTokenizer to break down input data into separate lines with CRLF (\ r \ n) sequence markers.
Class Mimeheader extends Hashtable{void parse (String data) {     StringTokenizer st = new StringTokenizer (data, "\ r \ n"); C1/>while (St.hasmoretokens ()) {     String s  = St.nexttoken ();     int colon = s.indexof (': ');     String key = S.substring (0,colon);     String val = s.substring (colon + 2);     Put (key,val);}} }
The Httpresponse.java HttpResponse class is the wrapper for all things related to HTTP server answers. It is used by the proxy portion of the HTTP class. When you send a request to an HTTP server, it is answered in an integer form stored in statuscode and a text stored in reasonphrase (these variable names are specified in the formal HTTP specification). This single-line response follows a MIME header that contains further response information.   We use the Mimeheader object to parse the string. Urlcacheentry.java to save the contents of a document on the server, you must establish a link between the URL used to retrieve the document and the document's own description. A document is described by its mimeheader and raw data.  For example, an image can be described by a content-type:image/gif-style mimeheader, and the original image data is a byte array. The constructor of the Urlcacheentry object requires a URL as a keyword and a mimeheader associated with it.   If there is a member inside Mimeheader named Content-length, the data region is pre-allocated enough space to hold its contents. Append () is used to add data to urlcacheentry objects. It is not a simple SetData () method, because data can flow through the network and need to be stored in chunks for a certain amount of time. The Append method deals with three cases: 1. The data buffer is not assigned at all; 2. The data buffer is too small for the data being introduced, so it is reassigned; 3. The introduced data can be inserted into the buffer exactly. At any time, the length member variable holds the current valid size value of the data buffer.

Simple cache proxy HTTP Server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.