Browse Source

Remove the onrequest hook

It was redundant with middlewares. Allows us to save a few operations
for every incoming requests.
Loïc Hoguin 10 years ago
parent
commit
aa4d86b81f

+ 0 - 3
ROADMAP.md

@@ -45,9 +45,6 @@ the halt tuple. The error tuple will therefore be removed.
 
 ### Hooks
 
-The `onrequest` hook will be removed. It can easily be replaced
-by a middleware.
-
 The interface of the `onresponse` hook will change. There has
 been a number of issues and added complexity with the current
 interface that warrant fixing. The main problem is that the

+ 5 - 43
doc/src/guide/hooks.ezdoc

@@ -1,45 +1,7 @@
 ::: Hooks
 
-Cowboy provides two hooks. `onrequest` is called once the request
-line and headers have been received. `onresponse` is called just
-before sending the response.
-
-:: Onrequest
-
-The `onrequest` hook is called as soon as Cowboy finishes fetching
-the request headers. It occurs before any other processing, including
-routing. It can be used to perform any modification needed on the
-request object before continuing with the processing. If a reply is
-sent inside this hook, then Cowboy will move on to the next request,
-skipping any subsequent handling.
-
-This hook is a function that takes a request object as argument,
-and returns a request object. This function MUST NOT crash. Cowboy
-will not send any reply if a crash occurs in this function.
-
-You can specify the `onrequest` hook when creating the listener,
-inside the request options.
-
-``` erlang
-cowboy:start_http(my_http_listener, 100,
-    [{port, 8080}],
-    [
-        {env, [{dispatch, Dispatch}]},
-        {onrequest, fun ?MODULE:debug_hook/1}
-    ]
-).
-```
-
-The following hook function prints the request object everytime a
-request is received. This can be useful for debugging, for example.
-
-``` erlang
-debug_hook(Req) ->
-    erlang:display(Req),
-    Req.
-```
-
-Make sure to always return the last request object obtained.
+Hooks allow the user to customize Cowboy's behavior during specific
+operations.
 
 :: Onresponse
 
@@ -48,9 +10,9 @@ to the socket. It can be used for the purposes of logging responses,
 or for modifying the response headers or body. The best example is
 providing custom error pages.
 
-Note that like the `onrequest` hook, this function MUST NOT crash.
-Cowboy may or may not send a reply if this function crashes. If a reply
-is sent, the hook MUST explicitly provide all headers that are needed.
+Note that this function MUST NOT crash. Cowboy may or may not send a
+reply if this function crashes. If a reply is sent, the hook MUST
+explicitly provide all headers that are needed.
 
 You can specify the `onresponse` hook when creating the listener.
 

BIN
doc/src/guide/http_req_resp.png


+ 68 - 106
doc/src/guide/http_req_resp.svg

@@ -65,15 +65,15 @@
      inkscape:pageopacity="1"
      inkscape:pageshadow="2"
      inkscape:zoom="1.4142136"
-     inkscape:cx="229.71447"
+     inkscape:cx="82.28271"
      inkscape:cy="764.83183"
      inkscape:document-units="px"
      inkscape:current-layer="layer1"
      showgrid="false"
-     inkscape:window-width="1920"
-     inkscape:window-height="1014"
+     inkscape:window-width="2560"
+     inkscape:window-height="1402"
      inkscape:window-x="0"
-     inkscape:window-y="33"
+     inkscape:window-y="38"
      inkscape:window-maximized="1"
      inkscape:snap-global="true"
      showguides="true">
@@ -93,7 +93,7 @@
         <dc:format>image/svg+xml</dc:format>
         <dc:type
            rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
-        <dc:title></dc:title>
+        <dc:title />
       </cc:Work>
     </rdf:RDF>
   </metadata>
@@ -101,42 +101,28 @@
      inkscape:label="Layer 1"
      inkscape:groupmode="layer"
      id="layer1">
-    <use
-       x="0"
-       y="0"
-       xlink:href="#path5757"
-       id="use5779"
-       transform="matrix(0.59961275,-0.80029029,0.80029029,0.59961275,-103.8895,437.48518)"
-       width="744.09448"
-       height="1052.3622"
-       inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
+    <path
+       inkscape:export-ydpi="89.926643"
        inkscape:export-xdpi="89.926643"
-       inkscape:export-ydpi="89.926643" />
-    <use
-       x="0"
-       y="0"
-       xlink:href="#path5757"
-       id="use5777"
-       transform="matrix(0.92125726,-0.38895379,0.38895379,0.92125726,-85.14742,176.0134)"
-       width="744.09448"
-       height="1052.3622"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
-       inkscape:export-xdpi="89.926643"
-       inkscape:export-ydpi="89.926643" />
-    <path
-       style="fill:none;stroke:#6d8e41;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:2, 4;stroke-dashoffset:0"
-       d="m 188.5,231.36218 187,79"
-       id="path5757"
        inkscape:connector-curvature="0"
-       inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
+       id="use5779"
+       d="M 194.29441,340.67017 369.64493,238.3853"
+       style="fill:none;stroke:#6d8e41;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:2, 4;stroke-dashoffset:0" />
+    <path
+       inkscape:export-ydpi="89.926643"
        inkscape:export-xdpi="89.926643"
-       inkscape:export-ydpi="89.926643" />
+       inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
+       inkscape:connector-curvature="0"
+       id="use5777"
+       d="m 178.49877,231.1517 203.00246,0.045"
+       style="fill:none;stroke:#6d8e41;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:1.99999999, 3.99999998;stroke-dashoffset:0" />
     <use
        x="0"
        y="0"
        xlink:href="#g5650"
        id="use5753"
-       transform="translate(475.11201,-33.017248)"
+       transform="translate(475.11201,-117.70525)"
        width="744.09448"
        height="1052.3622"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
@@ -154,12 +140,12 @@
        inkscape:export-xdpi="89.926643"
        inkscape:export-ydpi="89.926643" />
     <rect
-       style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:2.44279908999999984;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
+       style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:2.44279909;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
        id="rect5367"
        width="207.05719"
        height="171.55719"
        x="43.721401"
-       y="360.88528"
+       y="276.1973"
        rx="11.072577"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
        inkscape:export-xdpi="89.926643"
@@ -169,34 +155,38 @@
        y="0"
        xlink:href="#g5650"
        id="use5654"
-       transform="translate(205.03261,53.351708)"
-       width="744.09448"
-       height="1052.3622"
-       inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
-       inkscape:export-xdpi="89.926643"
-       inkscape:export-ydpi="89.926643" />
-    <use
-       x="0"
-       y="0"
-       xlink:href="#use5656"
-       id="use5658"
-       transform="translate(0,-86.13396)"
+       transform="translate(205.03261,-31.336292)"
        width="744.09448"
        height="1052.3622"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
        inkscape:export-xdpi="89.926643"
        inkscape:export-ydpi="89.926643" />
-    <use
-       x="0"
-       y="0"
-       xlink:href="#use5658"
+    <g
        id="use5660"
-       transform="translate(0,-87.519558)"
-       width="744.09448"
-       height="1052.3622"
-       inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
-       inkscape:export-xdpi="89.926643"
-       inkscape:export-ydpi="89.926643" />
+       transform="translate(205.03261,-207.5)">
+      <path
+         style="opacity:0.8;fill:none;stroke:#6d8e41;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+         d="m -57.78256,351.41962 0,52.3259"
+         id="path3051"
+         inkscape:connector-curvature="0" />
+      <path
+         sodipodi:type="star"
+         style="opacity:0.8;fill:#6d8e41;fill-opacity:1;fill-rule:nonzero;stroke:#6d8e41;stroke-width:0;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
+         id="path3053"
+         sodipodi:sides="3"
+         sodipodi:cx="-222.73865"
+         sodipodi:cy="415.25897"
+         sodipodi:r1="14.849242"
+         sodipodi:r2="7.4246211"
+         sodipodi:arg1="1.5707963"
+         sodipodi:arg2="2.6179939"
+         inkscape:flatsided="true"
+         inkscape:rounded="0"
+         inkscape:randomized="0"
+         d="m -222.73865,430.10821 -12.85982,-22.27386 25.71964,0 z"
+         inkscape:transform-center-y="2.1823437"
+         transform="matrix(0.58787746,0,0,0.58787746,73.160466,163.35774)" />
+    </g>
     <use
        x="0"
        y="0"
@@ -287,17 +277,6 @@
     <use
        x="0"
        y="0"
-       xlink:href="#rect5273"
-       id="use5335"
-       transform="translate(318.97597,268.31614)"
-       width="744.09448"
-       height="1052.3622"
-       inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
-       inkscape:export-xdpi="89.926643"
-       inkscape:export-ydpi="89.926643" />
-    <use
-       x="0"
-       y="0"
        xlink:href="#rect5273-22"
        id="use5355"
        transform="translate(318.97592,-176.5)"
@@ -328,23 +307,20 @@
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
        inkscape:export-xdpi="89.926643"
        inkscape:export-ydpi="89.926643" />
-    <use
-       x="0"
-       y="0"
-       xlink:href="#use5335"
+    <rect
+       rx="15"
+       y="386.37247"
+       x="94.955292"
+       height="36.392323"
+       width="104.5895"
        id="use5363"
-       transform="translate(0,173.33215)"
-       width="744.09448"
-       height="1052.3622"
-       inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
-       inkscape:export-xdpi="89.926643"
-       inkscape:export-ydpi="89.926643" />
+       style="fill:#d1f2a5;fill-opacity:1;fill-rule:nonzero;stroke:#a9ca7d;stroke-width:3;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
     <use
        x="0"
        y="0"
        xlink:href="#use5361"
        id="use5365"
-       transform="translate(0,173.66424)"
+       transform="translate(0,88.97624)"
        width="744.09448"
        height="1052.3622"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
@@ -393,7 +369,7 @@
        xml:space="preserve"
        style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
        x="146.53125"
-       y="407.78009"
+       y="323.0921"
        id="text5371-5"
        sodipodi:linespacing="125%"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
@@ -402,7 +378,7 @@
          sodipodi:role="line"
          id="tspan5373-0"
          x="146.53125"
-         y="407.78009">router</tspan></text>
+         y="323.0921">router</tspan></text>
     <text
        xml:space="preserve"
        style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
@@ -417,22 +393,8 @@
     <text
        xml:space="preserve"
        style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
-       x="147.00391"
-       y="321.39722"
-       id="text5371-2-3"
-       sodipodi:linespacing="125%"
-       inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
-       inkscape:export-xdpi="89.926643"
-       inkscape:export-ydpi="89.926643"><tspan
-         sodipodi:role="line"
-         id="tspan5373-6-7"
-         x="147.00391"
-         y="321.39722">onrequest</tspan></text>
-    <text
-       xml:space="preserve"
-       style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
        x="146.53125"
-       y="495.07318"
+       y="410.38519"
        id="text5371-2-3-0"
        sodipodi:linespacing="125%"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
@@ -441,11 +403,11 @@
          sodipodi:role="line"
          id="tspan5373-6-7-3"
          x="146.53125"
-         y="495.07318">handler</tspan></text>
+         y="410.38519">handler</tspan></text>
     <text
        xml:space="preserve"
        style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
-       x="-446.99591"
+       x="-362.30792"
        y="63.078125"
        id="text5371-2-3-0-7"
        sodipodi:linespacing="125%"
@@ -455,7 +417,7 @@
        inkscape:export-ydpi="89.926643"><tspan
          sodipodi:role="line"
          id="tspan5373-6-7-3-9"
-         x="-446.99591"
+         x="-362.30792"
          y="63.078125">middlewares</tspan></text>
     <text
        xml:space="preserve"
@@ -487,7 +449,7 @@
        y="0"
        xlink:href="#rect5273-7"
        id="use5668"
-       transform="translate(589.05532,207.03588)"
+       transform="translate(589.05532,122.34788)"
        width="744.09448"
        height="1052.3622"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
@@ -498,7 +460,7 @@
        y="0"
        xlink:href="#rect5273"
        id="use5670"
-       transform="translate(589.05538,355.27934)"
+       transform="translate(589.05538,270.59134)"
        width="744.09448"
        height="1052.3622"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
@@ -509,7 +471,7 @@
        y="0"
        xlink:href="#use5355"
        id="use5672"
-       transform="translate(270.07946,434.91762)"
+       transform="translate(270.07946,350.22962)"
        width="744.09448"
        height="1052.3622"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
@@ -520,7 +482,7 @@
        y="0"
        xlink:href="#text5371-4-0"
        id="use5674"
-       transform="translate(270.29655,434.16115)"
+       transform="translate(270.29655,349.47315)"
        width="744.09448"
        height="1052.3622"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
@@ -530,7 +492,7 @@
        xml:space="preserve"
        style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#77823c;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
        x="417.30829"
-       y="321.42792"
+       y="236.73991"
        id="text5371-9"
        sodipodi:linespacing="125%"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
@@ -539,12 +501,12 @@
          sodipodi:role="line"
          id="tspan5373-57"
          x="417.30829"
-         y="321.42792">reply</tspan></text>
+         y="236.73991">reply</tspan></text>
     <text
        xml:space="preserve"
        style="font-size:16px;font-style:normal;font-weight:normal;text-align:center;line-height:125%;letter-spacing:0px;word-spacing:0px;text-anchor:middle;fill:#6d8e41;fill-opacity:1;stroke:none;font-family:Sans;-inkscape-font-specification:Sans"
        x="417.30829"
-       y="407.77994"
+       y="323.09195"
        id="text5371-2-0"
        sodipodi:linespacing="125%"
        inkscape:export-filename="/home/essen/extend/cowboy/guide/http_req_resp.png"
@@ -553,6 +515,6 @@
          sodipodi:role="line"
          id="tspan5373-6-8"
          x="417.30829"
-         y="407.77994">onresponse</tspan></text>
+         y="323.09195">onresponse</tspan></text>
   </g>
 </svg>

+ 0 - 9
doc/src/manual/cowboy.ezdoc

@@ -25,15 +25,6 @@ A binary status can be used to set a custom message.
 
 HTTP version.
 
-: onrequest_fun() = fun((cowboy_req:req()) -> cowboy_req:req())
-
-Fun called immediately after receiving a request.
-
-It can perform any operation on the Req object, including
-reading the request body or replying. If a reply is sent,
-the processing of the request ends here, before any middleware
-is executed.
-
 : onresponse_fun() = fun((http_status(), http_headers(),
 	iodata(), cowboy_req:req()) -> cowboy_req:req())
 

+ 0 - 5
doc/src/manual/cowboy_protocol.ezdoc

@@ -14,7 +14,6 @@ as a Ranch protocol.
 	| {max_keepalive, non_neg_integer()}
 	| {max_request_line_length, non_neg_integer()}
 	| {middlewares, [module()]}
-	| {onrequest, cowboy:onrequest_fun()}
 	| {onresponse, cowboy:onresponse_fun()}
 	| {timeout, timeout()}]
 
@@ -67,10 +66,6 @@ Maximum length of the request line.
 
 List of middlewares to execute for every requests.
 
-: onrequest (undefined)
-
-Fun called every time a request is received.
-
 : onresponse (undefined)
 
 Fun called every time a response is sent.

+ 2 - 4
doc/src/manual/cowboy_req.ezdoc

@@ -126,8 +126,7 @@ Types:
 Return the requested URL excluding the path component.
 
 This function will always return `undefined` until the
-`cowboy_router` middleware has been executed. This includes
-the `onrequest` hook.
+`cowboy_router` middleware has been executed.
 
 : match_cookies(Req, Fields) -> Map
 
@@ -371,8 +370,7 @@ Types:
 Return the requested URL.
 
 This function will always return `undefined` until the
-`cowboy_router` middleware has been executed. This includes
-the `onrequest` hook.
+`cowboy_router` middleware has been executed.
 
 : version(Req) -> Version
 

+ 0 - 5
doc/src/manual/cowboy_spdy.ezdoc

@@ -6,7 +6,6 @@ The `cowboy_spdy` module implements SPDY/3 as a Ranch protocol.
 
 : opts() = [{env, cowboy_middleware:env()}
 	| {middlewares, [module()]}
-	| {onrequest, cowboy:onrequest_fun()}
 	| {onresponse, cowboy:onresponse_fun()}]
 
 Configuration for the SPDY protocol handler.
@@ -30,10 +29,6 @@ Initial middleware environment.
 
 List of middlewares to execute for every requests.
 
-: onrequest (undefined)
-
-Fun called every time a request is received.
-
 : onresponse (undefined)
 
 Fun called every time a response is sent.

+ 0 - 3
src/cowboy.erl

@@ -34,9 +34,6 @@
 -type http_version() :: 'HTTP/1.1' | 'HTTP/1.0'.
 -export_type([http_version/0]).
 
--type onrequest_fun() :: fun((Req) -> Req).
--export_type([onrequest_fun/0]).
-
 -type onresponse_fun() ::
 	fun((http_status(), http_headers(), iodata(), Req) -> Req).
 -export_type([onresponse_fun/0]).

+ 2 - 20
src/cowboy_protocol.erl

@@ -32,7 +32,6 @@
 	| {max_keepalive, non_neg_integer()}
 	| {max_request_line_length, non_neg_integer()}
 	| {middlewares, [module()]}
-	| {onrequest, cowboy:onrequest_fun()}
 	| {onresponse, cowboy:onresponse_fun()}
 	| {timeout, timeout()}].
 -export_type([opts/0]).
@@ -43,7 +42,6 @@
 	middlewares :: [module()],
 	compress :: boolean(),
 	env :: cowboy_middleware:env(),
-	onrequest :: undefined | cowboy:onrequest_fun(),
 	onresponse = undefined :: undefined | cowboy:onresponse_fun(),
 	max_empty_lines :: non_neg_integer(),
 	req_keepalive = 1 :: non_neg_integer(),
@@ -85,7 +83,6 @@ init(Ref, Socket, Transport, Opts) ->
 	MaxRequestLineLength = get_value(max_request_line_length, Opts, 4096),
 	Middlewares = get_value(middlewares, Opts, [cowboy_router, cowboy_handler]),
 	Env = [{listener, Ref}|get_value(env, Opts, [])],
-	OnRequest = get_value(onrequest, Opts, undefined),
 	OnResponse = get_value(onresponse, Opts, undefined),
 	Timeout = get_value(timeout, Opts, 5000),
 	ok = ranch:accept_ack(Ref),
@@ -95,8 +92,7 @@ init(Ref, Socket, Transport, Opts) ->
 		max_request_line_length=MaxRequestLineLength,
 		max_header_name_length=MaxHeaderNameLength,
 		max_header_value_length=MaxHeaderValueLength, max_headers=MaxHeaders,
-		onrequest=OnRequest, onresponse=OnResponse,
-		timeout=Timeout, until=until(Timeout)}, 0).
+		onresponse=OnResponse, timeout=Timeout, until=until(Timeout)}, 0).
 
 -spec until(timeout()) -> non_neg_integer() | infinity.
 until(infinity) ->
@@ -410,26 +406,12 @@ request(Buffer, State=#state{socket=Socket, transport=Transport,
 			Req = cowboy_req:new(Socket, Transport, Peer, Method, Path,
 				Query, Version, Headers, Host, Port, Buffer,
 				ReqKeepalive < MaxKeepalive, Compress, OnResponse),
-			onrequest(Req, State);
+			execute(Req, State);
 		{error, _} ->
 			%% Couldn't read the peer address; connection is gone.
 			terminate(State)
 	end.
 
-%% Call the global onrequest callback. The callback can send a reply,
-%% in which case we consider the request handled and move on to the next
-%% one. Note that since we haven't dispatched yet, we don't know the
-%% handler, host_info, path_info or bindings yet.
--spec onrequest(cowboy_req:req(), #state{}) -> ok.
-onrequest(Req, State=#state{onrequest=undefined}) ->
-	execute(Req, State);
-onrequest(Req, State=#state{onrequest=OnRequest}) ->
-	Req2 = OnRequest(Req),
-	case cowboy_req:get(resp_state, Req2) of
-		waiting -> execute(Req2, State);
-		_ -> next_request(Req2, State, ok)
-	end.
-
 -spec execute(cowboy_req:req(), #state{}) -> ok.
 execute(Req, State=#state{middlewares=Middlewares, env=Env}) ->
 	execute(Req, State, Env, Middlewares).

+ 7 - 20
src/cowboy_spdy.erl

@@ -24,7 +24,7 @@
 -export([system_code_change/4]).
 
 %% Internal request process.
--export([request_init/11]).
+-export([request_init/10]).
 -export([resume/5]).
 -export([reply/4]).
 -export([stream_reply/3]).
@@ -59,7 +59,6 @@
 	buffer = <<>> :: binary(),
 	middlewares,
 	env,
-	onrequest,
 	onresponse,
 	peer,
 	zdef,
@@ -70,7 +69,6 @@
 
 -type opts() :: [{env, cowboy_middleware:env()}
 	| {middlewares, [module()]}
-	| {onrequest, cowboy:onrequest_fun()}
 	| {onresponse, cowboy:onresponse_fun()}].
 -export_type([opts/0]).
 
@@ -97,13 +95,12 @@ init(Parent, Ref, Socket, Transport, Opts) ->
 	{ok, Peer} = Transport:peername(Socket),
 	Middlewares = get_value(middlewares, Opts, [cowboy_router, cowboy_handler]),
 	Env = [{listener, Ref}|get_value(env, Opts, [])],
-	OnRequest = get_value(onrequest, Opts, undefined),
 	OnResponse = get_value(onresponse, Opts, undefined),
 	Zdef = cow_spdy:deflate_init(),
 	Zinf = cow_spdy:inflate_init(),
 	ok = ranch:accept_ack(Ref),
 	loop(#state{parent=Parent, socket=Socket, transport=Transport,
-		middlewares=Middlewares, env=Env, onrequest=OnRequest,
+		middlewares=Middlewares, env=Env,
 		onresponse=OnResponse, peer=Peer, zdef=Zdef, zinf=Zinf}).
 
 loop(State=#state{parent=Parent, socket=Socket, transport=Transport,
@@ -257,11 +254,11 @@ handle_frame(State, {syn_stream, StreamID, AssocToStreamID,
 %% Erlang does not allow us to control the priority of processes
 %% so we ignore that value entirely.
 handle_frame(State=#state{middlewares=Middlewares, env=Env,
-		onrequest=OnRequest, onresponse=OnResponse, peer=Peer},
+		onresponse=OnResponse, peer=Peer},
 		{syn_stream, StreamID, _, IsFin, _, _,
 		Method, _, Host, Path, Version, Headers}) ->
 	Pid = spawn_link(?MODULE, request_init, [
-		{self(), StreamID}, Peer, OnRequest, OnResponse,
+		{self(), StreamID}, Peer, OnResponse,
 		Env, Middlewares, Method, Host, Path, Version, Headers
 	]),
 	new_child(State, StreamID, Pid, IsFin);
@@ -385,11 +382,10 @@ delete_child(Pid, State=#state{children=Children}) ->
 %% Request process.
 
 -spec request_init(socket(), {inet:ip_address(), inet:port_number()},
-		cowboy:onrequest_fun(), cowboy:onresponse_fun(),
-		cowboy_middleware:env(), [module()],
+		cowboy:onresponse_fun(), cowboy_middleware:env(), [module()],
 		binary(), binary(), binary(), binary(), [{binary(), binary()}])
 	-> ok.
-request_init(FakeSocket, Peer, OnRequest, OnResponse,
+request_init(FakeSocket, Peer, OnResponse,
 		Env, Middlewares, Method, Host, Path, Version, Headers) ->
 	{Host2, Port} = cow_http:parse_fullhost(Host),
 	{Path2, Qs} = cow_http:parse_fullpath(Path),
@@ -397,16 +393,7 @@ request_init(FakeSocket, Peer, OnRequest, OnResponse,
 	Req = cowboy_req:new(FakeSocket, ?MODULE, Peer,
 		Method, Path2, Qs, Version2, Headers,
 		Host2, Port, <<>>, true, false, OnResponse),
-	case OnRequest of
-		undefined ->
-			execute(Req, Env, Middlewares);
-		_ ->
-			Req2 = OnRequest(Req),
-			case cowboy_req:get(resp_state, Req2) of
-				waiting -> execute(Req2, Env, Middlewares);
-				_ -> ok
-			end
-	end.
+	execute(Req, Env, Middlewares).
 
 -spec execute(cowboy_req:req(), cowboy_middleware:env(), [module()])
 	-> ok.

+ 0 - 40
test/http_SUITE.erl

@@ -34,7 +34,6 @@ all() ->
 		{group, https},
 		{group, http_compress},
 		{group, https_compress},
-		{group, onrequest},
 		{group, onresponse},
 		{group, onresponse_capitalize},
 		{group, parse_host},
@@ -43,7 +42,6 @@ all() ->
 
 groups() ->
 	Tests = cowboy_test:all(?MODULE) -- [
-		onrequest, onrequest_reply, onrequest_hook,
 		onresponse_crash, onresponse_reply, onresponse_capitalize,
 		parse_host, set_env_dispatch
 	],
@@ -52,10 +50,6 @@ groups() ->
 		{https, [parallel], Tests},
 		{http_compress, [parallel], Tests},
 		{https_compress, [parallel], Tests},
-		{onrequest, [parallel], [
-			onrequest,
-			onrequest_reply
-		]},
 		{onresponse, [parallel], [
 			onresponse_crash,
 			onresponse_reply
@@ -98,15 +92,6 @@ init_per_group(Name = https_compress, Config) ->
 		{compress, true}
 	], Config);
 %% Most, if not all of these, should be in separate test suites.
-init_per_group(onrequest, Config) ->
-	{ok, _} = cowboy:start_http(onrequest, 100, [{port, 0}], [
-		{env, [{dispatch, init_dispatch(Config)}]},
-		{max_keepalive, 50},
-		{onrequest, fun do_onrequest_hook/1},
-		{timeout, 500}
-	]),
-	Port = ranch:get_port(onrequest),
-	[{type, tcp}, {port, Port}, {opts, []}|Config];
 init_per_group(onresponse, Config) ->
 	{ok, _} = cowboy:start_http(onresponse, 100, [{port, 0}], [
 		{env, [{dispatch, init_dispatch(Config)}]},
@@ -574,31 +559,6 @@ nc_rand(Config) ->
 nc_zero(Config) ->
 	do_nc(Config, "/dev/zero").
 
-onrequest(Config) ->
-	ConnPid = gun_open(Config),
-	Ref = gun:get(ConnPid, "/"),
-	{response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
-	{<<"server">>, <<"Serenity">>} = lists:keyfind(<<"server">>, 1, Headers),
-	{ok, <<"http_handler">>} = gun:await_body(ConnPid, Ref),
-	ok.
-
-onrequest_reply(Config) ->
-	ConnPid = gun_open(Config),
-	Ref = gun:get(ConnPid, "/?reply=1"),
-	{response, nofin, 200, Headers} = gun:await(ConnPid, Ref),
-	{<<"server">>, <<"Cowboy">>} = lists:keyfind(<<"server">>, 1, Headers),
-	{ok, <<"replied!">>} = gun:await_body(ConnPid, Ref),
-	ok.
-
-%% Hook for the above onrequest tests.
-do_onrequest_hook(Req) ->
-	case cowboy_req:match_qs(Req, [{reply, [], noreply}]) of
-		#{reply := noreply} ->
-			cowboy_req:set_resp_header(<<"server">>, <<"Serenity">>, Req);
-		_ ->
-			cowboy_req:reply(200, [], <<"replied!">>, Req)
-	end.
-
 onresponse_capitalize(Config) ->
 	Client = raw_open(Config),
 	ok = raw_send(Client, "GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"),