Commit 991ded91 authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

Added -a, --get-asserts option to spdycat

If this option is used, spdycat also downloads assets such as
stylesheets, images and script files linked from the downloaded
resource. They are queued in the same SPDY session.
parent 8b8d79ee
......@@ -95,6 +95,13 @@ if test "x${have_openssl}" = "xno"; then
AC_MSG_NOTICE([The example programs will not be built.])
fi
# libxml2 (for examples/spdycat)
AM_PATH_XML2(2.7.7, [have_libxml2=yes])
if test "x${have_libxml2}" = "xyes"; then
AC_DEFINE([HAVE_LIBXML2], [1], [Define to 1 if you have `libxml2` library.])
fi
AM_CONDITIONAL([HAVE_LIBXML2], [ test "x${have_libxml2}" = "xyes" ])
# The example programs depend on OpenSSL
enable_examples=$have_openssl
AM_CONDITIONAL([ENABLE_EXAMPLES], [ test "x${enable_examples}" = "xyes" ])
......
......@@ -25,8 +25,8 @@ if ENABLE_EXAMPLES
AM_CFLAGS = -Wall
AM_CPPFLAGS = -Wall -I$(srcdir)/../lib/includes -I$(builddir)/../lib/includes \
@OPENSSL_CFLAGS@ @DEFS@
AM_LDFLAGS = @OPENSSL_LIBS@
@OPENSSL_CFLAGS@ @XML_CPPFLAGS@ @DEFS@
AM_LDFLAGS = @OPENSSL_LIBS@ @XML_LIBS@
LDADD = $(top_builddir)/lib/libspdylay.la
bin_PROGRAMS = spdycat spdyd
......@@ -47,10 +47,18 @@ EVENT_OBJECTS += EventPoll_kqueue.cc
EVENT_HFILES += EventPoll_kqueue.h
endif # HAVE_KQUEUE
HTML_PARSER_OBJECTS =
HTML_PARSER_HFILES = HtmlParser.h
if HAVE_LIBXML2
HTML_PARSER_OBJECTS += HtmlParser.cc
endif # HAVE_LIBXML2
SPDY_SERVER_OBJECTS = SpdyServer.cc
SPDY_SERVER_HFILES = SpdyServer.h
spdycat_SOURCES = ${HELPER_OBJECTS} ${HELPER_HFILES} spdycat.cc
spdycat_SOURCES = ${HELPER_OBJECTS} ${HELPER_HFILES} spdycat.cc \
${HTML_PARSER_OBJECTS} ${HTML_PARSER_HFILES}
spdyd_SOURCES = ${HELPER_OBJECTS} ${HELPER_HFILES} \
${EVENT_OBJECTS} ${EVENT_HFILES} \
......
This diff is collapsed.
......@@ -49,8 +49,10 @@ namespace spdylay {
bool ssl_debug = false;
Spdylay::Spdylay(int fd, SSL *ssl, uint16_t version,
const spdylay_session_callbacks *callbacks)
: fd_(fd), ssl_(ssl), version_(version), want_write_(false)
const spdylay_session_callbacks *callbacks,
void *user_data)
: fd_(fd), ssl_(ssl), version_(version), user_data_(user_data),
want_write_(false)
{
int r = spdylay_session_client_new(&session_, version_, callbacks, this);
assert(r == 0);
......@@ -114,6 +116,11 @@ int Spdylay::fd() const
return fd_;
}
void* Spdylay::user_data()
{
return user_data_;
}
int Spdylay::submit_request(const std::string& hostport,
const std::string& path, uint8_t pri,
void *stream_user_data)
......
......@@ -41,7 +41,8 @@ extern bool ssl_debug;
class Spdylay {
public:
Spdylay(int fd, SSL *ssl, uint16_t version,
const spdylay_session_callbacks *callbacks);
const spdylay_session_callbacks *callbacks,
void *user_data);
~Spdylay();
int recv();
int send();
......@@ -55,11 +56,13 @@ public:
uint8_t pri, void *stream_user_data);
int submit_settings(int flags, spdylay_settings_entry *iv, size_t niv);
bool would_block(int r);
void* user_data();
private:
int fd_;
SSL *ssl_;
uint16_t version_;
spdylay_session *session_;
void *user_data_;
bool want_write_;
bool debug_;
};
......
......@@ -119,10 +119,55 @@ time_t parse_http_date(const std::string& s)
return timegm(&tm);
}
namespace {
char lowcase(char c)
{
if('A' <= c && c <= 'Z') {
return c+('a'-'A');
} else {
return c;
}
}
} // namespace
bool startsWith(const std::string& a, const std::string& b)
{
return startsWith(a.begin(), a.end(), b.begin(), b.end());
}
bool istartsWith(const std::string& a, const std::string& b)
{
return istartsWith(a.begin(), a.end(), b.begin(), b.end());
}
namespace {
void streq_advance(const char **ap, const char **bp)
{
for(; **ap && **bp && lowcase(**ap) == lowcase(**bp); ++*ap, ++*bp);
}
} // namespace
bool istartsWith(const char *a, const char* b)
{
if(!a || !b) {
return false;
}
streq_advance(&a, &b);
return !*b;
}
bool endsWith(const std::string& a, const std::string& b)
{
return endsWith(a.begin(), a.end(), b.begin(), b.end());
}
bool strieq(const char *a, const char *b)
{
if(!a || !b) {
return false;
}
for(; *a && *b && lowcase(*a) == lowcase(*b); ++a, ++b);
return !*a && !*b;
}
} // namespace util
......
......@@ -174,6 +174,50 @@ std::string to_str(T value)
return ss.str();
}
template<typename InputIterator1, typename InputIterator2>
bool startsWith
(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
InputIterator2 last2)
{
if(last1-first1 < last2-first2) {
return false;
}
return std::equal(first2, last2, first1);
}
bool startsWith(const std::string& a, const std::string& b);
struct CaseCmp {
bool operator()(char lhs, char rhs) const
{
if('A' <= lhs && lhs <= 'Z') {
lhs += 'a'-'A';
}
if('A' <= rhs && rhs <= 'Z') {
rhs += 'a'-'A';
}
return lhs == rhs;
}
};
template<typename InputIterator1, typename InputIterator2>
bool istartsWith
(InputIterator1 first1,
InputIterator1 last1,
InputIterator2 first2,
InputIterator2 last2)
{
if(last1-first1 < last2-first2) {
return false;
}
return std::equal(first2, last2, first1, CaseCmp());
}
bool istartsWith(const std::string& a, const std::string& b);
bool istartsWith(const char *a, const char* b);
template<typename InputIterator1, typename InputIterator2>
bool endsWith
(InputIterator1 first1,
......@@ -189,6 +233,8 @@ bool endsWith
bool endsWith(const std::string& a, const std::string& b);
bool strieq(const char *a, const char *b);
} // namespace util
} // namespace spdylay
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment