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
4f07db8b
Commit
4f07db8b
authored
Jan 17, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
src: Rename our new string classes
parent
959d378f
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
61 additions
and
51 deletions
+61
-51
src/http2.h
src/http2.h
+1
-1
src/shrpx.cc
src/shrpx.cc
+4
-4
src/shrpx_client_handler.cc
src/shrpx_client_handler.cc
+4
-4
src/shrpx_config.cc
src/shrpx_config.cc
+2
-2
src/shrpx_config.h
src/shrpx_config.h
+3
-3
src/shrpx_http2_downstream_connection.cc
src/shrpx_http2_downstream_connection.cc
+1
-1
src/shrpx_http_downstream_connection.cc
src/shrpx_http_downstream_connection.cc
+2
-2
src/shrpx_log.cc
src/shrpx_log.cc
+1
-1
src/shrpx_log.h
src/shrpx_log.h
+5
-5
src/shrpx_ssl.cc
src/shrpx_ssl.cc
+2
-2
src/template.h
src/template.h
+36
-26
No files found.
src/http2.h
View file @
4f07db8b
...
...
@@ -152,7 +152,7 @@ nghttp2_nv make_nv_ls_nocopy(const char(&name)[N], const std::string &value) {
}
template
<
size_t
N
>
nghttp2_nv
make_nv_ls_nocopy
(
const
char
(
&
name
)[
N
],
const
String
Adaptor
&
value
)
{
nghttp2_nv
make_nv_ls_nocopy
(
const
char
(
&
name
)[
N
],
const
String
Ref
&
value
)
{
return
{(
uint8_t
*
)
name
,
(
uint8_t
*
)
value
.
c_str
(),
N
-
1
,
value
.
size
(),
NGHTTP2_NV_FLAG_NO_COPY_NAME
|
NGHTTP2_NV_FLAG_NO_COPY_VALUE
};
}
...
...
src/shrpx.cc
View file @
4f07db8b
...
...
@@ -2474,7 +2474,7 @@ int main(int argc, char **argv) {
if
(
get_config
()
->
downstream_addr_groups
.
empty
())
{
DownstreamAddr
addr
;
addr
.
host
=
VString
(
DEFAULT_DOWNSTREAM_HOST
);
addr
.
host
=
ImmutableString
::
from_lit
(
DEFAULT_DOWNSTREAM_HOST
);
addr
.
port
=
DEFAULT_DOWNSTREAM_PORT
;
DownstreamAddrGroup
g
(
"/"
);
...
...
@@ -2536,8 +2536,8 @@ int main(int argc, char **argv) {
// for AF_UNIX socket, we use "localhost" as host for backend
// hostport. This is used as Host header field to backend and
// not going to be passed to any syscalls.
addr
.
hostport
=
VString
(
util
::
make_hostport
(
"localhost"
,
get_config
()
->
port
));
addr
.
hostport
=
ImmutableString
(
util
::
make_hostport
(
"localhost"
,
get_config
()
->
port
));
auto
path
=
addr
.
host
.
c_str
();
auto
pathlen
=
addr
.
host
.
size
();
...
...
@@ -2560,7 +2560,7 @@ int main(int argc, char **argv) {
}
addr
.
hostport
=
V
String
(
util
::
make_hostport
(
addr
.
host
.
c_str
(),
addr
.
port
));
Immutable
String
(
util
::
make_hostport
(
addr
.
host
.
c_str
(),
addr
.
port
));
if
(
resolve_hostname
(
&
addr
.
addr
,
addr
.
host
.
c_str
(),
addr
.
port
,
...
...
src/shrpx_client_handler.cc
View file @
4f07db8b
...
...
@@ -843,8 +843,8 @@ void ClientHandler::write_accesslog(Downstream *downstream) {
?
construct_absolute_request_uri
(
req
)
:
req
.
path
.
empty
()
?
req
.
method
==
HTTP_OPTIONS
?
String
Adaptor
::
from_lit
(
"*"
)
:
String
Adaptor
::
from_lit
(
"-"
)
?
String
Ref
::
from_lit
(
"*"
)
:
String
Ref
::
from_lit
(
"-"
)
:
req
.
path
,
alpn_
,
nghttp2
::
ssl
::
get_tls_session_info
(
&
tls_info
,
conn_
.
tls
.
ssl
),
...
...
@@ -869,8 +869,8 @@ void ClientHandler::write_accesslog(int major, int minor, unsigned int status,
get_config
()
->
accesslog_format
,
LogSpec
{
nullptr
,
ipaddr_
,
String
Adaptor
::
from_lit
(
"-"
),
// method
String
Adaptor
::
from_lit
(
"-"
),
// path,
String
Ref
::
from_lit
(
"-"
),
// method
String
Ref
::
from_lit
(
"-"
),
// path,
alpn_
,
nghttp2
::
ssl
::
get_tls_session_info
(
&
tls_info
,
conn_
.
tls
.
ssl
),
time_now
,
highres_now
,
// request_start_time TODO is
...
...
src/shrpx_config.cc
View file @
4f07db8b
...
...
@@ -1393,7 +1393,7 @@ int parse_config(const char *opt, const char *optarg,
DownstreamAddr
addr
;
if
(
util
::
istarts_with
(
optarg
,
SHRPX_UNIX_PATH_PREFIX
))
{
auto
path
=
optarg
+
str_size
(
SHRPX_UNIX_PATH_PREFIX
);
addr
.
host
=
V
String
(
path
,
pat_delim
);
addr
.
host
=
Immutable
String
(
path
,
pat_delim
);
addr
.
host_unix
=
true
;
}
else
{
if
(
split_host_port
(
host
,
sizeof
(
host
),
&
port
,
optarg
,
...
...
@@ -1401,7 +1401,7 @@ int parse_config(const char *opt, const char *optarg,
return
-
1
;
}
addr
.
host
=
V
String
(
host
);
addr
.
host
=
Immutable
String
(
host
);
addr
.
port
=
port
;
}
...
...
src/shrpx_config.h
View file @
4f07db8b
...
...
@@ -245,8 +245,8 @@ struct DownstreamAddr {
Address
addr
;
// backend address. If |host_unix| is true, this is UNIX domain
// socket path.
V
String
host
;
V
String
hostport
;
Immutable
String
host
;
Immutable
String
hostport
;
// backend port. 0 if |host_unix| is true.
uint16_t
port
;
// true if |host| contains UNIX domain socket path.
...
...
@@ -311,7 +311,7 @@ struct Config {
// string is provided.
std
::
string
forwarded_for_obfuscated
;
std
::
string
backend_tls_sni_name
;
String
Adaptor
server_name
;
String
Ref
server_name
;
std
::
chrono
::
seconds
tls_session_timeout
;
ev_tstamp
http2_upstream_read_timeout
;
ev_tstamp
upstream_read_timeout
;
...
...
src/shrpx_http2_downstream_connection.cc
View file @
4f07db8b
...
...
@@ -269,7 +269,7 @@ int Http2DownstreamConnection::push_request_headers() {
// For HTTP/1.0 request, there is no authority in request. In that
// case, we use backend server's host nonetheless.
auto
authority
=
String
Adaptor
(
downstream_hostport
);
auto
authority
=
String
Ref
(
downstream_hostport
);
if
(
no_host_rewrite
&&
!
req
.
authority
.
empty
())
{
authority
=
req
.
authority
;
...
...
src/shrpx_http_downstream_connection.cc
View file @
4f07db8b
...
...
@@ -219,13 +219,13 @@ int HttpDownstreamConnection::push_request_headers() {
// For HTTP/1.0 request, there is no authority in request. In that
// case, we use backend server's host nonetheless.
auto
authority
=
String
Adaptor
(
downstream_hostport
);
auto
authority
=
String
Ref
(
downstream_hostport
);
auto
no_host_rewrite
=
get_config
()
->
no_host_rewrite
||
get_config
()
->
http2_proxy
||
get_config
()
->
client_proxy
||
connect_method
;
if
(
no_host_rewrite
&&
!
req
.
authority
.
empty
())
{
authority
=
String
Adaptor
(
req
.
authority
);
authority
=
String
Ref
(
req
.
authority
);
}
downstream_
->
set_request_downstream_host
(
authority
.
str
());
...
...
src/shrpx_log.cc
View file @
4f07db8b
...
...
@@ -184,7 +184,7 @@ std::pair<OutputIterator, size_t> copy(const std::string &src, size_t avail,
namespace
{
template
<
typename
OutputIterator
>
std
::
pair
<
OutputIterator
,
size_t
>
copy
(
const
String
Adaptor
&
src
,
size_t
avail
,
std
::
pair
<
OutputIterator
,
size_t
>
copy
(
const
String
Ref
&
src
,
size_t
avail
,
OutputIterator
oitr
)
{
return
copy
(
src
.
c_str
(),
src
.
size
(),
avail
,
oitr
);
}
...
...
src/shrpx_log.h
View file @
4f07db8b
...
...
@@ -142,10 +142,10 @@ struct LogFragment {
struct
LogSpec
{
Downstream
*
downstream
;
String
Adaptor
remote_addr
;
String
Adaptor
method
;
String
Adaptor
path
;
String
Adaptor
alpn
;
String
Ref
remote_addr
;
String
Ref
method
;
String
Ref
path
;
String
Ref
alpn
;
const
nghttp2
::
ssl
::
TLSSessionInfo
*
tls_info
;
std
::
chrono
::
system_clock
::
time_point
time_now
;
std
::
chrono
::
high_resolution_clock
::
time_point
request_start_time
;
...
...
@@ -153,7 +153,7 @@ struct LogSpec {
int
major
,
minor
;
unsigned
int
status
;
int64_t
body_bytes_sent
;
String
Adaptor
remote_port
;
String
Ref
remote_port
;
uint16_t
server_port
;
pid_t
pid
;
};
...
...
src/shrpx_ssl.cc
View file @
4f07db8b
...
...
@@ -972,8 +972,8 @@ int check_cert(SSL *ssl, const DownstreamAddr *addr) {
return
-
1
;
}
auto
hostname
=
!
get_config
()
->
backend_tls_sni_name
.
empty
()
?
String
Adaptor
(
get_config
()
->
backend_tls_sni_name
)
:
String
Adaptor
(
addr
->
host
);
?
String
Ref
(
get_config
()
->
backend_tls_sni_name
)
:
String
Ref
(
addr
->
host
);
if
(
verify_hostname
(
cert
,
hostname
.
c_str
(),
hostname
.
size
(),
&
addr
->
addr
)
!=
0
)
{
LOG
(
ERROR
)
<<
"Certificate verification failed: hostname does not match"
;
...
...
src/template.h
View file @
4f07db8b
...
...
@@ -211,22 +211,25 @@ inline std::unique_ptr<char[]> strcopy(const std::unique_ptr<char[]> &val,
return
strcopy
(
val
.
get
(),
val
.
get
()
+
n
);
}
// VString represents string. It has c_str() and size() functions to
// mimic std::string. It manages buffer by itself. Just like
// std::string, c_str() returns NULL-terminated string, but NULL
// character may appear before the final terminal NULL.
struct
VString
{
VString
()
:
len
(
0
)
{}
VString
(
const
char
*
s
,
size_t
slen
)
:
len
(
slen
),
base
(
strcopy
(
s
,
len
))
{}
VString
(
const
char
*
s
)
:
len
(
strlen
(
s
)),
base
(
strcopy
(
s
,
len
))
{}
VString
(
const
std
::
string
&
s
)
:
len
(
s
.
size
()),
base
(
strcopy
(
s
))
{}
// ImmutableString represents string that is immutable unlike
// std::string. It has c_str() and size() functions to mimic
// std::string. It manages buffer by itself. Just like std::string,
// c_str() returns NULL-terminated string, but NULL character may
// appear before the final terminal NULL.
class
ImmutableString
{
public:
ImmutableString
()
:
len
(
0
)
{}
ImmutableString
(
const
char
*
s
,
size_t
slen
)
:
len
(
slen
),
base
(
strcopy
(
s
,
len
))
{}
ImmutableString
(
const
char
*
s
)
:
len
(
strlen
(
s
)),
base
(
strcopy
(
s
,
len
))
{}
ImmutableString
(
const
std
::
string
&
s
)
:
len
(
s
.
size
()),
base
(
strcopy
(
s
))
{}
template
<
typename
InputIt
>
V
String
(
InputIt
first
,
InputIt
last
)
Immutable
String
(
InputIt
first
,
InputIt
last
)
:
len
(
std
::
distance
(
first
,
last
)),
base
(
strcopy
(
first
,
last
))
{}
VString
(
const
V
String
&
other
)
ImmutableString
(
const
Immutable
String
&
other
)
:
len
(
other
.
len
),
base
(
strcopy
(
other
.
base
,
other
.
len
))
{}
VString
(
V
String
&&
)
=
default
;
VString
&
operator
=
(
const
V
String
&
other
)
{
ImmutableString
(
Immutable
String
&&
)
=
default
;
ImmutableString
&
operator
=
(
const
Immutable
String
&
other
)
{
if
(
this
==
&
other
)
{
return
*
this
;
}
...
...
@@ -234,30 +237,36 @@ struct VString {
base
=
strcopy
(
other
.
base
,
other
.
len
);
return
*
this
;
}
VString
&
operator
=
(
VString
&&
other
)
=
default
;
ImmutableString
&
operator
=
(
ImmutableString
&&
other
)
=
default
;
template
<
size_t
N
>
static
ImmutableString
from_lit
(
const
char
(
&
s
)[
N
])
{
return
ImmutableString
(
s
,
N
-
1
);
}
const
char
*
c_str
()
const
{
return
base
.
get
();
}
size_t
size
()
const
{
return
len
;
}
private:
size_t
len
;
std
::
unique_ptr
<
char
[]
>
base
;
};
// StringAdaptor behaves like simple string, but it does not own
// pointer. When it is default constructed, it has empty string. You
// can freely copy or move around this struct, but never free its
// pointer. str() function can be used to export the content as
// std::string.
struct
StringAdaptor
{
StringAdaptor
()
:
base
(
""
),
len
(
0
)
{}
// StringRef is a reference to a string owned by something else. So
// it behaves like simple string, but it does not own pointer. When
// it is default constructed, it has empty string. You can freely
// copy or move around this struct, but never free its pointer. str()
// function can be used to export the content as std::string.
class
StringRef
{
public:
StringRef
()
:
base
(
""
),
len
(
0
)
{}
template
<
typename
T
>
String
Adaptor
(
const
T
&
s
)
String
Ref
(
const
T
&
s
)
:
base
(
s
.
c_str
()),
len
(
s
.
size
())
{}
String
Adaptor
(
const
char
*
s
)
:
base
(
s
),
len
(
strlen
(
s
))
{}
String
Adaptor
(
const
char
*
s
,
size_t
n
)
:
base
(
s
),
len
(
n
)
{}
String
Ref
(
const
char
*
s
)
:
base
(
s
),
len
(
strlen
(
s
))
{}
String
Ref
(
const
char
*
s
,
size_t
n
)
:
base
(
s
),
len
(
n
)
{}
template
<
size_t
N
>
static
String
Adaptor
from_lit
(
const
char
(
&
s
)[
N
])
{
return
String
Adaptor
(
s
,
N
-
1
);
template
<
size_t
N
>
static
String
Ref
from_lit
(
const
char
(
&
s
)[
N
])
{
return
String
Ref
(
s
,
N
-
1
);
}
const
char
*
c_str
()
const
{
return
base
;
}
...
...
@@ -265,6 +274,7 @@ struct StringAdaptor {
std
::
string
str
()
const
{
return
std
::
string
(
base
,
len
);
}
private:
const
char
*
base
;
size_t
len
;
};
...
...
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