14c54154c83a5b3516d81903140b31349f196cbe2Steve Howard/* 24c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * Copyright (C) 2010 The Android Open Source Project 34c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * 44c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * Licensed under the Apache License, Version 2.0 (the "License"); 54c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * you may not use this file except in compliance with the License. 64c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * You may obtain a copy of the License at 74c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * 84c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * http://www.apache.org/licenses/LICENSE-2.0 94c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * 104c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * Unless required by applicable law or agreed to in writing, software 114c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * distributed under the License is distributed on an "AS IS" BASIS, 124c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * See the License for the specific language governing permissions and 144c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * limitations under the License. 154c54154c83a5b3516d81903140b31349f196cbe2Steve Howard */ 164c54154c83a5b3516d81903140b31349f196cbe2Steve Howard 174c54154c83a5b3516d81903140b31349f196cbe2Steve Howardpackage tests.http; 184c54154c83a5b3516d81903140b31349f196cbe2Steve Howard 194c54154c83a5b3516d81903140b31349f196cbe2Steve Howardimport java.util.List; 204c54154c83a5b3516d81903140b31349f196cbe2Steve Howard 214c54154c83a5b3516d81903140b31349f196cbe2Steve Howard/** 224c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * An HTTP request that came into the mock web server. 234c54154c83a5b3516d81903140b31349f196cbe2Steve Howard */ 244c54154c83a5b3516d81903140b31349f196cbe2Steve Howardpublic final class RecordedRequest { 254c54154c83a5b3516d81903140b31349f196cbe2Steve Howard private final String requestLine; 264c54154c83a5b3516d81903140b31349f196cbe2Steve Howard private final List<String> headers; 274c54154c83a5b3516d81903140b31349f196cbe2Steve Howard private final List<Integer> chunkSizes; 284c54154c83a5b3516d81903140b31349f196cbe2Steve Howard private final int bodySize; 294c54154c83a5b3516d81903140b31349f196cbe2Steve Howard private final byte[] body; 304c54154c83a5b3516d81903140b31349f196cbe2Steve Howard private final int sequenceNumber; 314c54154c83a5b3516d81903140b31349f196cbe2Steve Howard 324c54154c83a5b3516d81903140b31349f196cbe2Steve Howard RecordedRequest(String requestLine, List<String> headers, List<Integer> chunkSizes, 334c54154c83a5b3516d81903140b31349f196cbe2Steve Howard int bodySize, byte[] body, int sequenceNumber) { 344c54154c83a5b3516d81903140b31349f196cbe2Steve Howard this.requestLine = requestLine; 354c54154c83a5b3516d81903140b31349f196cbe2Steve Howard this.headers = headers; 364c54154c83a5b3516d81903140b31349f196cbe2Steve Howard this.chunkSizes = chunkSizes; 374c54154c83a5b3516d81903140b31349f196cbe2Steve Howard this.bodySize = bodySize; 384c54154c83a5b3516d81903140b31349f196cbe2Steve Howard this.body = body; 394c54154c83a5b3516d81903140b31349f196cbe2Steve Howard this.sequenceNumber = sequenceNumber; 404c54154c83a5b3516d81903140b31349f196cbe2Steve Howard } 414c54154c83a5b3516d81903140b31349f196cbe2Steve Howard 424c54154c83a5b3516d81903140b31349f196cbe2Steve Howard public String getRequestLine() { 434c54154c83a5b3516d81903140b31349f196cbe2Steve Howard return requestLine; 444c54154c83a5b3516d81903140b31349f196cbe2Steve Howard } 454c54154c83a5b3516d81903140b31349f196cbe2Steve Howard 464c54154c83a5b3516d81903140b31349f196cbe2Steve Howard public List<String> getHeaders() { 474c54154c83a5b3516d81903140b31349f196cbe2Steve Howard return headers; 484c54154c83a5b3516d81903140b31349f196cbe2Steve Howard } 494c54154c83a5b3516d81903140b31349f196cbe2Steve Howard 504c54154c83a5b3516d81903140b31349f196cbe2Steve Howard /** 514c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * Returns the sizes of the chunks of this request's body, or an empty list 524c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * if the request's body was empty or unchunked. 534c54154c83a5b3516d81903140b31349f196cbe2Steve Howard */ 544c54154c83a5b3516d81903140b31349f196cbe2Steve Howard public List<Integer> getChunkSizes() { 554c54154c83a5b3516d81903140b31349f196cbe2Steve Howard return chunkSizes; 564c54154c83a5b3516d81903140b31349f196cbe2Steve Howard } 574c54154c83a5b3516d81903140b31349f196cbe2Steve Howard 584c54154c83a5b3516d81903140b31349f196cbe2Steve Howard /** 594c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * Returns the total size of the body of this POST request (before 604c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * truncation). 614c54154c83a5b3516d81903140b31349f196cbe2Steve Howard */ 624c54154c83a5b3516d81903140b31349f196cbe2Steve Howard public int getBodySize() { 634c54154c83a5b3516d81903140b31349f196cbe2Steve Howard return bodySize; 644c54154c83a5b3516d81903140b31349f196cbe2Steve Howard } 654c54154c83a5b3516d81903140b31349f196cbe2Steve Howard 664c54154c83a5b3516d81903140b31349f196cbe2Steve Howard /** 674c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * Returns the body of this POST request. This may be truncated. 684c54154c83a5b3516d81903140b31349f196cbe2Steve Howard */ 694c54154c83a5b3516d81903140b31349f196cbe2Steve Howard public byte[] getBody() { 704c54154c83a5b3516d81903140b31349f196cbe2Steve Howard return body; 714c54154c83a5b3516d81903140b31349f196cbe2Steve Howard } 724c54154c83a5b3516d81903140b31349f196cbe2Steve Howard 734c54154c83a5b3516d81903140b31349f196cbe2Steve Howard /** 744c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * Returns the index of this request on its HTTP connection. Since a single 754c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * HTTP connection may serve multiple requests, each request is assigned its 764c54154c83a5b3516d81903140b31349f196cbe2Steve Howard * own sequence number. 774c54154c83a5b3516d81903140b31349f196cbe2Steve Howard */ 784c54154c83a5b3516d81903140b31349f196cbe2Steve Howard public int getSequenceNumber() { 794c54154c83a5b3516d81903140b31349f196cbe2Steve Howard return sequenceNumber; 804c54154c83a5b3516d81903140b31349f196cbe2Steve Howard } 814c54154c83a5b3516d81903140b31349f196cbe2Steve Howard 824c54154c83a5b3516d81903140b31349f196cbe2Steve Howard @Override public String toString() { 834c54154c83a5b3516d81903140b31349f196cbe2Steve Howard return requestLine; 844c54154c83a5b3516d81903140b31349f196cbe2Steve Howard } 85d6f9b5e72a135365f2358d79b3ea3c9f7cb99c8eSteve Howard 86d6f9b5e72a135365f2358d79b3ea3c9f7cb99c8eSteve Howard public String getMethod() { 87d6f9b5e72a135365f2358d79b3ea3c9f7cb99c8eSteve Howard return getRequestLine().split(" ")[0]; 88d6f9b5e72a135365f2358d79b3ea3c9f7cb99c8eSteve Howard } 89d6f9b5e72a135365f2358d79b3ea3c9f7cb99c8eSteve Howard 90d6f9b5e72a135365f2358d79b3ea3c9f7cb99c8eSteve Howard public String getPath() { 91d6f9b5e72a135365f2358d79b3ea3c9f7cb99c8eSteve Howard return getRequestLine().split(" ")[1]; 92d6f9b5e72a135365f2358d79b3ea3c9f7cb99c8eSteve Howard } 934c54154c83a5b3516d81903140b31349f196cbe2Steve Howard} 94