Browse Source

URI/URL integration

pull/2/head
Odilitime 5 years ago
parent
commit
e78815694d
  1. 7
      src/networking/HTTPRequest.cpp
  2. 7
      src/networking/HTTPRequest.h

7
src/networking/HTTPRequest.cpp

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
#include <iostream>
#include <string.h>
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN 1
#include <winsock2.h>
@ -22,7 +23,7 @@ WSADATA wsaData; @@ -22,7 +23,7 @@ WSADATA wsaData;
int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
#endif
HTTPRequest::HTTPRequest(const std::shared_ptr<URI> u) {
HTTPRequest::HTTPRequest(const std::shared_ptr<URL> u) {
#ifdef WIN32
if (iResult != 0) {
std::cout << "WSAStartup failed: " << iResult << std::endl;
@ -38,13 +39,13 @@ HTTPRequest::HTTPRequest(const std::shared_ptr<URI> u) { @@ -38,13 +39,13 @@ HTTPRequest::HTTPRequest(const std::shared_ptr<URI> u) {
bool HTTPRequest::sendRequest(std::function<void(const HTTPResponse&)> responseCallback) const {
struct addrinfo hints;
struct addrinfo *serverInfo = nullptr;
std::string host = uri->authority.host;
std::string host = uri->host;
std::string document = uri->path;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
const int res = getaddrinfo(uri->authority.host.c_str(), std::to_string(uri->authority.port).c_str(), &hints, &serverInfo);
const int res = getaddrinfo(uri->host.c_str(), std::to_string(uri->port).c_str(), &hints, &serverInfo);
if (res != 0) {
std::cout << "Could not lookup " << host << ": " << res << std::endl;
freeaddrinfo(serverInfo);

7
src/networking/HTTPRequest.h

@ -2,8 +2,7 @@ @@ -2,8 +2,7 @@
#define HTTPREQUEST_H
#include "HTTPResponse.h"
#include "URI.h"
#include "URL.h"
#include <functional>
#include <string>
@ -18,7 +17,7 @@ enum class Method { @@ -18,7 +17,7 @@ enum class Method {
class HTTPRequest {
public:
HTTPRequest(const std::shared_ptr<URI> u);
HTTPRequest(const std::shared_ptr<URL> u);
bool sendRequest(std::function<void(const HTTPResponse&)> responseCallback) const;
const std::string versionToString(const Version version) const;
const std::string methodToString(const Method method) const;
@ -26,7 +25,7 @@ private: @@ -26,7 +25,7 @@ private:
Version version;
Method method;
std::string userAgent;
std::shared_ptr<URI> uri;
std::shared_ptr<URL> uri;
};
#endif

Loading…
Cancel
Save