about summary refs log tree commit diff stats
path: root/http-server.mu
blob: 6bd172b304cdf391da862a2ebe44a036fe464fb4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# example program: a single-request HTTP server
#   listen for connections from clients on a server socket
#   when a connection occurs, transfer it to a session socket
#   read from it using channels
#   write to it directly
#
# After running it, navigate to localhost:8080. Your browser should display
# "SUCCESS!" and the server will terminate after one connection.

def main [
  local-scope
  socket:num <- $open-server-socket 8080/port
  $print [Mu socket creation returned ], socket, 10/newline
  return-unless socket
  session:num <- $accept socket
  contents:&:source:char, sink:&:sink:char <- new-channel 30
  sink <- start-running receive-from-socket session, sink
  query:text <- drain contents
  $print [Done reading from socket.], 10/newline
  write-to-socket session, [HTTP/1.0 200 OK
Content-type: text/plain

SUCCESS!
]
  $print 10/newline, [Wrote to and closing socket...], 10/newline
  session <- $close-socket session
  socket <- $close-socket socket
]
>find ranger -depth -name __pycache__ -type d -exec rm -rf -- {} \; doc: cleandoc mkdir -p $(DOCDIR) cd $(DOCDIR); \ $(PYTHON) -c 'import pydoc, sys; \ sys.path[0] = "$(CWD)"; \ pydoc.writedocs("$(CWD)")' find . -name \*.html -exec sed -i 's|'$(CWD)'|../..|g' -- {} \; test: @for FILE in $(shell grep -IHm 1 doctest -r ranger | cut -d: -f1); do \ echo "Testing $$FILE..."; \ PYTHONPATH=".:"$$PYTHONPATH ${PYTHON} $$FILE; \ done man: pod2man --stderr --center='ranger manual' --date='$(NAME)-$(VERSION)' \ --release=$(shell date +%x) doc/ranger.pod doc/ranger.1 manhtml: pod2html doc/ranger.pod --outfile=doc/ranger.1.html cleandoc: test -d $(DOCDIR) && rm -f -- $(DOCDIR)/*.html || true snapshot: git archive --prefix='$(NAME)-$(VERSION)/' --format=tar HEAD | gzip > $(SNAPSHOT_NAME) todo: @grep --color -Ion '\(TODO\|XXX\).*' -r ranger .PHONY: default options compile clean doc cleandoc snapshot install man todo