Advertisement
Snuggledash

Polipo: Add support for OPTIONS method

Oct 30th, 2014
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.42 KB | None | 0 0
  1. --- a/client.c
  2. +++ b/client.c
  3. @@ -739,7 +739,7 @@ httpClientRequest
  4.  
  5.      if(body_len < 0) {
  6.          if(request->method == METHOD_GET || request->method == METHOD_HEAD ||
  7. -           request->method == METHOD_POST)
  8. +           request->method == METHOD_POST || request->method == METHOD_OPTIONS)
  9.              body_len = 0;
  10.      }
  11.      connection->bodylen = body_len;
  12. @@ -868,7 +868,8 @@ httpClientRequestContinue
  13.          httpLocalRequest :
  14.          httpServerRequest;
  15.  
  16. -    if(request->method == METHOD_POST || request->method == METHOD_PUT) {
  17. +    if(request->method == METHOD_POST || request->method == METHOD_PUT
  18. +       || request->method == METHOD_OPTIONS) {
  19.          do {
  20.              object = findObject(OBJECT_HTTP, url->string, url->length);
  21.              if(object) {
  22. diff --git a/http.h b/http.h
  23. index 2a06a5a..3771421 100644
  24. --- a/http.h
  25. +++ b/http.h
  26. @@ -105,6 +105,7 @@ typedef struct _HTTPConnection {
  27.  #define METHOD_CONNECT 3
  28.  #define METHOD_POST 4
  29.  #define METHOD_PUT 5
  30. +#define METHOD_OPTIONS 6
  31.  
  32.  #define REQUEST_SIDE(request) ((request)->method >= METHOD_POST)
  33.  
  34. diff --git a/http_parse.c b/http_parse.c
  35. index a5940ff..20f376a 100644
  36. --- a/http_parse.c
  37. +++ b/http_parse.c
  38. @@ -417,6 +417,8 @@ httpParseClientFirstLine
  39.          method = METHOD_PUT;
  40.      else if(y == x + 7 && memcmp(buf + x, "CONNECT", 7) == 0)
  41.          method = METHOD_CONNECT;
  42. +    else if(y == x + 7 && memcmp(buf + x, "OPTIONS", 7) == 0)
  43. +        method = METHOD_OPTIONS;
  44.      else
  45.          method = METHOD_UNKNOWN;
  46.  
  47. diff --git a/polipo.texi b/polipo.texi
  48. index 3f3adf4..1a1b0e5 100644
  49. --- a/polipo.texi
  50. +++ b/polipo.texi
  51. @@ -305,10 +305,10 @@
  52.  resource with a different instance; it is typically used by web
  53.  publishing applications.
  54.  
  55. -@samp{POST} and @samp{PUT} requests are handled by Polipo pretty much
  56. -like @samp{GET} and @samp{HEAD}; however, for various reasons, some
  57. -precautions must be taken.  In particular, any cached data for the
  58. -resource they refer to must be discarded, and they can never be
  59. +@samp{POST}, @samp{PUT} and @samp{OPTIONS} requests are handled by
  60. +Polipo pretty much like @samp{GET} and @samp{HEAD}; however, for various
  61. +reasons, some precautions must be taken.  In particular, any cached data
  62. +for the resource they refer to must be discarded, and they can never be
  63.  pipelined.
  64.  
  65.  Finally, HTTP/1.1 includes a convenient backdoor with the
  66. @@ -316,7 +316,7 @@
  67.  @ref{Tunnelling connections}.
  68.  
  69.  Polipo does not currently handle the more exotic methods such as
  70. -@samp{OPTIONS} and @samp{PROPFIND}.
  71. +@samp{PROPFIND}.
  72.  
  73.  @node Running, Network, Background, Top
  74.  @chapter Running Polipo
  75. diff --git a/server.c b/server.c
  76. index e445d53..3e697a1 100644
  77. --- a/server.c
  78. +++ b/server.c
  79. @@ -467,7 +467,8 @@ httpMakeServerRequest
  80.              return 1;
  81.          }
  82.      } else if(expectContinue >= 2 && server->version == HTTP_11) {
  83. -        if(request->method == METHOD_POST || request->method == METHOD_PUT)
  84. +        if(request->method == METHOD_POST || request->method == METHOD_PUT
  85. +           || request->method == METHOD_OPTIONS)
  86.              request->flags |= REQUEST_WAIT_CONTINUE;
  87.      }
  88.  
  89. @@ -1593,6 +1594,7 @@ httpWriteRequest
  90.      case METHOD_HEAD: m = "HEAD"; break;
  91.      case METHOD_POST: m = "POST"; break;
  92.      case METHOD_PUT: m = "PUT"; break;
  93. +    case METHOD_OPTIONS: m = "OPTIONS"; break;
  94.      default: abort();
  95.      }
  96.      n = snnprintf(connection->reqbuf, n, bufsize, "%s ", m);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement