⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httphandler.java

📁 21天学通java的示例程序源代码
💻 JAVA
字号:
// HTTPHandler.java

package com.wrox.httpserver;

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

/**
 * Encapsulates an HTTP method handler such as GET, HEAD or POST.
 */
abstract class HTTPHandler extends HTTPConstants {

  // Instance variables
  protected HTTPResponse response;
  protected HTTPMessageHeaders headers;
  protected BufferedInputStream bis;
  protected BufferedOutputStream bos;
  protected String uri;
  protected HTTPInformation info;

  /**
   * Constructs an HTTPHandler. This constructor can only be called from the
   * respective method handler class.
   */
  public HTTPHandler(HTTPInformation info, String uri, 
                     HTTPMessageHeaders headers, InetAddress address, 
                     String protocol, BufferedInputStream bis, 
                     BufferedOutputStream bos) {

    // Initialize instance variables
    this.headers = headers;
    this.info = info;
    this.bis = bis;
    this.bos = bos;
    this.uri = uri;

    // Create an HTTP response
    response = new HTTPResponse();

    // Set up information
    info.serverProtocol = protocol;
    info.accept = headers.getHeader(HEADER_FIELD_ACCEPT);
    info.contentLength = headers.getHeader(HEADER_FIELD_CONTENTLENGTH);
    info.contentType = headers.getHeader(HEADER_FIELD_CONTENTTYPE);
    info.pragma = headers.getHeader(HEADER_FIELD_PRAGMA);
    info.referer = headers.getHeader(HEADER_FIELD_REFERER);
    info.userAgent = headers.getHeader(HEADER_FIELD_USERAGENT);
    info.remoteAddr = address.getHostAddress().toString();
    info.remoteHost = address.getHostName();
  }

  /**
   * Processes the corresponding method.
   */
  public abstract void process() throws HTTPException;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -