Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
755b14de
Commit
755b14de
authored
Mar 12, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src: Unify path_join implementation
parent
3455cb35
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
124 deletions
+3
-124
src/http2.cc
src/http2.cc
+3
-124
No files found.
src/http2.cc
View file @
755b14de
...
@@ -1198,132 +1198,11 @@ std::vector<LinkHeader> parse_link_header(const char *src, size_t len) {
...
@@ -1198,132 +1198,11 @@ std::vector<LinkHeader> parse_link_header(const char *src, size_t len) {
return
res
;
return
res
;
}
}
namespace
{
void
eat_file
(
std
::
string
&
path
)
{
if
(
path
.
empty
())
{
path
=
"/"
;
return
;
}
auto
p
=
path
.
size
()
-
1
;
if
(
path
[
p
]
==
'/'
)
{
return
;
}
p
=
path
.
rfind
(
'/'
,
p
);
if
(
p
==
std
::
string
::
npos
)
{
// this should not happend in normal case, where we expect path
// starts with '/'
path
=
"/"
;
return
;
}
path
.
erase
(
std
::
begin
(
path
)
+
p
+
1
,
std
::
end
(
path
));
}
}
// namespace
namespace
{
void
eat_dir
(
std
::
string
&
path
)
{
if
(
path
.
empty
())
{
path
=
"/"
;
return
;
}
auto
p
=
path
.
size
()
-
1
;
if
(
path
[
p
]
!=
'/'
)
{
p
=
path
.
rfind
(
'/'
,
p
);
if
(
p
==
std
::
string
::
npos
)
{
// this should not happend in normal case, where we expect path
// starts with '/'
path
=
"/"
;
return
;
}
}
if
(
path
[
p
]
==
'/'
)
{
if
(
p
==
0
)
{
return
;
}
--
p
;
}
p
=
path
.
rfind
(
'/'
,
p
);
if
(
p
==
std
::
string
::
npos
)
{
// this should not happend in normal case, where we expect path
// starts with '/'
path
=
"/"
;
return
;
}
path
.
erase
(
std
::
begin
(
path
)
+
p
+
1
,
std
::
end
(
path
));
}
}
// namespace
std
::
string
path_join
(
const
StringRef
&
base_path
,
const
StringRef
&
base_query
,
std
::
string
path_join
(
const
StringRef
&
base_path
,
const
StringRef
&
base_query
,
const
StringRef
&
rel_path
,
const
StringRef
&
rel_query
)
{
const
StringRef
&
rel_path
,
const
StringRef
&
rel_query
)
{
std
::
string
res
;
BlockAllocator
balloc
(
1024
,
1024
);
if
(
rel_path
.
empty
())
{
if
(
base_path
.
empty
())
{
res
=
"/"
;
}
else
{
res
.
assign
(
std
::
begin
(
base_path
),
std
::
end
(
base_path
));
}
if
(
rel_query
.
empty
())
{
if
(
!
base_query
.
empty
())
{
res
+=
'?'
;
res
.
append
(
std
::
begin
(
base_query
),
std
::
end
(
base_query
));
}
return
res
;
}
res
+=
'?'
;
res
.
append
(
std
::
begin
(
rel_query
),
std
::
end
(
rel_query
));
return
res
;
}
auto
first
=
std
::
begin
(
rel_path
);
auto
last
=
std
::
end
(
rel_path
);
if
(
rel_path
[
0
]
==
'/'
)
{
res
=
"/"
;
++
first
;
}
else
if
(
base_path
.
empty
())
{
res
=
"/"
;
}
else
{
res
.
assign
(
std
::
begin
(
base_path
),
std
::
end
(
base_path
));
}
for
(;
first
!=
last
;)
{
return
path_join
(
balloc
,
base_path
,
base_query
,
rel_path
,
rel_query
).
str
();
if
(
*
first
==
'.'
)
{
if
(
first
+
1
==
last
)
{
break
;
}
if
(
*
(
first
+
1
)
==
'/'
)
{
first
+=
2
;
continue
;
}
if
(
*
(
first
+
1
)
==
'.'
)
{
if
(
first
+
2
==
last
)
{
eat_dir
(
res
);
break
;
}
if
(
*
(
first
+
2
)
==
'/'
)
{
eat_dir
(
res
);
first
+=
3
;
continue
;
}
}
}
if
(
res
.
back
()
!=
'/'
)
{
eat_file
(
res
);
}
auto
slash
=
std
::
find
(
first
,
last
,
'/'
);
if
(
slash
==
last
)
{
res
.
append
(
first
,
last
);
break
;
}
res
.
append
(
first
,
slash
+
1
);
first
=
slash
+
1
;
for
(;
first
!=
last
&&
*
first
==
'/'
;
++
first
)
;
}
if
(
!
rel_query
.
empty
())
{
res
+=
'?'
;
res
.
append
(
std
::
begin
(
rel_query
),
std
::
end
(
rel_query
));
}
return
res
;
}
}
bool
expect_response_body
(
int
status_code
)
{
bool
expect_response_body
(
int
status_code
)
{
...
@@ -1729,7 +1608,7 @@ StringRef path_join(BlockAllocator &balloc, const StringRef &base_path,
...
@@ -1729,7 +1608,7 @@ StringRef path_join(BlockAllocator &balloc, const StringRef &base_path,
StringRef
normalize_path
(
BlockAllocator
&
balloc
,
const
StringRef
&
path
,
StringRef
normalize_path
(
BlockAllocator
&
balloc
,
const
StringRef
&
path
,
const
StringRef
&
query
)
{
const
StringRef
&
query
)
{
// First, decode %XX for unreserved characters, then do
// First, decode %XX for unreserved characters, then do
// http2::
join_path
// http2::
path_join
// We won't find %XX if length is less than 3.
// We won't find %XX if length is less than 3.
if
(
path
.
size
()
<
3
||
if
(
path
.
size
()
<
3
||
...
...
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