1
0
mirror of https://github.com/moparisthebest/spdylay synced 2024-11-12 04:25:09 -05:00

Changed spdylay_select_next_protocol behaviour

It now always select "spdy/2" as a next protocol regardless whether or not
the server advertises it. The NPN draft allows this.
Returning integer version number is not flexible because the selected protcol
is just a string.
The function now returns 0 if the server advertised spdy/2, or -1.
This commit is contained in:
Tatsuhiro Tsujikawa 2012-02-05 21:48:20 +09:00
parent be7cc9710f
commit d0cd362852
4 changed files with 33 additions and 14 deletions

View File

@ -360,8 +360,7 @@ int select_next_proto_cb(SSL* ssl,
}
}
if(spdylay_select_next_protocol(out, outlen, in, inlen) == -1) {
std::cerr << "Invalid protocol: "
<< std::string((const char*)*out, (size_t)*outlen) << std::endl;
std::cerr << "Server did not advertise spdy/2 protocol." << std::endl;
abort();
}
if(ssl_debug) {

View File

@ -435,16 +435,37 @@ int spdylay_submit_ping(spdylay_session *session);
int spdylay_submit_goaway(spdylay_session *session);
/*
* A helper function for dealing with NPN. This function returns the
* version of spdy that was negotiated, or -1. To use this method you
* should do something like:
* A helper function for dealing with NPN. This function always
* selects "spdy/2" protocol. NPN draft permits that client can
* select any protocol even if server does not advertise it at the
* time of this writing:
*
* It's expected that a client will have a list of protocols that it
* supports, in preference order, and will only select a protocol if
* the server supports it. In that case, the client SHOULD select
* the first protocol advertised by the server that it also
* supports. In the event that the client doesn't support any of
* server's protocols, or the server doesn't advertise any, it
* SHOULD select the first protocol that it supports.
*
* There are cases where the client knows that a server supports an
* unadvertised protocol. In these cases the client should simply
* select that protocol.
*
* Selecting "spdy/2" means that "spdy/2" is written into |*out| and
* length of "spdy/2" (which is 6) is assigned to |*outlen|.
*
* This function returns 0 if server advertised "spdy/2" and it is
* selected, or -1.
*
* To use this method you should do something like:
*
* static int select_next_proto_cb(SSL* ssl,
* unsigned char **out, unsigned char *outlen,
* const unsigned char *in, unsigned int inlen,
* void *arg)
* {
* if (spdylay_select_next_protocol(out, outlen, in, inlen) > 0) {
* if (spdylay_select_next_protocol(out, outlen, in, inlen) == 0) {
* ((MyType*)arg)->spdy = 1;
* }
* return SSL_TLSEXT_ERR_OK;

View File

@ -30,12 +30,11 @@ int spdylay_select_next_protocol(unsigned char **out, unsigned char *outlen,
const unsigned char *in, unsigned int inlen)
{
unsigned int i = 0;
*out = (unsigned char*)"spdy/2";
*outlen = 6;
for(; i < inlen; i += in[i]+1) {
/* Always assign to *out so that the last one is picked. */
*out = (unsigned char*)in+i+1;
*outlen = in[i];
if(in[i] == 6 && memcmp(&in[i+1], "spdy/2", in[i]) == 0) {
return 2;
return 0;
}
}
return -1;

View File

@ -36,10 +36,10 @@ static void spdy2()
};
unsigned char outlen;
unsigned char* out;
CU_ASSERT(2 == spdylay_select_next_protocol(&out, &outlen,
CU_ASSERT(0 == spdylay_select_next_protocol(&out, &outlen,
spdy, sizeof(spdy)));
CU_ASSERT(6 == outlen);
CU_ASSERT(memcmp("spdy/2", out, 6) == 0);
CU_ASSERT(memcmp("spdy/2", out, outlen) == 0);
}
static void spdy4()
@ -53,8 +53,8 @@ static void spdy4()
unsigned char* out;
CU_ASSERT(-1 == spdylay_select_next_protocol(&out, &outlen,
spdy, sizeof(spdy)));
CU_ASSERT(8 == outlen);
CU_ASSERT(memcmp("http/1.0", out, outlen) == 0);
CU_ASSERT(6 == outlen);
CU_ASSERT(memcmp("spdy/2", out, outlen) == 0);
}
void test_spdylay_npn()