Skip to content

Commit

Permalink
lib: redirect handling by protocol handler
Browse files Browse the repository at this point in the history
Adds a `follow()` callback to protocol handlers, so they may decide how
to act on a `newurl` after a request has been done. This is optional.

This moves the HTTP code for handling redirects from multi.c to http.c
where it should be. If we ever add a protocol with its own logic, it
would install its own follow function.

Closes curl#16075
  • Loading branch information
icing authored and bagder committed Jan 24, 2025
1 parent e83818c commit 1213c31
Show file tree
Hide file tree
Showing 24 changed files with 347 additions and 292 deletions.
6 changes: 6 additions & 0 deletions lib/curl_rtmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const struct Curl_handler Curl_handler_rtmp = {
ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
ZERO_NULL, /* follow */
PORT_RTMP, /* defport */
CURLPROTO_RTMP, /* protocol */
CURLPROTO_RTMP, /* family */
Expand All @@ -109,6 +110,7 @@ const struct Curl_handler Curl_handler_rtmpt = {
ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
ZERO_NULL, /* follow */
PORT_RTMPT, /* defport */
CURLPROTO_RTMPT, /* protocol */
CURLPROTO_RTMPT, /* family */
Expand All @@ -133,6 +135,7 @@ const struct Curl_handler Curl_handler_rtmpe = {
ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
ZERO_NULL, /* follow */
PORT_RTMP, /* defport */
CURLPROTO_RTMPE, /* protocol */
CURLPROTO_RTMPE, /* family */
Expand All @@ -157,6 +160,7 @@ const struct Curl_handler Curl_handler_rtmpte = {
ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
ZERO_NULL, /* follow */
PORT_RTMPT, /* defport */
CURLPROTO_RTMPTE, /* protocol */
CURLPROTO_RTMPTE, /* family */
Expand All @@ -181,6 +185,7 @@ const struct Curl_handler Curl_handler_rtmps = {
ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
ZERO_NULL, /* follow */
PORT_RTMPS, /* defport */
CURLPROTO_RTMPS, /* protocol */
CURLPROTO_RTMP, /* family */
Expand All @@ -205,6 +210,7 @@ const struct Curl_handler Curl_handler_rtmpts = {
ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
ZERO_NULL, /* follow */
PORT_RTMPS, /* defport */
CURLPROTO_RTMPTS, /* protocol */
CURLPROTO_RTMPT, /* family */
Expand Down
1 change: 1 addition & 0 deletions lib/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const struct Curl_handler Curl_handler_dict = {
ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
ZERO_NULL, /* follow */
PORT_DICT, /* defport */
CURLPROTO_DICT, /* protocol */
CURLPROTO_DICT, /* family */
Expand Down
1 change: 1 addition & 0 deletions lib/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const struct Curl_handler Curl_handler_file = {
ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
ZERO_NULL, /* follow */
0, /* defport */
CURLPROTO_FILE, /* protocol */
CURLPROTO_FILE, /* family */
Expand Down
2 changes: 2 additions & 0 deletions lib/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ const struct Curl_handler Curl_handler_ftp = {
ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
ZERO_NULL, /* follow */
PORT_FTP, /* defport */
CURLPROTO_FTP, /* protocol */
CURLPROTO_FTP, /* family */
Expand Down Expand Up @@ -282,6 +283,7 @@ const struct Curl_handler Curl_handler_ftps = {
ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
ZERO_NULL, /* follow */
PORT_FTPS, /* defport */
CURLPROTO_FTPS, /* protocol */
CURLPROTO_FTP, /* family */
Expand Down
2 changes: 2 additions & 0 deletions lib/gopher.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const struct Curl_handler Curl_handler_gopher = {
ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
ZERO_NULL, /* follow */
PORT_GOPHER, /* defport */
CURLPROTO_GOPHER, /* protocol */
CURLPROTO_GOPHER, /* family */
Expand All @@ -104,6 +105,7 @@ const struct Curl_handler Curl_handler_gophers = {
ZERO_NULL, /* write_resp_hd */
ZERO_NULL, /* connection_check */
ZERO_NULL, /* attach connection */
ZERO_NULL, /* follow */
PORT_GOPHER, /* defport */
CURLPROTO_GOPHERS, /* protocol */
CURLPROTO_GOPHER, /* family */
Expand Down
Loading

0 comments on commit 1213c31

Please sign in to comment.