~ubuntu-branches/ubuntu/saucy/lighttpd/saucy

« back to all changes in this revision

Viewing changes to src/mod_proxy.c

  • Committer: Package Import Robot
  • Author(s): Lorenzo De Liso
  • Date: 2012-12-06 17:54:59 UTC
  • mfrom: (6.1.20 sid)
  • Revision ID: package-import@ubuntu.com-20121206175459-aq6vz5xa9fa202jw
Tags: 1.4.31-3ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: libgamin-dev rather than libfam-dev to fix startup warning.
  - debian/index.html: s/Debian/Ubuntu/g branding on the default page.
  - Added a UFW profile set:
    + debian/lighttpd.dirs: added etc/ufw/applications.d
    + debian/rules: install the ufw profile.
    + debian/control: Suggests on ufw.
  - Add lighttpd-dev package:
    + debian/control: Added lighttpd-dev package; Build-depends on
      automake, libtool
    + debian/lighttpd-dev.install: Added.
  - debian/rules: Add override_dh_installinit to set "defaults 91 09" to not
    start before apache2 but in the same runlevel with the same priority.
  - debian/patches/build-dev-package.patch: Updated
  - debian/lighttpd.conf: Comment 'use-ipv6.pl' by default, which causes
    failure to bind port in ipv4
* debian/index.html: corrected BTS Ubuntu link for lighttpd

Show diffs side-by-side

added added

removed removed

Lines of Context:
724
724
                                con->file_started = 1;
725
725
                                if (blen) {
726
726
                                        http_chunk_append_mem(srv, con, c + 4, blen + 1);
727
 
                                        joblist_append(srv, con);
728
727
                                }
729
728
                                hctx->response->used = 0;
 
729
                                joblist_append(srv, con);
730
730
                        }
731
731
                } else {
732
732
                        http_chunk_append_mem(srv, con, hctx->response->ptr, hctx->response->used);
750
750
 
751
751
static handler_t proxy_write_request(server *srv, handler_ctx *hctx) {
752
752
        data_proxy *host= hctx->host;
753
 
        plugin_data *p    = hctx->plugin_data;
754
753
        connection *con   = hctx->remote_conn;
755
754
 
756
755
        int ret;
759
758
            (!host->host->used || !host->port)) return -1;
760
759
 
761
760
        switch(hctx->state) {
 
761
        case PROXY_STATE_CONNECT:
 
762
                /* wait for the connect() to finish */
 
763
 
 
764
                /* connect failed ? */
 
765
                if (-1 == hctx->fde_ndx) return HANDLER_ERROR;
 
766
 
 
767
                /* wait */
 
768
                return HANDLER_WAIT_FOR_EVENT;
 
769
 
 
770
                break;
 
771
 
762
772
        case PROXY_STATE_INIT:
763
773
#if defined(HAVE_IPV6) && defined(HAVE_INET_PTON)
764
774
                if (strstr(host->host->ptr,":")) {
786
796
                        return HANDLER_ERROR;
787
797
                }
788
798
 
789
 
                /* fall through */
790
 
 
791
 
        case PROXY_STATE_CONNECT:
792
 
                /* try to finish the connect() */
793
 
                if (hctx->state == PROXY_STATE_INIT) {
794
 
                        /* first round */
795
 
                        switch (proxy_establish_connection(srv, hctx)) {
796
 
                        case 1:
797
 
                                proxy_set_state(srv, hctx, PROXY_STATE_CONNECT);
798
 
 
799
 
                                /* connection is in progress, wait for an event and call getsockopt() below */
800
 
 
801
 
                                fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
802
 
 
803
 
                                return HANDLER_WAIT_FOR_EVENT;
804
 
                        case -1:
805
 
                                /* if ECONNREFUSED choose another connection -> FIXME */
806
 
                                hctx->fde_ndx = -1;
807
 
 
808
 
                                return HANDLER_ERROR;
809
 
                        default:
810
 
                                /* everything is ok, go on */
811
 
                                break;
812
 
                        }
813
 
                } else {
814
 
                        int socket_error;
815
 
                        socklen_t socket_error_len = sizeof(socket_error);
816
 
 
817
 
                        /* we don't need it anymore */
818
 
                        fdevent_event_del(srv->ev, &(hctx->fde_ndx), hctx->fd);
819
 
 
820
 
                        /* try to finish the connect() */
821
 
                        if (0 != getsockopt(hctx->fd, SOL_SOCKET, SO_ERROR, &socket_error, &socket_error_len)) {
822
 
                                log_error_write(srv, __FILE__, __LINE__, "ss",
823
 
                                                "getsockopt failed:", strerror(errno));
824
 
 
825
 
                                return HANDLER_ERROR;
826
 
                        }
827
 
                        if (socket_error != 0) {
828
 
                                log_error_write(srv, __FILE__, __LINE__, "ss",
829
 
                                                "establishing connection failed:", strerror(socket_error),
830
 
                                                "port:", hctx->host->port);
831
 
 
832
 
                                return HANDLER_ERROR;
833
 
                        }
834
 
                        if (p->conf.debug) {
835
 
                                log_error_write(srv, __FILE__, __LINE__,  "s", "proxy - connect - delayed success");
836
 
                        }
 
799
                switch (proxy_establish_connection(srv, hctx)) {
 
800
                case 1:
 
801
                        proxy_set_state(srv, hctx, PROXY_STATE_CONNECT);
 
802
 
 
803
                        /* connection is in progress, wait for an event and call getsockopt() below */
 
804
 
 
805
                        fdevent_event_set(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_OUT);
 
806
 
 
807
                        return HANDLER_WAIT_FOR_EVENT;
 
808
                case -1:
 
809
                        /* if ECONNREFUSED choose another connection -> FIXME */
 
810
                        hctx->fde_ndx = -1;
 
811
 
 
812
                        return HANDLER_ERROR;
 
813
                default:
 
814
                        /* everything is ok, go on */
 
815
                        proxy_set_state(srv, hctx, PROXY_STATE_PREPARE_WRITE);
 
816
                        break;
837
817
                }
838
818
 
839
 
                proxy_set_state(srv, hctx, PROXY_STATE_PREPARE_WRITE);
840
819
                /* fall through */
 
820
 
841
821
        case PROXY_STATE_PREPARE_WRITE:
842
822
                proxy_create_env(srv, hctx);
843
823
 
845
825
 
846
826
                /* fall through */
847
827
        case PROXY_STATE_WRITE:;
848
 
                ret = srv->network_backend_write(srv, con, hctx->fd, hctx->wb);
 
828
                ret = srv->network_backend_write(srv, con, hctx->fd, hctx->wb, MAX_WRITE_LIMIT);
849
829
 
850
830
                chunkqueue_remove_finished_chunks(hctx->wb);
851
831
 
1019
999
                                        "proxy: fdevent-out", hctx->state);
1020
1000
                }
1021
1001
 
1022
 
                if (hctx->state == PROXY_STATE_CONNECT ||
 
1002
                if (hctx->state == PROXY_STATE_CONNECT) {
 
1003
                        int socket_error;
 
1004
                        socklen_t socket_error_len = sizeof(socket_error);
 
1005
 
 
1006
                        /* we don't need it anymore */
 
1007
                        fdevent_event_del(srv->ev, &(hctx->fde_ndx), hctx->fd);
 
1008
                        hctx->fde_ndx = -1;
 
1009
 
 
1010
                        /* try to finish the connect() */
 
1011
                        if (0 != getsockopt(hctx->fd, SOL_SOCKET, SO_ERROR, &socket_error, &socket_error_len)) {
 
1012
                                log_error_write(srv, __FILE__, __LINE__, "ss",
 
1013
                                        "getsockopt failed:", strerror(errno));
 
1014
 
 
1015
                                joblist_append(srv, con);
 
1016
                                return HANDLER_FINISHED;
 
1017
                        }
 
1018
                        if (socket_error != 0) {
 
1019
                                log_error_write(srv, __FILE__, __LINE__, "ss",
 
1020
                                        "establishing connection failed:", strerror(socket_error),
 
1021
                                        "port:", hctx->host->port);
 
1022
 
 
1023
                                joblist_append(srv, con);
 
1024
                                return HANDLER_FINISHED;
 
1025
                        }
 
1026
                        if (p->conf.debug) {
 
1027
                                log_error_write(srv, __FILE__, __LINE__,  "s", "proxy - connect - delayed success");
 
1028
                        }
 
1029
 
 
1030
                        proxy_set_state(srv, hctx, PROXY_STATE_PREPARE_WRITE);
 
1031
                }
 
1032
 
 
1033
                if (hctx->state == PROXY_STATE_PREPARE_WRITE ||
1023
1034
                    hctx->state == PROXY_STATE_WRITE) {
1024
1035
                        /* we are allowed to send something out
1025
1036
                         *
1026
 
                         * 1. in a unfinished connect() call
 
1037
                         * 1. after a just finished connect() call
1027
1038
                         * 2. in a unfinished write() call (long POST request)
1028
1039
                         */
1029
1040
                        return mod_proxy_handle_subrequest(srv, con, p);