{"id":2050,"date":"2019-02-17T20:40:03","date_gmt":"2019-02-17T19:40:03","guid":{"rendered":"http:\/\/labalec.fr\/erwan\/?p=2050"},"modified":"2019-02-17T20:40:03","modified_gmt":"2019-02-17T19:40:03","slug":"build-a-lightweigth-https-server-step-2","status":"publish","type":"post","link":"https:\/\/labalec.fr\/erwan\/?p=2050","title":{"rendered":"Build a lightweigth HTTPS server : step 2"},"content":{"rendered":"<p>In previous <a href=\"https:\/\/labalec.fr\/erwan\/?p=2039\" rel=\"noopener\" target=\"_blank\">article<\/a> we installed indy 10 in Lazarus.<\/p>\n<p>Lets now build a lightweigth HTTP server.<\/p>\n<p>All it is really is a tcp server listening on port 80, parsing the incoming request and sending back the content of the requested file.<\/p>\n<p>All the \u00ab\u00a0magic\u00a0\u00bb really happens below.<\/p>\n<p><code><br \/>\n    lCmdLine := AContext.Connection.IOHandler.ReadLn;<br \/>\n    memResults.Lines.Add (lCmdLine);<br \/>\n    if lCmdLine<>'' then<br \/>\n        begin<br \/>\n        uri := StringReplace (lCmdLine ,'GET ','',[]);<br \/>\n        uri := copy(uri,1,pos(' ',uri )-1);<br \/>\n        uri :=StringReplace (uri,'\/','',[]);;<br \/>\n        if FileExists(uri)<br \/>\n           then AContext.Connection.IOHandler.WriteFile(uri)<br \/>\n           else AContext.Connection.IOHandler.Writeln('file not found');<br \/>\n        AContext.Connection.Disconnect;<br \/>\n        end;<br \/>\nend;<br \/>\n<\/code><\/p>\n<p>Source code can be found on <a href=\"https:\/\/github.com\/erwan2212\/indy-freepascal\" rel=\"noopener\" target=\"_blank\">github<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In previous article we installed indy 10 in Lazarus. Lets now build a lightweigth HTTP server. All it is really is a tcp server listening on port 80, parsing the incoming request and sending back the content of the requested file. All the \u00ab\u00a0magic\u00a0\u00bb really happens below. lCmdLine := AContext.Connection.IOHandler.ReadLn; memResults.Lines.Add (lCmdLine); if lCmdLine\u00a0\u00bb then <a href='https:\/\/labalec.fr\/erwan\/?p=2050' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"class_list":["post-2050","post","type-post","status-publish","format-standard","hentry","category-delphi","category-37-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/2050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2050"}],"version-history":[{"count":2,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/2050\/revisions"}],"predecessor-version":[{"id":2053,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=\/wp\/v2\/posts\/2050\/revisions\/2053"}],"wp:attachment":[{"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labalec.fr\/erwan\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}