コード例 #1
0
    /*
     * Reads an entry from an input stream. A typical entry looks like this:
     *   http://google.com/foo
     *   GET
     *   2
     *   Accept-Language: fr-CA
     *   Accept-Charset: UTF-8
     *   HTTP/1.1 200 OK
     *   3
     *   Content-Type: image/png
     *   Content-Length: 100
     *   Cache-Control: max-age=600
     *
     * A typical HTTPS file looks like this:
     *   https://google.com/foo
     *   GET
     *   2
     *   Accept-Language: fr-CA
     *   Accept-Charset: UTF-8
     *   HTTP/1.1 200 OK
     *   3
     *   Content-Type: image/png
     *   Content-Length: 100
     *   Cache-Control: max-age=600
     *
     *   AES_256_WITH_MD5
     *   2
     *   base64-encoded peerCertificate[0]
     *   base64-encoded peerCertificate[1]
     *   -1
     *
     * The file is newline separated. The first two lines are the URL and
     * the request method. Next is the number of HTTP Vary request header
     * lines, followed by those lines.
     *
     * Next is the response status line, followed by the number of HTTP
     * response header lines, followed by those lines.
     *
     * HTTPS responses also contain SSL session information. This begins
     * with a blank line, and then a line containing the cipher suite. Next
     * is the length of the peer certificate chain. These certificates are
     * base64-encoded and appear each on their own line. The next line
     * contains the length of the local certificate chain. These
     * certificates are also base64-encoded and appear each on their own
     * line. A length of -1 is used to encode a null array.
     */
    public Entry(InputStream in) throws IOException {
      try {
        StrictLineReader reader = new StrictLineReader(in, Charsets.US_ASCII);
        uri = reader.readLine();
        requestMethod = reader.readLine();
        varyHeaders = new RawHeaders();
        int varyRequestHeaderLineCount = reader.readInt();
        for (int i = 0; i < varyRequestHeaderLineCount; i++) {
          varyHeaders.addLine(reader.readLine());
        }

        responseHeaders = new RawHeaders();
        responseHeaders.setStatusLine(reader.readLine());
        int responseHeaderLineCount = reader.readInt();
        for (int i = 0; i < responseHeaderLineCount; i++) {
          responseHeaders.addLine(reader.readLine());
        }

        //                if (isHttps()) {
        //                    String blank = reader.readLine();
        //                    if (blank.length() != 0) {
        //                        throw new IOException("expected \"\" but was \"" + blank + "\"");
        //                    }
        //                    cipherSuite = reader.readLine();
        //                    peerCertificates = readCertArray(reader);
        //                    localCertificates = readCertArray(reader);
        //                } else {
        cipherSuite = null;
        peerCertificates = null;
        localCertificates = null;
        //                }
      } finally {
        in.close();
      }
    }
コード例 #2
0
 @Override
 public void onStringAvailable(String s) {
   try {
     if (mRawHeaders.getStatusLine() == null) {
       mRawHeaders.setStatusLine(s);
     } else if (!"\r".equals(s)) {
       mRawHeaders.addLine(s);
     } else {
       mHeaders = new ResponseHeaders(mRequest.getUri(), mRawHeaders);
       onHeadersReceived();
       // socket may get detached after headers (websocket)
       if (mSocket == null) return;
       DataEmitter emitter = Util.getBodyDecoder(mSocket, mRawHeaders, false, mReporter);
       setDataEmitter(emitter);
     }
   } catch (Exception ex) {
     report(ex);
   }
 }