diff --git a/addons/HttpClient/io/HCConnection.io b/addons/HttpClient/io/HCConnection.io index 64de3f7ae..4d085d248 100644 --- a/addons/HttpClient/io/HCConnection.io +++ b/addons/HttpClient/io/HCConnection.io @@ -33,7 +33,7 @@ HCConnection := Object clone do( if(request port asString == "80", request setHeader("Host", request host) , - request setHeader("Host", Sequence with(request host, ":", request port)) + request setHeader("Host", Sequence with(request host, ":", request port asString)) ) request headers select(k, v, v != nil) map(k, v, @@ -42,7 +42,7 @@ HCConnection := Object clone do( ) httpMessage := method( - Sequence with(statusLine, headersLines, headerTerminator) + Sequence with(statusLine, headersLines, headerTerminator, request body) ) sendMessage := method( @@ -75,4 +75,4 @@ HCConnection := Object clone do( self ) -) \ No newline at end of file +) diff --git a/addons/HttpClient/io/HCRequest.io b/addons/HttpClient/io/HCRequest.io index cbdc2753e..3405ff88a 100644 --- a/addons/HttpClient/io/HCRequest.io +++ b/addons/HttpClient/io/HCRequest.io @@ -12,7 +12,8 @@ //doc HCRequest hasHeader(name) Returns true if this request has a header with name //doc HCRequest setHeader(name, value) Sets header with name to value //doc HCRequest headerAt(name) Returns the value for header with name - +// doc HCRequest setBody(string) Sets the body to string and changes the "Content-Length" header accordingly +// doc HCReqeust body The message body HCRequest := Object clone do( url ::= nil @@ -26,6 +27,8 @@ HCRequest := Object clone do( headers atPut("Connection", "close") ) + messageBody ::= nil + with := method(url, self clone setUrl(url) ) @@ -57,4 +60,19 @@ HCRequest := Object clone do( headerAt := method(name, headers at(name) ) -) \ No newline at end of file + + setBody := method(string, + messageBody := string + if(messageBody isNil, + headers removeAt("Content-Length") + return + ) + + setHeader("Content-Length", messageBody size asString) + ) + + body := method( + messageBody ifNilEval(return "") + return messageBody + ) +)