]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libhttpd/unallowed.c
libaml: fix gc bug, need to amltake()/amldrop() temporary buffer
[plan9front.git] / sys / src / libhttpd / unallowed.c
1 #include <u.h>
2 #include <libc.h>
3 #include <bin.h>
4 #include <httpd.h>
5
6 int
7 hunallowed(HConnect *c, char *allowed)
8 {
9         Hio *hout;
10         int n;
11
12         n = snprint(c->xferbuf, HBufSize, "<head><title>Method Not Allowed</title></head>\r\n"
13                 "<body><h1>Method Not Allowed</h1>\r\n"
14                 "You can't %s on <a href=\"%U\"> here</a>.<p></body>\r\n", c->req.meth, c->req.uri);
15
16         hout = &c->hout;
17         hprint(hout, "%s 405 Method Not Allowed\r\n", hversion);
18         hprint(hout, "Date: %D\r\n", time(nil));
19         hprint(hout, "Server: Plan9\r\n");
20         hprint(hout, "Content-Type: text/html\r\n");
21         hprint(hout, "Allow: %s\r\n", allowed);
22         hprint(hout, "Content-Length: %d\r\n", n);
23         if(c->head.closeit)
24                 hprint(hout, "Connection: close\r\n");
25         else if(!http11(c))
26                 hprint(hout, "Connection: Keep-Alive\r\n");
27         hprint(hout, "\r\n");
28
29         if(strcmp(c->req.meth, "HEAD") != 0)
30                 hwrite(hout, c->xferbuf, n);
31
32         if(c->replog)
33                 c->replog(c, "Reply: 405 Method Not Allowed\nReason: Method Not Allowed\n");
34         return hflush(hout);
35 }