Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: sky/engine/platform/network/HTTPRequest.cpp

Issue 1239633002: Remove //sky/engine/platform/network (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2011 Apple Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "sky/engine/platform/network/HTTPRequest.h"
27
28 #include "sky/engine/wtf/text/CString.h"
29
30 namespace blink {
31
32 PassRefPtr<HTTPRequest> HTTPRequest::parseHTTPRequestFromBuffer(const char* data , size_t length, String& failureReason)
33 {
34 if (!length) {
35 failureReason = "No data to parse.";
36 return nullptr;
37 }
38
39 // Request we will be building.
40 RefPtr<HTTPRequest> request = HTTPRequest::create();
41
42 // Advance a pointer through the data as needed.
43 const char* pos = data;
44 size_t remainingLength = length;
45
46 // 1. Parse Method + URL.
47 size_t requestLineLength = request->parseRequestLine(pos, remainingLength, f ailureReason);
48 if (!requestLineLength)
49 return nullptr;
50 pos += requestLineLength;
51 remainingLength -= requestLineLength;
52
53 // 2. Parse HTTP Headers.
54 size_t headersLength = request->parseHeaders(pos, remainingLength, failureRe ason);
55 if (!headersLength)
56 return nullptr;
57 pos += headersLength;
58 remainingLength -= headersLength;
59
60 // 3. Parse HTTP Data.
61 size_t dataLength = request->parseRequestBody(pos, remainingLength);
62 remainingLength -= dataLength;
63
64 // We should have processed the entire input.
65 ASSERT(!remainingLength);
66 return request.release();
67 }
68
69 size_t HTTPRequest::parseRequestLine(const char* data, size_t length, String& fa ilureReason)
70 {
71 String url;
72 size_t result = parseHTTPRequestLine(data, length, failureReason, m_requestM ethod, url, m_httpVersion);
73 m_url = KURL(KURL(), url);
74 return result;
75 }
76
77 size_t HTTPRequest::parseHeaders(const char* data, size_t length, String& failur eReason)
78 {
79 const char* p = data;
80 const char* end = data + length;
81 AtomicString name;
82 AtomicString value;
83 while (p < data + length) {
84 size_t consumedLength = parseHTTPHeader(p, end - p, failureReason, name, value);
85 if (!consumedLength)
86 return 0;
87 p += consumedLength;
88 if (name.isEmpty())
89 break;
90 m_headerFields.add(name, value);
91 }
92 return p - data;
93 }
94
95 size_t HTTPRequest::parseRequestBody(const char* data, size_t length)
96 {
97 return parseHTTPRequestBody(data, length, m_body);
98 }
99
100 HTTPRequest::HTTPRequest()
101 : m_httpVersion(Unknown)
102 {
103 }
104
105 HTTPRequest::HTTPRequest(const String& requestMethod, const KURL& url, HTTPVersi on version)
106 : m_url(url)
107 , m_httpVersion(version)
108 , m_requestMethod(requestMethod)
109 {
110 }
111
112 HTTPRequest::~HTTPRequest()
113 {
114 }
115
116 } // namespace blink
OLDNEW
« no previous file with comments | « sky/engine/platform/network/HTTPRequest.h ('k') | sky/engine/platform/network/ParsedContentType.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698