Permalink
Browse files

http, bugfix: HttpResponse.statusMessage encode error.

  • Loading branch information...
xicilion committed Sep 28, 2017
1 parent b7f14b1 commit 91915c08429e99b8e4fc66269564cbd4dd6edd76
Showing with 43 additions and 2 deletions.
  1. +8 −2 fibjs/src/http/HttpResponse.cpp
  2. +35 −0 test/http_test.js
@@ -297,11 +297,17 @@ result_t HttpResponse::sendTo(Stream_base* stm, AsyncEvent* ac)
}
exlib::string strCommand;
exlib::string statusMessage = m_statusMessage;
exlib::string statusMessage;
if (statusMessage.empty()) {
if (m_statusMessage.empty()) {
int32_t pos = shortcut[m_statusCode / 100 - 1] + m_statusCode % 100;
statusMessage.assign(status_lines[pos], status_lines_size[pos]);
} else {
char buf[16];
sprintf(buf, " %d ", m_statusCode);
statusMessage = buf;
statusMessage.append(m_statusMessage);
}
get_protocol(strCommand);
View
@@ -811,6 +811,41 @@ describe("http", () => {
assert.equal(ms.read(), 'HTTP/1.1 200 OK\r\nConnection: keep-alive\r\nContent-Length: 10\r\n\r\n');
});
it("statusCode", () => {
var ms = new io.MemoryStream();
var rep = new http.Response();
rep.statusCode = 404;
rep.sendTo(ms);
ms.rewind();
assert.equal(ms.read(), 'HTTP/1.1 404 File Not Found\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n');
});
it("statusMessage", () => {
var ms = new io.MemoryStream();
var rep = new http.Response();
rep.statusMessage = "test message";
rep.sendTo(ms);
ms.rewind();
assert.equal(ms.read(), 'HTTP/1.1 200 test message\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n');
});
it("writeHead", () => {
var ms = new io.MemoryStream();
var rep = new http.Response();
rep.writeHead(202, "test message", {
"test": "test_header"
});
rep.sendTo(ms);
ms.rewind();
assert.equal(ms.read().toString(), 'HTTP/1.1 202 test message\r\ntest: test_header\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n');
});
it("address", () => {
var rep = new http.Request();
rep.body.write("0123456789");

0 comments on commit 91915c0

Please sign in to comment.