Skip to content

Commit 530480b

Browse files
committed
Fixed Double host entry & websocket initiator requests
1 parent 890d472 commit 530480b

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

websocketpp/http/impl/parser.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ inline bool parser::parse_parameter_list(std::string const & in,
141141
}
142142

143143
inline bool parser::prepare_body(lib::error_code & ec) {
144+
ec.clear();
145+
144146
if (!get_header("Content-Length").empty()) {
145147
std::string const & cl_header = get_header("Content-Length");
146148
char * end;
@@ -160,14 +162,12 @@ inline bool parser::prepare_body(lib::error_code & ec) {
160162
}
161163

162164
m_body_encoding = body_encoding::plain;
163-
ec = lib::error_code();
164-
return true;
165+
return m_body_bytes_needed;
165166
} else if (get_header("Transfer-Encoding") == "chunked") {
166167
m_body_encoding = body_encoding::chunked;
167168
return true;
168169
} else {
169-
ec = lib::error_code();
170-
return true; // valid! means there is no body to read
170+
return false;
171171
}
172172
}
173173

@@ -218,8 +218,6 @@ inline size_t parser::process_body(char const * buf, size_t len,
218218
return processed + process_body(buf + processed, len - processed, ec);
219219
}
220220
}
221-
return 0;
222-
// TODO: support for chunked transfers?
223221
} else {
224222
ec = error::make_error_code(error::unknown_transfer_encoding);
225223
return 0;

websocketpp/http/impl/response.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,12 @@ inline size_t response::consume(char const * buf, size_t len, lib::error_code &
122122
return 0;
123123
}
124124

125-
if (!prepare_body(ec))
125+
const bool need_more = prepare_body(ec);
126+
if (ec) {
126127
return 0;
128+
}
127129

128-
if (m_body_encoding == body_encoding::unknown) {
130+
if (m_body_encoding == body_encoding::unknown || !need_more) {
129131
m_state = state::DONE;
130132
m_buf.reset();
131133
ec.clear();

websocketpp/impl/connection_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ void connection<config>::handle_transport_init(lib::error_code const & ec) {
904904
} else {
905905
if (m_request.get_version().empty())
906906
m_request.set_version("HTTP/1.1");
907-
m_request.append_header("Host", m_uri->get_host_port());
907+
m_request.replace_header("Host", m_uri->get_host_port());
908908
if (m_request.get_uri().empty())
909909
m_request.set_uri(get_uri()->get_resource());
910910
}

0 commit comments

Comments
 (0)