-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #88 Header views on requests could be moved on a re-allocation
- Loading branch information
Showing
16 changed files
with
267 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <string_view> | ||
|
||
namespace lift { | ||
|
||
class Executor; | ||
|
||
class Header { | ||
friend Executor; | ||
|
||
public: | ||
/** | ||
* Creates an owned header. | ||
* @param name The name of the header. | ||
* @param value The value of the header. | ||
*/ | ||
explicit Header( | ||
std::string_view name, | ||
std::string_view value); | ||
|
||
/** | ||
* Creates an owned header. | ||
* @param header_full The full "<name>: <value>" header field. | ||
*/ | ||
explicit Header( | ||
std::string header_full); | ||
|
||
/** | ||
* @return The entire header, e.g. "Connection: Keep-Alive" | ||
*/ | ||
[[nodiscard]] auto HeaderFull() const -> const std::string& { return m_header; } | ||
|
||
/** | ||
* @return The header's name. | ||
*/ | ||
[[nodiscard]] auto Name() const -> std::string_view | ||
{ | ||
std::string_view name = m_header; | ||
name = name.substr(0, m_colon_pos); | ||
return name; | ||
} | ||
|
||
/** | ||
* @return The header's value or empty if it doesn't have a value. | ||
*/ | ||
[[nodiscard]] auto Value() const -> std::string_view | ||
{ | ||
std::string_view value = m_header; | ||
// Remove the name from the value. We know we made this string with ": " so skip two chars. | ||
value.remove_prefix(m_colon_pos + 2); | ||
return value; | ||
} | ||
|
||
private: | ||
/// The full header data. | ||
std::string m_header {}; | ||
std::size_t m_colon_pos { 0 }; | ||
|
||
// Executor requires a char* to pass into the curlslist. | ||
[[nodiscard]] auto headerFull() -> std::string& { return m_header; } | ||
}; | ||
|
||
} // lift |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "lift/Header.hpp" | ||
|
||
#include <string> | ||
|
||
namespace lift { | ||
|
||
Header::Header( | ||
std::string_view name, | ||
std::string_view value) | ||
{ | ||
m_header.reserve(name.length() + value.length() + 2); | ||
m_header.append(name.data(), name.length()); | ||
m_header.append(": "); | ||
m_header.append(value.data(), value.length()); | ||
|
||
m_colon_pos = name.length(); | ||
} | ||
|
||
Header::Header( | ||
std::string header_full) | ||
: m_header(std::move(header_full)) | ||
{ | ||
m_colon_pos = m_header.find(":"); | ||
// class assumes the two bytes ": " always exist, enforce that. | ||
if (m_colon_pos == std::string::npos) { | ||
m_colon_pos = m_header.length(); | ||
m_header.append(": "); | ||
} else if (m_colon_pos == m_header.length() - 1) { | ||
m_header.append(" "); | ||
} else if (m_header[m_colon_pos + 1] != ' ') { | ||
m_header.insert(m_colon_pos + 1, 1, ' '); | ||
} | ||
} | ||
|
||
} // lift |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.