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
fc2170e4
Commit
fc2170e4
authored
Mar 04, 2015
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asio: Use uri_ref in server code
parent
0cda2282
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
83 deletions
+36
-83
examples/asio-sv2.cc
examples/asio-sv2.cc
+1
-1
src/asio_http2_handler.cc
src/asio_http2_handler.cc
+20
-49
src/asio_http2_handler.h
src/asio_http2_handler.h
+11
-18
src/includes/nghttp2/asio_http2_server.h
src/includes/nghttp2/asio_http2_server.h
+4
-15
No files found.
examples/asio-sv2.cc
View file @
fc2170e4
...
...
@@ -68,7 +68,7 @@ int main(int argc, char *argv[]) {
server
.
listen
(
"*"
,
port
,
[
&
docroot
](
const
request
&
req
,
const
response
&
res
)
{
auto
path
=
percent_decode
(
req
.
path
()
);
auto
path
=
percent_decode
(
req
.
uri
().
path
);
if
(
!
check_path
(
path
))
{
res
.
write_head
(
404
);
res
.
end
();
...
...
src/asio_http2_handler.cc
View file @
fc2170e4
...
...
@@ -45,13 +45,7 @@ const header_map &request::header() const { return impl_->header(); }
const
std
::
string
&
request
::
method
()
const
{
return
impl_
->
method
();
}
const
std
::
string
&
request
::
scheme
()
const
{
return
impl_
->
scheme
();
}
const
std
::
string
&
request
::
authority
()
const
{
return
impl_
->
authority
();
}
const
std
::
string
&
request
::
host
()
const
{
return
impl_
->
host
();
}
const
std
::
string
&
request
::
path
()
const
{
return
impl_
->
path
();
}
const
uri_ref
&
request
::
uri
()
const
{
return
impl_
->
uri
();
}
bool
request
::
push
(
std
::
string
method
,
std
::
string
path
,
header_map
h
)
const
{
return
impl_
->
push
(
std
::
move
(
method
),
std
::
move
(
path
),
std
::
move
(
h
));
...
...
@@ -91,13 +85,9 @@ const header_map &request_impl::header() const { return header_; }
const
std
::
string
&
request_impl
::
method
()
const
{
return
method_
;
}
const
std
::
string
&
request_impl
::
scheme
()
const
{
return
scheme_
;
}
const
std
::
string
&
request_impl
::
authority
()
const
{
return
authority_
;
}
const
std
::
string
&
request_impl
::
host
()
const
{
return
host_
;
}
const
uri_ref
&
request_impl
::
uri
()
const
{
return
uri_
;
}
const
std
::
string
&
request_impl
::
path
()
const
{
return
path
_
;
}
uri_ref
&
request_impl
::
uri
()
{
return
uri
_
;
}
void
request_impl
::
header
(
header_map
h
)
{
header_
=
std
::
move
(
h
);
}
...
...
@@ -105,14 +95,6 @@ header_map &request_impl::header() { return header_; }
void
request_impl
::
method
(
std
::
string
arg
)
{
method_
=
std
::
move
(
arg
);
}
void
request_impl
::
scheme
(
std
::
string
arg
)
{
scheme_
=
std
::
move
(
arg
);
}
void
request_impl
::
authority
(
std
::
string
arg
)
{
authority_
=
std
::
move
(
arg
);
}
void
request_impl
::
host
(
std
::
string
arg
)
{
host_
=
std
::
move
(
arg
);
}
void
request_impl
::
path
(
std
::
string
arg
)
{
path_
=
std
::
move
(
arg
);
}
bool
request_impl
::
push
(
std
::
string
method
,
std
::
string
path
,
header_map
h
)
{
auto
handler
=
stream_
->
handler
();
auto
rv
=
handler
->
push_promise
(
*
stream_
,
std
::
move
(
method
),
std
::
move
(
path
),
...
...
@@ -261,22 +243,25 @@ int on_header_callback(nghttp2_session *session, const nghttp2_frame *frame,
}
auto
&
req
=
stream
->
request
().
impl
();
auto
&
uref
=
req
.
uri
();
switch
(
nghttp2
::
http2
::
lookup_token
(
name
,
namelen
))
{
case
nghttp2
:
:
http2
::
HD__METHOD
:
req
.
method
(
std
::
string
(
value
,
value
+
valuelen
));
break
;
case
nghttp2
:
:
http2
::
HD__SCHEME
:
req
.
scheme
(
std
::
string
(
value
,
value
+
valuelen
)
);
uref
.
scheme
.
assign
(
value
,
value
+
valuelen
);
break
;
case
nghttp2
:
:
http2
::
HD__AUTHORITY
:
req
.
authority
(
std
::
string
(
value
,
value
+
valuelen
)
);
uref
.
host
.
assign
(
value
,
value
+
valuelen
);
break
;
case
nghttp2
:
:
http2
::
HD__PATH
:
req
.
path
(
std
::
string
(
value
,
value
+
valuelen
)
);
split_path
(
uref
,
value
,
value
+
valuelen
);
break
;
case
nghttp2
:
:
http2
::
HD_HOST
:
req
.
host
(
std
::
string
(
value
,
value
+
valuelen
));
if
(
uref
.
host
.
empty
())
{
uref
.
host
.
assign
(
value
,
value
+
valuelen
);
}
// fall through
default:
req
.
header
().
emplace
(
std
::
string
(
name
,
name
+
namelen
),
...
...
@@ -310,12 +295,6 @@ int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame,
break
;
}
auto
&
req
=
stream
->
request
().
impl
();
if
(
req
.
host
().
empty
())
{
req
.
host
(
req
.
authority
());
}
handler
->
call_on_request
(
*
stream
);
if
(
frame
->
hd
.
flags
&
NGHTTP2_FLAG_END_STREAM
)
{
...
...
@@ -549,22 +528,17 @@ void http2_handler::resume(http2_stream &stream) {
}
int
http2_handler
::
push_promise
(
http2_stream
&
stream
,
std
::
string
method
,
std
::
string
path
,
header_map
h
)
{
std
::
string
raw_path_query
,
header_map
h
)
{
int
rv
;
auto
&
req
=
stream
.
request
().
impl
();
auto
nva
=
std
::
vector
<
nghttp2_nv
>
();
nva
.
reserve
(
5
+
h
.
size
());
nva
.
reserve
(
4
+
h
.
size
());
nva
.
push_back
(
nghttp2
::
http2
::
make_nv_ls
(
":method"
,
method
));
nva
.
push_back
(
nghttp2
::
http2
::
make_nv_ls
(
":scheme"
,
req
.
scheme
()));
if
(
!
req
.
authority
().
empty
())
{
nva
.
push_back
(
nghttp2
::
http2
::
make_nv_ls
(
":authority"
,
req
.
authority
()));
}
nva
.
push_back
(
nghttp2
::
http2
::
make_nv_ls
(
":path"
,
path
));
if
(
!
req
.
host
().
empty
())
{
nva
.
push_back
(
nghttp2
::
http2
::
make_nv_ls
(
"host"
,
req
.
host
()));
}
nva
.
push_back
(
nghttp2
::
http2
::
make_nv_ls
(
":scheme"
,
req
.
uri
().
scheme
));
nva
.
push_back
(
nghttp2
::
http2
::
make_nv_ls
(
":authority"
,
req
.
uri
().
host
));
nva
.
push_back
(
nghttp2
::
http2
::
make_nv_ls
(
":path"
,
raw_path_query
));
for
(
auto
&
hd
:
h
)
{
nva
.
push_back
(
nghttp2
::
http2
::
make_nv
(
hd
.
first
,
hd
.
second
.
value
,
...
...
@@ -582,15 +556,12 @@ int http2_handler::push_promise(http2_stream &stream, std::string method,
auto
promised_stream
=
create_stream
(
rv
);
auto
&
promised_req
=
promised_stream
->
request
().
impl
();
promised_req
.
pushed
(
true
);
promised_req
.
method
(
std
::
move
(
method
));
promised_req
.
scheme
(
req
.
scheme
());
promised_req
.
authority
(
req
.
authority
());
promised_req
.
path
(
std
::
move
(
path
));
promised_req
.
host
(
req
.
host
());
promised_req
.
header
(
std
::
move
(
h
));
if
(
!
req
.
host
().
empty
())
{
promised_req
.
header
().
emplace
(
"host"
,
header_value
(
req
.
host
()));
}
promised_req
.
method
(
std
::
move
(
method
));
auto
&
uref
=
promised_req
.
uri
();
uref
.
scheme
=
req
.
uri
().
scheme
;
uref
.
host
=
req
.
uri
().
host
;
split_path
(
uref
,
std
::
begin
(
raw_path_query
),
std
::
end
(
raw_path_query
));
return
0
;
}
...
...
src/asio_http2_handler.h
View file @
fc2170e4
...
...
@@ -47,27 +47,23 @@ class request_impl {
public:
request_impl
();
void
header
(
header_map
h
);
const
header_map
&
header
()
const
;
header_map
&
header
();
void
method
(
std
::
string
method
);
const
std
::
string
&
method
()
const
;
const
std
::
string
&
scheme
()
const
;
const
std
::
string
&
authority
()
const
;
const
std
::
string
&
host
()
const
;
const
std
::
string
&
path
()
const
;
bool
push
(
std
::
string
method
,
std
::
string
path
,
header_map
h
=
{});
const
uri_ref
&
uri
()
const
;
uri_ref
&
uri
();
bool
push
(
std
::
string
method
,
std
::
string
raw_path_query
,
header_map
h
=
{});
bool
pushed
()
const
;
void
on_data
(
data_cb
cb
);
void
on_end
(
void_cb
cb
);
void
header
(
header_map
h
);
header_map
&
header
();
void
method
(
std
::
string
method
);
void
scheme
(
std
::
string
scheme
);
void
authority
(
std
::
string
authority
);
void
host
(
std
::
string
host
);
void
path
(
std
::
string
path
);
void
pushed
(
bool
f
);
void
stream
(
http2_stream
*
s
);
void
call_on_data
(
const
uint8_t
*
data
,
std
::
size_t
len
);
...
...
@@ -77,10 +73,7 @@ private:
http2_stream
*
stream_
;
header_map
header_
;
std
::
string
method_
;
std
::
string
scheme_
;
std
::
string
authority_
;
std
::
string
host_
;
std
::
string
path_
;
uri_ref
uri_
;
data_cb
on_data_cb_
;
void_cb
on_end_cb_
;
bool
pushed_
;
...
...
@@ -162,8 +155,8 @@ public:
void
resume
(
http2_stream
&
stream
);
int
push_promise
(
http2_stream
&
stream
,
std
::
string
method
,
std
::
string
path
,
header_map
h
);
int
push_promise
(
http2_stream
&
stream
,
std
::
string
method
,
std
::
string
raw_path_query
,
header_map
h
);
boost
::
asio
::
io_service
&
io_service
();
...
...
src/includes/nghttp2/asio_http2_server.h
View file @
fc2170e4
...
...
@@ -48,20 +48,8 @@ public:
// Returns method (e.g., GET).
const
std
::
string
&
method
()
const
;
// Returns scheme (e.g., https).
const
std
::
string
&
scheme
()
const
;
// Returns authority (e.g., example.org). This could be empty
// string. In this case, check host().
const
std
::
string
&
authority
()
const
;
// Returns host (e.g., example.org). If host header field is not
// present, this value is copied from authority().
const
std
::
string
&
host
()
const
;
// Returns path (e.g., /index.html).
const
std
::
string
&
path
()
const
;
// Returns request URI, split into components.
const
uri_ref
&
uri
()
const
;
// Sets callback when chunk of request body is received.
void
on_data
(
data_cb
cb
)
const
;
...
...
@@ -73,7 +61,8 @@ public:
// headers can be given in |h|. request_cb will be called for
// pushed resource later on. This function returns true if it
// succeeds, or false.
bool
push
(
std
::
string
method
,
std
::
string
path
,
header_map
h
=
{})
const
;
bool
push
(
std
::
string
method
,
std
::
string
raw_path_query
,
header_map
h
=
{})
const
;
// Returns true if this is pushed request.
bool
pushed
()
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