options.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. options.c -- Options and Trace handler
  3. Copyright (c) All Rights Reserved. See details at the end of the file.
  4. */
  5. /********************************* Includes ***********************************/
  6. #include "goahead.h"
  7. /*********************************** Code *************************************/
  8. /*
  9. Handle OPTIONS and TRACE methods.
  10. Return true to indicate the request was handled, even for errors.
  11. */
  12. static bool optionsHandler(Webs *wp)
  13. {
  14. assert(wp);
  15. #if !ME_GOAHEAD_STEALTH
  16. if (smatch(wp->method, "OPTIONS")) {
  17. websSetStatus(wp, HTTP_CODE_OK);
  18. websWriteHeaders(wp, 0, 0);
  19. websWriteHeader(wp, "Allow", "DELETE,GET,HEAD,OPTIONS,POST,PUT,TRACE");
  20. websWriteEndHeaders(wp);
  21. websDone(wp);
  22. return 1;
  23. } else if (smatch(wp->method, "TRACE")) {
  24. websSetStatus(wp, HTTP_CODE_OK);
  25. websWriteHeaders(wp, 0, 0);
  26. websWriteEndHeaders(wp);
  27. websWrite(wp, "%s %s %s\r\n", wp->method, wp->url, wp->protoVersion);
  28. websDone(wp);
  29. return 1;
  30. }
  31. #endif
  32. websResponse(wp, HTTP_CODE_NOT_ACCEPTABLE, "Unsupported method");
  33. return 1;
  34. }
  35. PUBLIC int websOptionsOpen()
  36. {
  37. websDefineHandler("options", 0, optionsHandler, 0, 0);
  38. return 0;
  39. }
  40. /*
  41. Copyright (c) Embedthis Software. All Rights Reserved.
  42. This software is distributed under commercial and open source licenses.
  43. You may use the Embedthis GoAhead open source license or you may acquire
  44. a commercial license from Embedthis Software. You agree to be fully bound
  45. by the terms of either license. Consult the LICENSE.md distributed with
  46. this software for full details and other copyrights.
  47. */