Correct documentation about request properties
bbblitz opened this issue · 3 comments
Currently, the readme makes the following claims:
Request properties:
path:string
however, request.path is a function (that returns a string),
headers:table
however, request.headers is a function (that returns a table),
method:function
is correct (it's a function that returns a string)
querystring:string
however, request.querystring is a table (of strings)
ip:string
is correct
port:number
is correct
Response properties seem to be all correct.
I found the above with the below script:
local pegasus = require("pegasus")
local server = pegasus:new{
port="9090",
location=".",
}
server:start(function(req,res)
for _,cursor in pairs({req,res}) do
while cursor ~= nil do
print("Cursor:",cursor)
for k,v in pairs(cursor) do
print("\t",k,":",v)
end
cursor = getmetatable(cursor) and getmetatable(cursor).__index or nil
end
print("----------------")
end
end)
Gives the output
Pegasus is up on 0.0.0.0:9090
Request for: /
Cursor: table: 00000000026842f0
_params : table: 00000000026835b0
_headerParsed : false
port : 9090
_contentDone : 0
_method : GET
_path : /
server : tcp{server}: 000000000268C238
_firstLine : GET / HTTP/1.1
querystring : table: 0000000002683af0
ip : 127.0.0.1
_headers : table: 0000000002683670
client : tcp{client}: 000000000268E2E8
Cursor: table: 0000000002658c70
receiveBody : function: 0000000002652970
PATTERN_QUERY_STRING : ([^=]*)=([^&]*)&?
PATTERN_PATH : (%S+)%s*
parseFirstLine : function: 0000000002658f70
PATTERN_PROTOCOL : (HTTP%/%d%.%d)
headers : function: 0000000002658970
method : function: 0000000002653240
PATTERN_REQUEST : ^(.-)%s(%S+)%s*(HTTP%/%d%.%d)
path : function: 0000000002652c10
PATTERN_METHOD : ^(.-)%s
post : function: 0000000002652fa0
parseUrlEncoded : function: 0000000002659530
new : function: 00000000026531e0
__index : table: 0000000002658c70
PATTERN_HEADER : ([%w-]+): ([%w %p]+=?)
----------------
Cursor: table: 0000000002684330
_templateFirstLine : HTTP/1.1 {{ STATUS_CODE }} {{ STATUS_TEXT }}
request : table: 00000000026842f0
_client : tcp{client}: 000000000268E2E8
headers : table: 0000000002683ff0
_headersSended : false
_isClosed : false
status : 200
_headers : table: 0000000002683cb0
_headFirstLine : HTTP/1.1 200 OK
_writeHandler : table: 0000000002683630
Cursor: table: 0000000002659230
writeFile : function: 000000000265a5c0
statusCode : function: 0000000002659370
write : function: 000000000265a590
addHeaders : function: 000000000265ad70
sendOnlyHeaders : function: 000000000265b010
contentType : function: 000000000265ada0
_getHeaders : function: 000000000265af80
close : function: 000000000265a4d0
sendHeaders : function: 000000000265a650
writeDefaultErrorMessage : function: 00000000026588f0
__index : table: 0000000002659230
new : function: 000000000265abf0
addHeader : function: 000000000265ad10
----------------
In case it matters, I'm on Windows with luarocks using mingw32 as my compiler.
I really don't care if you make everything functions that return these things, or make them actual fields, but this inconsistency is really confusing!
@bbblitz I'm not sure if I understood your point.
You don't agree with the fact that we've some properties and some methods, is that?
I don't agree that they're documented as properties, but are actually methods (except for querystring:string
, which is actually a table)
You're correct, there're some outdated information.
Thanks for letting me know, I didn't notice this issues :)