Skip to content

Commit

Permalink
Upgrade nghttp2 to 1.64.0
Browse files Browse the repository at this point in the history
In new nghttp2 versions, conretely since 1.51.0, this library
separates old module nghttp2-asio, now in a different
repository.

Old percent_encode has evolve to percent_encode_path which is
not exactly the same because slash '/' is not encoded, so we
need to re-implement the function within the project scope,
not using nghttp2/nghttp2-asio stuff anymore.

Implement: #25
  • Loading branch information
testillano authored and Eduardo Ramos Testillano (eramedu) committed Dec 20, 2024
1 parent 342761d commit d1851ae
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/URLFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,40 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <nghttp2/asio_http2.h>

#include <string>
#include <regex>
//#include <iomanip>
//#include <cctype>

#include <ert/http2comm/URLFunctions.hpp>

#include <ert/http2comm/URLFunctions.hpp>

namespace nghttp2
{
namespace util
{
// This percent_encode function is declared in util.h file from
// nghttp2 source code and is present in the library itself, but
// the util.h header file is not installed in /usr/local/include/nghttp2
// We declare it here so it can be used in the
// add_query_parameters_to_uri anonymous function
extern std::string percent_encode(const std::string& target);
}
}

const char UPPER_XDIGITS[] = "0123456789ABCDEF";

namespace ert
{
namespace http2comm
{
std::string URLFunctions::encode(const std::string& decodedUrl)
{
return nghttp2::util::percent_encode(decodedUrl);
std::string result;
result.reserve(decodedUrl.length() * 3); // minimize reallocations in std::string
// (we multiply by 3 because it is the worst case: %XX for every character)

for (unsigned char c : decodedUrl) {
if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { // unreserved (RFC3986)
result += c;
} else {
// encode as %XX
result += '%';
result += UPPER_XDIGITS[c >> 4]; // first digit
result += UPPER_XDIGITS[c & 0x0F]; // second digit
}
}

return result;
}

std::string URLFunctions::decode(const std::string& encodedUrl)
Expand Down

0 comments on commit d1851ae

Please sign in to comment.