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
e0d7f7de
Commit
e0d7f7de
authored
Dec 21, 2019
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
h2load: Allow port in --connect-to
parent
df575f96
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
89 additions
and
6 deletions
+89
-6
src/h2load.cc
src/h2load.cc
+19
-6
src/h2load.h
src/h2load.h
+1
-0
src/shrpx-unittest.cc
src/shrpx-unittest.cc
+2
-0
src/util.cc
src/util.cc
+35
-0
src/util.h
src/util.h
+7
-0
src/util_test.cc
src/util_test.cc
+24
-0
src/util_test.h
src/util_test.h
+1
-0
No files found.
src/h2load.cc
View file @
e0d7f7de
...
...
@@ -94,6 +94,7 @@ Config::Config()
log_fd
(
-
1
),
port
(
0
),
default_port
(
0
),
connect_to_port
(
0
),
verbose
(
false
),
timing_script
(
false
),
base_uri_unix
(
false
),
...
...
@@ -1565,9 +1566,11 @@ void resolve_host() {
const
auto
&
resolve_host
=
config
.
connect_to_host
.
empty
()
?
config
.
host
:
config
.
connect_to_host
;
auto
port
=
config
.
connect_to_port
==
0
?
config
.
port
:
config
.
connect_to_port
;
rv
=
getaddrinfo
(
resolve_host
.
c_str
(),
util
::
utos
(
config
.
port
).
c_str
(),
&
hints
,
&
res
);
rv
=
getaddrinfo
(
resolve_host
.
c_str
(),
util
::
utos
(
port
).
c_str
(),
&
hints
,
&
res
);
if
(
rv
!=
0
)
{
std
::
cerr
<<
"getaddrinfo() failed: "
<<
gai_strerror
(
rv
)
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
...
...
@@ -1982,8 +1985,9 @@ Options:
response time when using one worker thread, but may
appear slightly out of order with multiple threads due
to buffering. Status code is -1 for failed streams.
--connect-to=<HOST>
Host to connect instead of using the host in <URI>.
--connect-to=<HOST>[:<PORT>]
Host and port to connect instead of using the authority
in <URI>.
-v, --verbose
Output debug information.
--version Display version information and exit.
...
...
@@ -2270,11 +2274,20 @@ int main(int argc, char **argv) {
// --log-file
logfile
=
optarg
;
break
;
case
11
:
case
11
:
{
// --connect-to
config
.
connect_to_host
=
optarg
;
auto
p
=
util
::
split_hostport
(
StringRef
{
optarg
});
int64_t
port
=
0
;
if
(
p
.
first
.
empty
()
||
(
!
p
.
second
.
empty
()
&&
(
port
=
util
::
parse_uint
(
p
.
second
))
==
-
1
))
{
std
::
cerr
<<
"--connect-to: Invalid value "
<<
optarg
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
config
.
connect_to_host
=
p
.
first
.
str
();
config
.
connect_to_port
=
port
;
break
;
}
}
break
;
default:
break
;
...
...
src/h2load.h
View file @
e0d7f7de
...
...
@@ -102,6 +102,7 @@ struct Config {
int
log_fd
;
uint16_t
port
;
uint16_t
default_port
;
uint16_t
connect_to_port
;
bool
verbose
;
bool
timing_script
;
std
::
string
base_uri
;
...
...
src/shrpx-unittest.cc
View file @
e0d7f7de
...
...
@@ -195,6 +195,8 @@ int main(int argc, char *argv[]) {
!
CU_add_test
(
pSuite
,
"util_decode_hex"
,
shrpx
::
test_util_decode_hex
)
||
!
CU_add_test
(
pSuite
,
"util_extract_host"
,
shrpx
::
test_util_extract_host
)
||
!
CU_add_test
(
pSuite
,
"util_split_hostport"
,
shrpx
::
test_util_split_hostport
)
||
!
CU_add_test
(
pSuite
,
"gzip_inflate"
,
test_nghttp2_gzip_inflate
)
||
!
CU_add_test
(
pSuite
,
"buffer_write"
,
nghttp2
::
test_buffer_write
)
||
!
CU_add_test
(
pSuite
,
"pool_recycle"
,
nghttp2
::
test_pool_recycle
)
||
...
...
src/util.cc
View file @
e0d7f7de
...
...
@@ -1537,6 +1537,41 @@ StringRef extract_host(const StringRef &hostport) {
return
StringRef
{
std
::
begin
(
hostport
),
p
};
}
std
::
pair
<
StringRef
,
StringRef
>
split_hostport
(
const
StringRef
&
hostport
)
{
if
(
hostport
.
empty
())
{
return
{};
}
if
(
hostport
[
0
]
==
'['
)
{
// assume this is IPv6 numeric address
auto
p
=
std
::
find
(
std
::
begin
(
hostport
),
std
::
end
(
hostport
),
']'
);
if
(
p
==
std
::
end
(
hostport
))
{
return
{};
}
if
(
p
+
1
==
std
::
end
(
hostport
))
{
return
{
StringRef
{
std
::
begin
(
hostport
)
+
1
,
p
},
{}};
}
if
(
*
(
p
+
1
)
!=
':'
||
p
+
2
==
std
::
end
(
hostport
))
{
return
{};
}
return
{
StringRef
{
std
::
begin
(
hostport
)
+
1
,
p
},
StringRef
{
p
+
2
,
std
::
end
(
hostport
)}};
}
auto
p
=
std
::
find
(
std
::
begin
(
hostport
),
std
::
end
(
hostport
),
':'
);
if
(
p
==
std
::
begin
(
hostport
))
{
return
{};
}
if
(
p
==
std
::
end
(
hostport
))
{
return
{
StringRef
{
std
::
begin
(
hostport
),
p
},
{}};
}
if
(
p
+
1
==
std
::
end
(
hostport
))
{
return
{};
}
return
{
StringRef
{
std
::
begin
(
hostport
),
p
},
StringRef
{
p
+
1
,
std
::
end
(
hostport
)}};
}
std
::
mt19937
make_mt19937
()
{
std
::
random_device
rd
;
return
std
::
mt19937
(
rd
());
...
...
src/util.h
View file @
e0d7f7de
...
...
@@ -769,6 +769,13 @@ int sha1(uint8_t *buf, const StringRef &s);
// NULL-terminated.
StringRef
extract_host
(
const
StringRef
&
hostport
);
// split_hostport splits host and port in |hostport|. Unlike
// extract_host, square brackets enclosing host name is stripped. If
// port is not available, it returns empty string in the second
// string. The returned string might not be NULL-terminated. On any
// error, it returns a pair which has empty strings.
std
::
pair
<
StringRef
,
StringRef
>
split_hostport
(
const
StringRef
&
hostport
);
// Returns new std::mt19937 object.
std
::
mt19937
make_mt19937
();
...
...
src/util_test.cc
View file @
e0d7f7de
...
...
@@ -628,4 +628,28 @@ void test_util_extract_host(void) {
CU_ASSERT
(
util
::
extract_host
(
StringRef
{}).
empty
());
}
void
test_util_split_hostport
(
void
)
{
CU_ASSERT
(
std
::
make_pair
(
StringRef
::
from_lit
(
"foo"
),
StringRef
{})
==
util
::
split_hostport
(
StringRef
::
from_lit
(
"foo"
)));
CU_ASSERT
(
std
::
make_pair
(
StringRef
::
from_lit
(
"foo"
),
StringRef
::
from_lit
(
"80"
))
==
util
::
split_hostport
(
StringRef
::
from_lit
(
"foo:80"
)));
CU_ASSERT
(
std
::
make_pair
(
StringRef
::
from_lit
(
"::1"
),
StringRef
::
from_lit
(
"80"
))
==
util
::
split_hostport
(
StringRef
::
from_lit
(
"[::1]:80"
)));
CU_ASSERT
(
std
::
make_pair
(
StringRef
::
from_lit
(
"::1"
),
StringRef
{})
==
util
::
split_hostport
(
StringRef
::
from_lit
(
"[::1]"
)));
CU_ASSERT
(
std
::
make_pair
(
StringRef
{},
StringRef
{})
==
util
::
split_hostport
(
StringRef
{}));
CU_ASSERT
(
std
::
make_pair
(
StringRef
{},
StringRef
{})
==
util
::
split_hostport
(
StringRef
::
from_lit
(
"[::1]:"
)));
CU_ASSERT
(
std
::
make_pair
(
StringRef
{},
StringRef
{})
==
util
::
split_hostport
(
StringRef
::
from_lit
(
"foo:"
)));
CU_ASSERT
(
std
::
make_pair
(
StringRef
{},
StringRef
{})
==
util
::
split_hostport
(
StringRef
::
from_lit
(
"[::1:"
)));
CU_ASSERT
(
std
::
make_pair
(
StringRef
{},
StringRef
{})
==
util
::
split_hostport
(
StringRef
::
from_lit
(
"[::1]80"
)));
}
}
// namespace shrpx
src/util_test.h
View file @
e0d7f7de
...
...
@@ -67,6 +67,7 @@ void test_util_format_hex(void);
void
test_util_is_hex_string
(
void
);
void
test_util_decode_hex
(
void
);
void
test_util_extract_host
(
void
);
void
test_util_split_hostport
(
void
);
}
// namespace shrpx
...
...
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