Package de.ioexception.www.http.impl

Examples of de.ioexception.www.http.impl.BasicHttpRequest


  @Override
  protected HttpRequest parseRequest(InputStream inputStream) throws IOException
  {
    String firstLine = readLine(inputStream);

    BasicHttpRequest request = new BasicHttpRequest();

    request.setVersion(HttpVersion.extractVersion(firstLine));
    request.setRequestUri(firstLine.split(" ", 3)[1]);
    request.setMethod(HttpMethod.extractMethod(firstLine));

    Map<String, String> headers = new HashMap<String, String>();

    String nextLine = "";
    while (!(nextLine = readLine(inputStream)).equals(""))
    {
      String values[] = nextLine.split(":", 2);
      headers.put(values[0], values[1].trim());
    }
    request.setHeaders(headers);

    if (headers.containsKey(Http.CONTENT_LENGTH))
    {
      int size = Integer.parseInt(headers.get(Http.CONTENT_LENGTH));
      byte[] data = new byte[size];
      int n;
      for (int i = 0; i < size && (n = inputStream.read()) != -1; i++)
      {
        data[i] = (byte) n;
      }
      request.setEntity(data);
    }
    else
    {
      request.setEntity(null);
    }

    return request;
  }
View Full Code Here

TOP

Related Classes of de.ioexception.www.http.impl.BasicHttpRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.