ben-zen / uri-library Goto Github PK
View Code? Open in Web Editor NEWA Modern C++ URI library.
A Modern C++ URI library.
Compiling with g++ g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
src/uri.hh: In constructor ‘uri::uri(const char*, uri::scheme_category, uri::query_argument_separator)’:
src/uri.hh:655:8: warning: ‘uri::m_path_is_rooted’ will be initialized after [-Wreorder]
655 | bool m_path_is_rooted;
| ^~~~~~~~~~~~~~~~
src/uri.hh:654:17: warning: ‘long unsigned int uri::m_port’ [-Wreorder]
654 | unsigned long m_port;
| ^~~~~~
src/uri.hh:54:3: warning: when initialized here [-Wreorder]
54 | uri(char const *uri_text, scheme_category category = scheme_category::Hierarchical,
| ^~~
src/uri.hh: In constructor ‘uri::uri(const string&, uri::scheme_category, uri::query_argument_separator)’:
src/uri.hh:655:8: warning: ‘uri::m_path_is_rooted’ will be initialized after [-Wreorder]
655 | bool m_path_is_rooted;
| ^~~~~~~~~~~~~~~~
src/uri.hh:654:17: warning: ‘long unsigned int uri::m_port’ [-Wreorder]
654 | unsigned long m_port;
| ^~~~~~
src/uri.hh:64:3: warning: when initialized here [-Wreorder]
64 | uri(std::string const &uri_text, scheme_category category = scheme_category::Hierarchical,
| ^~~
I need to parse URIs which contain arbitrary characters in the query value. To be able to do this the URI library needs to be able to decode the percent-encoded value string.
Here is an example : http://a/b/?q1=question-mark%3f&q2=ampersand%26
The query parameters of this URI should result in these decoded parameter-name parameter-value pairs:
q1=question-mark?
q2=ampersand&
This project should actually use GTest for really testing the code.
How to keep uri after try-catch without empty constructor?
uri request;
try {
request = uri(std::string(buf));
auto requestParams = request.get_query_dictionary();
} catch (std::invalid_argument &e) {
...
}
request.get_path();
Following example is not working, I don't want to wrap whole logic into try-catch...
When attempting to parse: https://test.com:443
#include "uri.hh"
#include <iostream>
int main(int argc, char ** argv)
{
uri test_uri("https://test.com:443");
auto t = test_uri.to_string();
cout << "server: " << test_uri.get_host() << " post: " << test_uri.get_port() << " new_url: " << test_uri.get_path() << " - " << t << std::endl;
return 0;
}
The host and port are correctly set. However the m_path
is not correctly set. It is set to //test.com:443
You can mitigate this issue by appending /
to the url (e.g. https://test.com:443/
). However the a uri should be parsed correctly without a path.
Test.cc fails with the above message when it is compiled with:
cl /MDd /D_ITERATOR_DEBUG_LEVEL=1 test.cc
The failing test is this one:
uri no_host("file:/example.txt");
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.