Translate received SPDY/2 name/value pairs into SPDY/3 style.
The callback functions receives SPDY/3 style name/value pairs.
This commit is contained in:
parent
00abfc8dd3
commit
185d929d86
|
@ -266,8 +266,8 @@ int SpdyEventHandler::submit_file_response(const std::string& status,
|
|||
std::string date_str = util::http_date(time(0));
|
||||
std::string content_length = util::to_str(file_length);
|
||||
const char *nv[] = {
|
||||
get_header_field(version_, HD_STATUS).c_str(), status.c_str(),
|
||||
get_header_field(version_, HD_VERSION).c_str(), "HTTP/1.1",
|
||||
":status", status.c_str(),
|
||||
":version", "HTTP/1.1",
|
||||
"server", SPDYD_SERVER.c_str(),
|
||||
"content-length", content_length.c_str(),
|
||||
"cache-control", "max-age=3600",
|
||||
|
@ -290,9 +290,9 @@ int SpdyEventHandler::submit_response
|
|||
{
|
||||
std::string date_str = util::http_date(time(0));
|
||||
const char **nv = new const char*[8+headers.size()*2+1];
|
||||
nv[0] = get_header_field(version_, HD_STATUS).c_str();
|
||||
nv[0] = ":status";
|
||||
nv[1] = status.c_str();
|
||||
nv[2] = get_header_field(version_, HD_VERSION).c_str();
|
||||
nv[2] = ":version";
|
||||
nv[3] = "HTTP/1.1";
|
||||
nv[4] = "server";
|
||||
nv[5] = SPDYD_SERVER.c_str();
|
||||
|
@ -313,8 +313,8 @@ int SpdyEventHandler::submit_response(const std::string& status,
|
|||
spdylay_data_provider *data_prd)
|
||||
{
|
||||
const char *nv[] = {
|
||||
get_header_field(version_, HD_STATUS).c_str(), status.c_str(),
|
||||
get_header_field(version_, HD_VERSION).c_str(), "HTTP/1.1",
|
||||
":status", status.c_str(),
|
||||
":version", "HTTP/1.1",
|
||||
"server", SPDYD_SERVER.c_str(),
|
||||
0
|
||||
};
|
||||
|
@ -452,16 +452,16 @@ void prepare_response(Request *req, SpdyEventHandler *hd)
|
|||
for(int i = 0; i < (int)req->headers.size(); ++i) {
|
||||
const std::string &field = req->headers[i].first;
|
||||
const std::string &value = req->headers[i].second;
|
||||
if(!url_found && field == get_header_field(hd->version(), HD_PATH)) {
|
||||
if(!url_found && field == ":path") {
|
||||
url_found = true;
|
||||
url = value;
|
||||
} else if(field == get_header_field(hd->version(), HD_METHOD)) {
|
||||
} else if(field == ":method") {
|
||||
method_found = true;
|
||||
} else if(field == get_header_field(hd->version(), HD_SCHEME)) {
|
||||
} else if(field == ":scheme") {
|
||||
scheme_found = true;
|
||||
} else if(field == get_header_field(hd->version(), HD_VERSION)) {
|
||||
} else if(field == ":version") {
|
||||
version_found = true;
|
||||
} else if(field == get_header_field(hd->version(), HD_HOST)) {
|
||||
} else if(field == ":host") {
|
||||
host_found = true;
|
||||
} else if(!last_mod_found && field == "if-modified-since") {
|
||||
last_mod_found = true;
|
||||
|
|
|
@ -48,17 +48,6 @@ namespace spdylay {
|
|||
|
||||
bool ssl_debug = false;
|
||||
|
||||
const std::string& get_header_field(uint16_t version, size_t field)
|
||||
{
|
||||
if(version == SPDYLAY_PROTO_SPDY2) {
|
||||
return header_fields_spdy2[field];
|
||||
} else if(version == SPDYLAY_PROTO_SPDY3) {
|
||||
return header_fields_spdy3[field];
|
||||
} else {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
Spdylay::Spdylay(int fd, SSL *ssl, uint16_t version,
|
||||
const spdylay_session_callbacks *callbacks)
|
||||
: fd_(fd), ssl_(ssl), version_(version), want_write_(false)
|
||||
|
@ -122,11 +111,11 @@ int Spdylay::submit_request(const std::string& hostport,
|
|||
void *stream_user_data)
|
||||
{
|
||||
const char *nv[] = {
|
||||
get_header_field(version_, HD_METHOD).c_str(), "GET",
|
||||
get_header_field(version_, HD_PATH).c_str(), path.c_str(),
|
||||
get_header_field(version_, HD_VERSION).c_str(), "HTTP/1.1",
|
||||
get_header_field(version_, HD_SCHEME).c_str(), "https",
|
||||
get_header_field(version_, HD_HOST).c_str(), hostport.c_str(),
|
||||
":method", "GET",
|
||||
":path", path.c_str(),
|
||||
":version", "HTTP/1.1",
|
||||
":scheme", "https",
|
||||
":host", hostport.c_str(),
|
||||
"user-agent", "spdylay/0.0.0",
|
||||
NULL
|
||||
};
|
||||
|
|
|
@ -38,25 +38,6 @@ namespace spdylay {
|
|||
|
||||
extern bool ssl_debug;
|
||||
|
||||
enum HeaderField {
|
||||
HD_METHOD = 0,
|
||||
HD_PATH = 1,
|
||||
HD_VERSION = 2,
|
||||
HD_HOST = 3,
|
||||
HD_SCHEME = 4,
|
||||
HD_STATUS = 5
|
||||
};
|
||||
|
||||
const std::string header_fields_spdy2[] = {
|
||||
"method", "url", "version", "host", "scheme", "status", "version"
|
||||
};
|
||||
|
||||
const std::string header_fields_spdy3[] = {
|
||||
":method", ":path", ":version", ":host", ":scheme", ":status", ":version"
|
||||
};
|
||||
|
||||
const std::string& get_header_field(uint16_t version, size_t field);
|
||||
|
||||
class Spdylay {
|
||||
public:
|
||||
Spdylay(int fd, SSL *ssl, uint16_t version,
|
||||
|
|
|
@ -1539,6 +1539,9 @@ static int spdylay_session_process_ctrl_frame(spdylay_session *session)
|
|||
session->iframe.len,
|
||||
&session->hd_inflater);
|
||||
if(r == 0) {
|
||||
if(session->version == SPDYLAY_PROTO_SPDY2) {
|
||||
spdylay_frame_nv_2to3(frame.syn_stream.nv);
|
||||
}
|
||||
r = spdylay_session_on_syn_stream_received(session, &frame);
|
||||
spdylay_frame_syn_stream_free(&frame.syn_stream);
|
||||
/* TODO if r indicates mulformed NV pairs (multiple nulls) or
|
||||
|
@ -1560,6 +1563,9 @@ static int spdylay_session_process_ctrl_frame(spdylay_session *session)
|
|||
session->iframe.len,
|
||||
&session->hd_inflater);
|
||||
if(r == 0) {
|
||||
if(session->version == SPDYLAY_PROTO_SPDY2) {
|
||||
spdylay_frame_nv_2to3(frame.syn_reply.nv);
|
||||
}
|
||||
r = spdylay_session_on_syn_reply_received(session, &frame);
|
||||
spdylay_frame_syn_reply_free(&frame.syn_reply);
|
||||
} else if(spdylay_is_non_fatal(r)) {
|
||||
|
@ -1632,6 +1638,9 @@ static int spdylay_session_process_ctrl_frame(spdylay_session *session)
|
|||
session->iframe.len,
|
||||
&session->hd_inflater);
|
||||
if(r == 0) {
|
||||
if(session->version == SPDYLAY_PROTO_SPDY2) {
|
||||
spdylay_frame_nv_2to3(frame.headers.nv);
|
||||
}
|
||||
r = spdylay_session_on_headers_received(session, &frame);
|
||||
spdylay_frame_headers_free(&frame.headers);
|
||||
} else if(spdylay_is_non_fatal(r)) {
|
||||
|
|
Loading…
Reference in New Issue