]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/net/http/Request.cpp
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / src / jaegertracing / net / http / Request.cpp
1 /*
2 * Copyright (c) 2017-2018 Uber Technologies, Inc.
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 #include "jaegertracing/net/http/Request.h"
18 #include "jaegertracing/net/http/SocketReader.h"
19
20 #include <regex>
21
22 namespace jaegertracing {
23 namespace net {
24 namespace http {
25
26 Request Request::read(Socket & socket)
27 {
28 std::string response = SocketReader::read(socket);
29 std::istringstream responseStream(response);
30 return Request::parse(responseStream);
31 }
32
33 Request Request::parse(std::istream& in)
34 {
35 const std::regex requestLinePattern(
36 "([A-Z]+) ([^ ]+) HTTP/([0-9]\\.[0-9])$");
37 std::string line;
38 std::smatch match;
39 if (!readLineCRLF(in, line) ||
40 !std::regex_match(line, match, requestLinePattern) ||
41 match.size() < 4) {
42 throw ParseError::make("request line", line);
43 }
44 Request request;
45
46 request._method = parseMethod(match[1]);
47 request._target = match[2];
48 request._version = match[3];
49
50 readHeaders(in, request._headers);
51 request._body = std::string(std::istreambuf_iterator<char>(in),
52 std::istreambuf_iterator<char>{});
53
54 return request;
55 }
56
57 } // namespace http
58 } // namespace net
59 } // namespace jaegertracing