OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 2 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
3 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 3 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. |
4 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ | 4 * Copyright (C) 2009 Torch Mobile Inc. http://www.torchmobile.com/ |
5 * Copyright (C) 2009 Google Inc. All rights reserved. | 5 * Copyright (C) 2009 Google Inc. All rights reserved. |
6 * Copyright (C) 2011 Apple Inc. All Rights Reserved. | 6 * Copyright (C) 2011 Apple Inc. All Rights Reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 16 matching lines...) Expand all Loading... |
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 28 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 */ | 31 */ |
32 | 32 |
33 #include "platform/network/HTTPParsers.h" | 33 #include "platform/network/HTTPParsers.h" |
34 | 34 |
35 #include "net/http/http_response_headers.h" | 35 #include "net/http/http_response_headers.h" |
36 #include "net/http/http_util.h" | 36 #include "net/http/http_util.h" |
| 37 #include "platform/HTTPNames.h" |
37 #include "platform/json/JSONParser.h" | 38 #include "platform/json/JSONParser.h" |
38 #include "platform/network/ResourceResponse.h" | 39 #include "platform/network/ResourceResponse.h" |
39 #include "platform/weborigin/Suborigin.h" | 40 #include "platform/weborigin/Suborigin.h" |
40 #include "public/platform/WebString.h" | 41 #include "public/platform/WebString.h" |
41 #include "wtf/DateMath.h" | 42 #include "wtf/DateMath.h" |
42 #include "wtf/MathExtras.h" | 43 #include "wtf/MathExtras.h" |
43 #include "wtf/text/CString.h" | 44 #include "wtf/text/CString.h" |
44 #include "wtf/text/CharacterNames.h" | 45 #include "wtf/text/CharacterNames.h" |
45 #include "wtf/text/ParsingUtilities.h" | 46 #include "wtf/text/ParsingUtilities.h" |
46 #include "wtf/text/StringBuilder.h" | 47 #include "wtf/text/StringBuilder.h" |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 | 892 |
892 response->clearHTTPHeaderField(header); | 893 response->clearHTTPHeaderField(header); |
893 while (responseHeaders->EnumerateHeader(&iterator, headerStringPiece, | 894 while (responseHeaders->EnumerateHeader(&iterator, headerStringPiece, |
894 &value)) { | 895 &value)) { |
895 response->addHTTPHeaderField(header, WebString::fromLatin1(value)); | 896 response->addHTTPHeaderField(header, WebString::fromLatin1(value)); |
896 } | 897 } |
897 } | 898 } |
898 return true; | 899 return true; |
899 } | 900 } |
900 | 901 |
| 902 bool parseMultipartFormHeadersFromBody(const char* bytes, |
| 903 size_t size, |
| 904 HTTPHeaderMap* headerFields, |
| 905 size_t* end) { |
| 906 DCHECK_EQ(0u, headerFields->size()); |
| 907 |
| 908 int headersEndPos = |
| 909 net::HttpUtil::LocateEndOfAdditionalHeaders(bytes, size, 0); |
| 910 |
| 911 if (headersEndPos < 0) |
| 912 return false; |
| 913 |
| 914 *end = headersEndPos; |
| 915 |
| 916 // Eat headers and prepend a status line as is required by |
| 917 // HttpResponseHeaders. |
| 918 std::string headers("HTTP/1.1 200 OK\r\n"); |
| 919 headers.append(bytes, headersEndPos); |
| 920 |
| 921 scoped_refptr<net::HttpResponseHeaders> responseHeaders = |
| 922 new net::HttpResponseHeaders( |
| 923 net::HttpUtil::AssembleRawHeaders(headers.data(), headers.length())); |
| 924 |
| 925 // Copy selected headers to the response. |
| 926 const AtomicString* const headerNamePointers[] = { |
| 927 &HTTPNames::Content_Disposition, &HTTPNames::Content_Transfer_Encoding, |
| 928 &HTTPNames::Content_Type}; |
| 929 for (const AtomicString* headerNamePointer : headerNamePointers) { |
| 930 StringUTF8Adaptor adaptor(*headerNamePointer); |
| 931 size_t iterator = 0; |
| 932 base::StringPiece headerNameStringPiece = adaptor.asStringPiece(); |
| 933 std::string value; |
| 934 while (responseHeaders->EnumerateHeader(&iterator, headerNameStringPiece, |
| 935 &value)) { |
| 936 headerFields->add(*headerNamePointer, WebString::fromUTF8(value)); |
| 937 } |
| 938 } |
| 939 |
| 940 return true; |
| 941 } |
| 942 |
901 // See https://tools.ietf.org/html/draft-ietf-httpbis-jfv-01, Section 4. | 943 // See https://tools.ietf.org/html/draft-ietf-httpbis-jfv-01, Section 4. |
902 std::unique_ptr<JSONArray> parseJSONHeader(const String& header, | 944 std::unique_ptr<JSONArray> parseJSONHeader(const String& header, |
903 int maxParseDepth) { | 945 int maxParseDepth) { |
904 StringBuilder sb; | 946 StringBuilder sb; |
905 sb.append("["); | 947 sb.append("["); |
906 sb.append(header); | 948 sb.append(header); |
907 sb.append("]"); | 949 sb.append("]"); |
908 std::unique_ptr<JSONValue> headerValue = | 950 std::unique_ptr<JSONValue> headerValue = |
909 parseJSON(sb.toString(), maxParseDepth); | 951 parseJSON(sb.toString(), maxParseDepth); |
910 return JSONArray::from(std::move(headerValue)); | 952 return JSONArray::from(std::move(headerValue)); |
911 } | 953 } |
912 | 954 |
913 } // namespace blink | 955 } // namespace blink |
OLD | NEW |