Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
ccef65a7
Commit
ccef65a7
authored
Jun 01, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add comments to URL lib.
parent
a833fd79
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
11 deletions
+20
-11
url-test.c++
c++/src/kj/compat/url-test.c++
+3
-2
url.c++
c++/src/kj/compat/url.c++
+4
-4
url.h
c++/src/kj/compat/url.h
+13
-5
No files found.
c++/src/kj/compat/url-test.c++
View file @
ccef65a7
...
...
@@ -272,14 +272,15 @@ KJ_TEST("URL relative paths") {
KJ_TEST
(
"URL for HTTP request"
)
{
{
Url
url
=
Url
::
parse
(
"https://bob:1234@capnproto.org/foo/bar?baz=qux#corge"
);
KJ_EXPECT
(
url
.
toString
(
Url
::
GENERAL
)
==
"https://bob:1234@capnproto.org/foo/bar?baz=qux#corge"
);
KJ_EXPECT
(
url
.
toString
(
Url
::
REMOTE_HREF
)
==
"https://bob:1234@capnproto.org/foo/bar?baz=qux#corge"
);
KJ_EXPECT
(
url
.
toString
(
Url
::
HTTP_PROXY_REQUEST
)
==
"https://capnproto.org/foo/bar?baz=qux"
);
KJ_EXPECT
(
url
.
toString
(
Url
::
HTTP_REQUEST
)
==
"/foo/bar?baz=qux"
);
}
{
Url
url
=
Url
::
parse
(
"https://capnproto.org"
);
KJ_EXPECT
(
url
.
toString
(
Url
::
GENERAL
)
==
"https://capnproto.org"
);
KJ_EXPECT
(
url
.
toString
(
Url
::
REMOTE_HREF
)
==
"https://capnproto.org"
);
KJ_EXPECT
(
url
.
toString
(
Url
::
HTTP_PROXY_REQUEST
)
==
"https://capnproto.org"
);
KJ_EXPECT
(
url
.
toString
(
Url
::
HTTP_REQUEST
)
==
"/"
);
}
...
...
c++/src/kj/compat/url.c++
View file @
ccef65a7
...
...
@@ -148,7 +148,7 @@ Maybe<Url> Url::tryParse(StringPtr text, Context context) {
auto
authority
=
split
(
text
,
END_AUTHORITY
);
KJ_IF_MAYBE
(
userpass
,
trySplit
(
authority
,
'@'
))
{
if
(
context
!=
GENERAL
)
{
if
(
context
!=
REMOTE_HREF
)
{
// No user/pass allowed here.
return
nullptr
;
}
...
...
@@ -210,7 +210,7 @@ Maybe<Url> Url::tryParse(StringPtr text, Context context) {
}
if
(
text
.
startsWith
(
"#"
))
{
if
(
context
!=
GENERAL
)
{
if
(
context
!=
REMOTE_HREF
)
{
// No fragment allowed here.
return
nullptr
;
}
...
...
@@ -376,7 +376,7 @@ String Url::toString(Context context) const {
chars
.
addAll
(
scheme
);
chars
.
addAll
(
StringPtr
(
"://"
));
if
(
context
==
GENERAL
)
{
if
(
context
==
REMOTE_HREF
)
{
KJ_IF_MAYBE
(
user
,
userInfo
)
{
chars
.
addAll
(
encodeUriComponent
(
user
->
username
));
KJ_IF_MAYBE
(
pass
,
user
->
password
)
{
...
...
@@ -422,7 +422,7 @@ String Url::toString(Context context) const {
}
}
if
(
context
==
GENERAL
)
{
if
(
context
==
REMOTE_HREF
)
{
KJ_IF_MAYBE
(
f
,
fragment
)
{
chars
.
add
(
'#'
);
chars
.
addAll
(
encodeUriComponent
(
*
f
));
...
...
c++/src/kj/compat/url.h
View file @
ccef65a7
...
...
@@ -28,6 +28,10 @@
namespace
kj
{
struct
Url
{
// Represents a URL (or, more accurately, a URI, but whatever).
//
// Can be parsed from a string and composed back into a string.
String
scheme
;
// E.g. "http", "https".
...
...
@@ -69,8 +73,9 @@ struct Url {
Url
clone
()
const
;
enum
Context
{
GENERAL
,
// The full URL.
REMOTE_HREF
,
// A link to a remote resource. Requires an authority (hostname) section, hence this will
// reject things like "mailto:" and "data:". This is the default context.
HTTP_PROXY_REQUEST
,
// The URL to place in the first line of an HTTP proxy request. This includes scheme, host,
...
...
@@ -80,13 +85,16 @@ struct Url {
HTTP_REQUEST
// The path to place in the first line of a regular HTTP request. This includes only the path
// and query. Scheme, user, host, and fragment are omitted.
// TODO(someday): Add context(s) that supports things like "mailto:", "data:", "blob:". These
// don't have an authority section.
};
kj
::
String
toString
(
Context
context
=
GENERAL
)
const
;
kj
::
String
toString
(
Context
context
=
REMOTE_HREF
)
const
;
// Convert the URL to a string.
static
Url
parse
(
StringPtr
text
,
Context
context
=
GENERAL
);
static
Maybe
<
Url
>
tryParse
(
StringPtr
text
,
Context
context
=
GENERAL
);
static
Url
parse
(
StringPtr
text
,
Context
context
=
REMOTE_HREF
);
static
Maybe
<
Url
>
tryParse
(
StringPtr
text
,
Context
context
=
REMOTE_HREF
);
// Parse an absolute URL.
Url
parseRelative
(
StringPtr
relative
)
const
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment