tailieunhanh - Mod_perl Recipes

Bạn có thể xác thực người dùng với cơ chế riêng của bạn (thay vì tiêu chuẩn này) nhưng vẫn làm cho Apache nghĩ rằng người sử dụng đã được chứng thực của cơ chế tiêu chuẩn. Đặt tên người dùng với: $ R- kết nối- người dùng ('username'); Bây giờ bạn có thể sử dụng thông tin này, ví dụ, trong quá trình khai thác gỗ, để bạn có thể có "của bạn tên người dùng" thông qua như thể nó đã được chuyển đến Apache thông qua xác thực HTTP | Page 753 Thursday November 18 2004 12 48 PM APPENDIX A mod_perl Recipes This appendix acts as a mini-cookbook for mod_perl. As we ve mentioned many times in this book the mod_perl mailing list is a terrific resource for anyone working with mod_perl. Many very useful code snippets and neat techniques have been posted to the mod_perl mailing list. In this appendix we present the techniques that you will find most useful in your day-to-day mod_perl programming. Emulating the Authentication Mechanism You can authenticate users with your own mechanism instead of the standard one but still make Apache think that the user was authenticated by the standard mechanism. Set the username with r- connection- user username Now you can use this information for example during logging so that you can have your username passed as if it was transmitted to Apache through HTTP authentication. Reusing Data from POST Requests What happens if you need to access the POSTed data more than once. For example suppose you need to reuse it in subsequent handlers of the same request POSTed data comes directly from the socket and at the low level data can be read from a socket only once. You have to store it to make it available for reuse. But what do you do with large multipart file uploads Because POSTed data is not all read in one clump it s a problem that s not easy to solve in a general way. A transparent way to do this is to switch the request method from POST to GET and store the POST data in the query string. The handler in Example A-1 does exactly that. 753 Page 754 Thursday November 18 2004 12 48 PM Example A-1. Apache package Apache POST2GET use Apache Constants qw M_GET OK DECLINED sub handler my r shift return DECLINED unless r- method eq POST r- args scalar r- content r- method GET r- method_number M_GET r- headers_in- unset Content-length return OK i In add PerlInitHandler Apache POST2GET or even this Limit POST PerlInitHandler Apache .

TỪ KHÓA LIÊN QUAN