Skip to content

Commit

Permalink
更新代码
Browse files Browse the repository at this point in the history
  • Loading branch information
CandyMi committed Nov 10, 2019
1 parent 6ee1ca3 commit e58f5b6
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions luaclib/src/lhttpparser/lhttpparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "../../../src/core.h"
#include "httpparser.h"

#define MAX_HEADER (128)

static int
lparser_response_chunked(lua_State *L){
size_t buf_len;
Expand Down Expand Up @@ -34,19 +36,19 @@ lparser_http_request(lua_State *L){
const char *path;
size_t method_len, path_len, num_headers;

struct phr_header headers[128];
memset(headers, 0x0, sizeof(headers));
struct phr_header headers[MAX_HEADER];
memset(headers, 0x0, sizeof(struct phr_header) * MAX_HEADER);

num_headers = sizeof(headers) / sizeof(headers[0]);
num_headers = MAX_HEADER;
ret = phr_parse_request(buf, buf_len, &method, &method_len, &path, &path_len, &minor_version, headers, &num_headers, 0);
if (0 > ret) return 0;

lua_pushlstring(L, method, method_len); // METHOD
lua_pushlstring(L, path, path_len); // PATH
lua_pushnumber(L, minor_version > 0 ? 1.1 : 1.0); // VERSION

lua_createtable(L, 0, 128);
for (i = 0; i < 128; i++){
lua_createtable(L, 0, MAX_HEADER);
for (i = 0; i < MAX_HEADER; i++){
if (!headers[i].name || !headers[i].value)
break;
lua_pushlstring(L, headers[i].name, headers[i].name_len);
Expand All @@ -65,19 +67,19 @@ lparser_http_response(lua_State *L){
size_t msg_len, num_headers;
const char* msg;

struct phr_header headers[128];
memset(headers, 0x0, sizeof(headers));
struct phr_header headers[MAX_HEADER];
memset(headers, 0x0, sizeof(struct phr_header) * MAX_HEADER);

num_headers = sizeof(headers) / sizeof(headers[0]);
num_headers = MAX_HEADER;
ret = phr_parse_response(buf, buf_len, &minor_version, &status, &msg, &msg_len, headers, &num_headers, 0);
if (0 > ret) return 0;

lua_pushnumber(L, minor_version > 0 ? 1.1 : 1.0); // VERSION
lua_pushinteger(L, status); // STATUS CODE
lua_pushlstring(L, msg, msg_len); // STATUS MSG

lua_createtable(L, 0, 128);
for (i = 0; i < 128; i++){
lua_createtable(L, 0, MAX_HEADER);
for (i = 0; i < MAX_HEADER; i++){
if (!headers[i].name || !headers[i].value)
break;
lua_pushlstring(L, headers[i].name, headers[i].name_len);
Expand Down

0 comments on commit e58f5b6

Please sign in to comment.