Skip to content

Commit 702756c

Browse files
committed
Update http-client-lite library and fix some founded errors
1 parent d9b3101 commit 702756c

File tree

6 files changed

+21
-24
lines changed

6 files changed

+21
-24
lines changed

3rdpatry/http-client-lite/include/jdl/httpclientlite.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ namespace jdl {
188188

189189
struct HTTPClient {
190190
typedef enum {
191-
OPTIONS = 0,
192-
GET,
193-
HEAD,
194-
POST,
195-
PUT,
196-
DELETE,
197-
TRACE,
198-
CONNECT
191+
m_options = 0,
192+
m_get,
193+
m_head,
194+
m_post,
195+
m_put,
196+
m_delete,
197+
m_trace,
198+
m_connect
199199
} HTTPMethod;
200200

201201
inline static const char *method2string(HTTPMethod method) {
@@ -204,7 +204,7 @@ namespace jdl {
204204
return methods[method];
205205
}
206206

207-
inline static int connectToURI(const URI& uri) {
207+
inline static socktype_t connectToURI(const URI& uri) {
208208
struct addrinfo hints, *result, *rp;
209209

210210
memset(&hints, 0, sizeof(addrinfo));
@@ -228,7 +228,7 @@ namespace jdl {
228228
continue;
229229
}
230230

231-
int connect_result = connect(fd, rp->ai_addr, rp->ai_addrlen);
231+
int connect_result = connect(fd, rp->ai_addr, static_cast<socklen_t>(rp->ai_addrlen));
232232

233233
if (connect_result == -1) {
234234
// successfully created a socket, but connection failed. close it!
@@ -245,16 +245,16 @@ namespace jdl {
245245
return fd;
246246
}
247247

248-
inline static std::string bufferedRead(int fd) {
248+
inline static std::string bufferedRead(socktype_t fd) {
249249
size_t initial_factor = 4, buffer_increment_size = 8192, buffer_size = 0,
250250
bytes_read = 0;
251251
std::string buffer;
252252

253253
buffer.resize(initial_factor * buffer_increment_size);
254254

255255
// do {
256-
bytes_read = recv(fd, ((char *)buffer.c_str()) + buffer_size,
257-
buffer.size() - buffer_size, 0);
256+
bytes_read = recv(fd, ((char*)buffer.c_str()) + buffer_size,
257+
static_cast<socklen_t>(buffer.size() - buffer_size), 0);
258258

259259
buffer_size += bytes_read;
260260

@@ -274,7 +274,7 @@ namespace jdl {
274274

275275
inline static HTTPResponse request(HTTPMethod method, const URI& uri, const std::string& body = "") {
276276

277-
int fd = connectToURI(uri);
277+
socktype_t fd = connectToURI(uri);
278278
if (fd < 0)
279279
return HTTPResponse::fail();
280280

@@ -293,11 +293,11 @@ namespace jdl {
293293
"Content-Length: " + std::to_string(body.size()) + HTTP_NEWLINE + HTTP_NEWLINE +
294294
body;
295295

296-
/*int bytes_written = */send(fd, request.c_str(), request.size(), 0);
296+
/*int bytes_written = */send(fd, request.c_str(), static_cast<socklen_t>(request.size()), 0);
297297

298298
std::string buffer = bufferedRead(fd);
299299

300-
close(fd);
300+
closesocket(fd);
301301

302302
HTTPResponse result;
303303

core/include/prometheus/gateway.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ namespace prometheus {
120120
* additional library of HTTP requests. */
121121

122122
jdl::URI uri(uri_str);
123-
jdl::HTTPResponse response = jdl::HTTPClient::request(jdl::HTTPClient::POST, uri, body);
123+
jdl::HTTPResponse response = jdl::HTTPClient::request(jdl::HTTPClient::m_post, uri, body);
124124

125125
return std::stoi(response.response);
126126
}

core/include/prometheus/push_to_server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace prometheus {
2525
TextSerializer::Serialize(body_strm, registry_ptr->Collect());
2626

2727
std::string body = body_strm.str();
28-
jdl::HTTPResponse response = jdl::HTTPClient::request(jdl::HTTPClient::POST, jdl::URI(uri), body);
28+
jdl::HTTPResponse response = jdl::HTTPClient::request(jdl::HTTPClient::m_post, jdl::URI(uri), body);
2929
}
3030
}
3131
}

simpleapi/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ cmake_minimum_required(VERSION 3.2)
55
add_library (${PROJECT_NAME} STATIC "./src/simpleapi.cpp" )
66
target_sources (${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/prometheus/simpleapi.h")
77
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
8-
target_link_libraries (${PROJECT_NAME} INTERFACE prometheus-cpp-lite-core)
8+
target_link_libraries (${PROJECT_NAME} PUBLIC prometheus-cpp-lite-core)

simpleapi/include/prometheus/simpleapi.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include <prometheus/gauge.h>
88
#include <prometheus/benchmark.h>
99

10-
#include "prometheus/registry.h"
11-
#include "prometheus/save_to_file.h"
10+
#include <prometheus/registry.h>
11+
#include <prometheus/save_to_file.h>
1212

1313
#include <thread>
1414
#include <iostream>

simpleapi/src/simpleapi.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#include "prometheus/simpleapi.h"
22

3-
#include "prometheus/registry.h"
4-
#include "prometheus/save_to_file.h"
5-
63
#include <memory>
74

85
namespace prometheus {

0 commit comments

Comments
 (0)