Micro changes and fix utest fail.

pull/3195/head
winlin 2 years ago
parent 1e6143e2eb
commit d32bd72527

@ -1011,8 +1011,6 @@ void SrsHttpResponseWriter::write_default_header()
SrsHttpRequestWriter::SrsHttpRequestWriter(ISrsProtocolReadWriter* io)
{
writer_ = new SrsHttpMessageWriter(io, this);
method_ = NULL;
path_ = NULL;
}
SrsHttpRequestWriter::~SrsHttpRequestWriter()
@ -1040,10 +1038,10 @@ srs_error_t SrsHttpRequestWriter::writev(const iovec* iov, int iovcnt, ssize_t*
return writer_->writev(iov, iovcnt, pnwrite);
}
void SrsHttpRequestWriter::write_header(const char* method, const char* path)
void SrsHttpRequestWriter::write_header(const std::string& method, const std::string& path)
{
if (writer_->header_wrote()) {
srs_warn("http: multiple write_header calls, current=%s(%s), now=%s(%s)", method_, path_, method, path);
srs_warn("http: multiple write_header calls, current=%s(%s), now=%s(%s)", method_.c_str(), path_.c_str(), method.c_str(), path.c_str());
return;
}

@ -290,8 +290,8 @@ class SrsHttpRequestWriter : public ISrsHttpRequestWriter, public ISrsHttpFirstL
protected:
SrsHttpMessageWriter* writer_;
// The method and path passed to WriteHeader, for request only.
const char* method_;
const char* path_;
std::string method_;
std::string path_;
public:
SrsHttpRequestWriter(ISrsProtocolReadWriter* io);
virtual ~SrsHttpRequestWriter();
@ -301,7 +301,7 @@ public:
virtual SrsHttpHeader* header();
virtual srs_error_t write(char* data, int size);
virtual srs_error_t writev(const iovec* iov, int iovcnt, ssize_t* pnwrite);
virtual void write_header(const char* method, const char* path);
virtual void write_header(const std::string& method, const std::string& path);
// Interface ISrsHttpFirstLineWriter
public:
virtual srs_error_t build_first_line(std::stringstream& ss, char* data, int size);

@ -270,7 +270,7 @@ public:
// Thus explicit calls to WriteHeader are mainly used to
// send error codes.
// @remark, user must set header then write or write_header.
virtual void write_header(const char* method, const char* path) = 0;
virtual void write_header(const std::string& method, const std::string& path) = 0;
};
// Objects implementing the Handler interface can be

@ -91,6 +91,7 @@ VOID TEST(TCPServerTest, PingPong)
l.set_endpoint(_srs_tmp_host, _srs_tmp_port);
HELPER_EXPECT_SUCCESS(l.listen());
EXPECT_TRUE(srs_netfd_fileno(l.lfd) > 0);
}
if (true) {
@ -515,12 +516,12 @@ VOID TEST(HTTPServerTest, MessageConnection)
if (true) {
SrsHttpMessage m;
m.set_basic(HTTP_REQUEST, 100, 0, 0); EXPECT_STREQ("<unknown>", m.method_str().c_str());
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_GET, 0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_GET, m.method()); EXPECT_STREQ("GET", m.method_str().c_str());
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_PUT, 0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_PUT, m.method()); EXPECT_STREQ("PUT", m.method_str().c_str());
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_POST, 0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_POST, m.method()); EXPECT_STREQ("POST", m.method_str().c_str());
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_DELETE, 0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_DELETE, m.method()); EXPECT_STREQ("DELETE", m.method_str().c_str());
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_OPTIONS, 0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_OPTIONS, m.method()); EXPECT_STREQ("OPTIONS", m.method_str().c_str());
m.set_basic(HTTP_REQUEST, (http_method)100, (http_status)0, 0); EXPECT_STREQ("<unknown>", m.method_str().c_str());
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_GET, (http_status)0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_GET, m.method()); EXPECT_STREQ("GET", m.method_str().c_str());
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_PUT, (http_status)0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_PUT, m.method()); EXPECT_STREQ("PUT", m.method_str().c_str());
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_POST, (http_status)0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_POST, m.method()); EXPECT_STREQ("POST", m.method_str().c_str());
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_DELETE, (http_status)0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_DELETE, m.method()); EXPECT_STREQ("DELETE", m.method_str().c_str());
m.set_basic(HTTP_REQUEST, SRS_CONSTS_HTTP_OPTIONS, (http_status)0, 0); EXPECT_EQ(SRS_CONSTS_HTTP_OPTIONS, m.method()); EXPECT_STREQ("OPTIONS", m.method_str().c_str());
}
if (true) {

Loading…
Cancel
Save