Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
562bf712
Commit
562bf712
authored
5 years ago
by
Seva
Committed by
Adrien Béraud
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
http: handle url fragment
parent
5b344cad
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
include/opendht/http.h
+1
-0
1 addition, 0 deletions
include/opendht/http.h
src/http.cpp
+8
-2
8 additions, 2 deletions
src/http.cpp
tests/httptester.cpp
+16
-0
16 additions, 0 deletions
tests/httptester.cpp
tests/httptester.h
+2
-0
2 additions, 0 deletions
tests/httptester.h
with
27 additions
and
2 deletions
include/opendht/http.h
+
1
−
0
View file @
562bf712
...
@@ -68,6 +68,7 @@ public:
...
@@ -68,6 +68,7 @@ public:
std
::
string
service
{
"80"
};
std
::
string
service
{
"80"
};
std
::
string
target
{
"/"
};
std
::
string
target
{
"/"
};
std
::
string
query
;
std
::
string
query
;
std
::
string
fragment
;
};
};
class
OPENDHT_PUBLIC
Connection
class
OPENDHT_PUBLIC
Connection
...
...
This diff is collapsed.
Click to expand it.
src/http.cpp
+
8
−
2
View file @
562bf712
...
@@ -52,7 +52,7 @@ Url::Url(const std::string& url): url(url)
...
@@ -52,7 +52,7 @@ Url::Url(const std::string& url): url(url)
host
=
host_service
.
first
;
host
=
host_service
.
first
;
if
(
!
host_service
.
second
.
empty
())
if
(
!
host_service
.
second
.
empty
())
service
=
host_service
.
second
;
service
=
host_service
.
second
;
// target, query
// target, query
fragment
size_t
query_begin
=
url
.
find
(
"?"
);
size_t
query_begin
=
url
.
find
(
"?"
);
auto
addr_end
=
addr_begin
+
addr_size
;
auto
addr_end
=
addr_begin
+
addr_size
;
if
(
addr_end
<
url
.
size
()){
if
(
addr_end
<
url
.
size
()){
...
@@ -61,7 +61,13 @@ Url::Url(const std::string& url): url(url)
...
@@ -61,7 +61,13 @@ Url::Url(const std::string& url): url(url)
else
else
target
=
url
.
substr
(
addr_end
,
query_begin
-
addr_end
);
target
=
url
.
substr
(
addr_end
,
query_begin
-
addr_end
);
}
}
size_t
fragment_begin
=
url
.
find
(
"#"
);
if
(
fragment_begin
==
std
::
string
::
npos
)
query
=
url
.
substr
(
query_begin
+
1
);
query
=
url
.
substr
(
query_begin
+
1
);
else
{
query
=
url
.
substr
(
query_begin
+
1
,
fragment_begin
-
query_begin
-
1
);
fragment
=
url
.
substr
(
fragment_begin
);
}
}
}
// connection
// connection
...
...
This diff is collapsed.
Click to expand it.
tests/httptester.cpp
+
16
−
0
View file @
562bf712
...
@@ -96,6 +96,22 @@ HttpTester::test_parse_url_query() {
...
@@ -96,6 +96,22 @@ HttpTester::test_parse_url_query() {
CPPUNIT_ASSERT
(
parsed
.
query
==
"key=1"
);
CPPUNIT_ASSERT
(
parsed
.
query
==
"key=1"
);
}
}
void
HttpTester
::
test_parse_url_fragment
()
{
// Arrange
std
::
string
url
=
"http://google.com/?key=1#some-important-id"
;
// Act
dht
::
http
::
Url
parsed
(
url
);
// Assert
CPPUNIT_ASSERT
(
parsed
.
url
==
url
);
CPPUNIT_ASSERT
(
parsed
.
protocol
==
"http"
);
CPPUNIT_ASSERT
(
parsed
.
host
==
"google.com"
);
CPPUNIT_ASSERT
(
parsed
.
service
==
"80"
);
CPPUNIT_ASSERT
(
parsed
.
target
==
"/"
);
CPPUNIT_ASSERT
(
parsed
.
query
==
"key=1"
);
CPPUNIT_ASSERT
(
parsed
.
fragment
==
"#some-important-id"
);
}
void
void
HttpTester
::
test_parse_url_ipv4
()
{
HttpTester
::
test_parse_url_ipv4
()
{
// Arrange
// Arrange
...
...
This diff is collapsed.
Click to expand it.
tests/httptester.h
+
2
−
0
View file @
562bf712
...
@@ -34,6 +34,7 @@ class HttpTester : public CppUnit::TestFixture {
...
@@ -34,6 +34,7 @@ class HttpTester : public CppUnit::TestFixture {
CPPUNIT_TEST
(
test_parse_url_no_prefix_no_target
);
CPPUNIT_TEST
(
test_parse_url_no_prefix_no_target
);
CPPUNIT_TEST
(
test_parse_url_target
);
CPPUNIT_TEST
(
test_parse_url_target
);
CPPUNIT_TEST
(
test_parse_url_query
);
CPPUNIT_TEST
(
test_parse_url_query
);
CPPUNIT_TEST
(
test_parse_url_fragment
);
CPPUNIT_TEST
(
test_parse_url_ipv4
);
CPPUNIT_TEST
(
test_parse_url_ipv4
);
CPPUNIT_TEST
(
test_parse_url_no_prefix_no_target_ipv4
);
CPPUNIT_TEST
(
test_parse_url_no_prefix_no_target_ipv4
);
CPPUNIT_TEST
(
test_parse_url_target_ipv4
);
CPPUNIT_TEST
(
test_parse_url_target_ipv4
);
...
@@ -59,6 +60,7 @@ class HttpTester : public CppUnit::TestFixture {
...
@@ -59,6 +60,7 @@ class HttpTester : public CppUnit::TestFixture {
void
test_parse_url_no_prefix_no_target
();
void
test_parse_url_no_prefix_no_target
();
void
test_parse_url_target
();
void
test_parse_url_target
();
void
test_parse_url_query
();
void
test_parse_url_query
();
void
test_parse_url_fragment
();
/**
/**
* Test parse urls (ipv4)
* Test parse urls (ipv4)
*/
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment