Esempio n. 1
0
    private RecordedRequest readRequest(SpdyStream stream) throws IOException {
      List<String> spdyHeaders = stream.getRequestHeaders();
      List<String> httpHeaders = new ArrayList<String>();
      String method = "<:method omitted>";
      String path = "<:path omitted>";
      String version = "<:version omitted>";
      for (Iterator<String> i = spdyHeaders.iterator(); i.hasNext(); ) {
        String name = i.next();
        String value = i.next();
        if (":method".equals(name)) {
          method = value;
        } else if (":path".equals(name)) {
          path = value;
        } else if (":version".equals(name)) {
          version = value;
        } else {
          httpHeaders.add(name + ": " + value);
        }
      }

      InputStream bodyIn = stream.getInputStream();
      ByteArrayOutputStream bodyOut = new ByteArrayOutputStream();
      byte[] buffer = new byte[8192];
      int count;
      while ((count = bodyIn.read(buffer)) != -1) {
        bodyOut.write(buffer, 0, count);
      }
      bodyIn.close();
      String requestLine = method + ' ' + path + ' ' + version;
      List<Integer> chunkSizes = Collections.emptyList(); // No chunked encoding for SPDY.
      return new RecordedRequest(
          requestLine,
          httpHeaders,
          chunkSizes,
          bodyOut.size(),
          bodyOut.toByteArray(),
          sequenceNumber.getAndIncrement(),
          socket);
    }