unallowed.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bin.h>
  12. #include <httpd.h>
  13. int
  14. hunallowed(HConnect *c, char *allowed)
  15. {
  16. Hio *hout;
  17. int n;
  18. n = snprint(c->xferbuf, HBufSize, "<head><title>Method Not Allowed</title></head>\r\n"
  19. "<body><h1>Method Not Allowed</h1>\r\n"
  20. "You can't %s on <a href=\"%U\"> here</a>.<p></body>\r\n", c->req.meth, c->req.uri);
  21. hout = &c->hout;
  22. hprint(hout, "%s 405 Method Not Allowed\r\n", hversion);
  23. hprint(hout, "Date: %D\r\n", time(nil));
  24. hprint(hout, "Server: Plan9\r\n");
  25. hprint(hout, "Content-Type: text/html\r\n");
  26. hprint(hout, "Allow: %s\r\n", allowed);
  27. hprint(hout, "Content-Length: %d\r\n", n);
  28. if(c->head.closeit)
  29. hprint(hout, "Connection: close\r\n");
  30. else if(!http11(c))
  31. hprint(hout, "Connection: Keep-Alive\r\n");
  32. hprint(hout, "\r\n");
  33. if(strcmp(c->req.meth, "HEAD") != 0)
  34. hwrite(hout, c->xferbuf, n);
  35. if(c->replog)
  36. c->replog(c, "Reply: 405 Method Not Allowed\nReason: Method Not Allowed\n");
  37. return hflush(hout);
  38. }