Home | History | Annotate | Download | only in http
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package tests.http;
     18 
     19 import java.util.List;
     20 
     21 /**
     22  * An HTTP request that came into the mock web server.
     23  */
     24 public final class RecordedRequest {
     25     private final String requestLine;
     26     private final List<String> headers;
     27     private final List<Integer> chunkSizes;
     28     private final int bodySize;
     29     private final byte[] body;
     30     private final int sequenceNumber;
     31 
     32     RecordedRequest(String requestLine, List<String> headers, List<Integer> chunkSizes,
     33             int bodySize, byte[] body, int sequenceNumber) {
     34         this.requestLine = requestLine;
     35         this.headers = headers;
     36         this.chunkSizes = chunkSizes;
     37         this.bodySize = bodySize;
     38         this.body = body;
     39         this.sequenceNumber = sequenceNumber;
     40     }
     41 
     42     public String getRequestLine() {
     43         return requestLine;
     44     }
     45 
     46     public List<String> getHeaders() {
     47         return headers;
     48     }
     49 
     50     /**
     51      * Returns the sizes of the chunks of this request's body, or an empty list
     52      * if the request's body was empty or unchunked.
     53      */
     54     public List<Integer> getChunkSizes() {
     55         return chunkSizes;
     56     }
     57 
     58     /**
     59      * Returns the total size of the body of this POST request (before
     60      * truncation).
     61      */
     62     public int getBodySize() {
     63         return bodySize;
     64     }
     65 
     66     /**
     67      * Returns the body of this POST request. This may be truncated.
     68      */
     69     public byte[] getBody() {
     70         return body;
     71     }
     72 
     73     /**
     74      * Returns the index of this request on its HTTP connection. Since a single
     75      * HTTP connection may serve multiple requests, each request is assigned its
     76      * own sequence number.
     77      */
     78     public int getSequenceNumber() {
     79         return sequenceNumber;
     80     }
     81 
     82     @Override public String toString() {
     83         return requestLine;
     84     }
     85 }
     86