unallowed.c 980 B

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