0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Caveman2のCookieの値を変えたい

Last updated at Posted at 2015-01-04

###やりたいこと###
CookieのNameと値を変えたり,httponlytにしたりしたい。

###app.lisp###
とりあえずapp.lispbuilder内部の<clack-middleware-session>が,外部からいじれる部分だろうと思って<clack-middleware-session>をsuperclassとしたclassを定義してみました。

(defclass <myapp-clack-session-state-cookie> (<clack-session-state-cookie>)
  ((session-key :initform :myapp.session
		:accessor session-key)
   (secure :initform nil
	   :accessor secure)
   (httponly :initform  t
	     :accessor httponly)))

(defclass <myapp-clack-middleware-session> (<clack-middleware-session>)
  ((state :initform (make-instance '<myapp-clack-session-state-cookie>)
	  :accessor state)))

(builder
 (<clack-middleware-static>
  :path (lambda (path)
          (if (ppcre:scan "^(?:/images/|/css/|/js/|/robot\\.txt$|/favicon.ico$)" path)
              path
              nil))
  :root *static-directory*)
 (if (productionp)
     nil
     (make-instance '<clack-middleware-accesslog>))
 (if (getf (config) :error-log)
     (make-instance '<clack-middleware-backtrace>
                    :output (getf (config) :error-log))
     nil)
;; <clack-middleware-session>
 <myapp-clack-middleware-session>  ;;ここだけ書き換え
 (if (productionp)
     nil
     (lambda (app)
       (lambda (env)
         (let ((datafly:*trace-sql* t))
           (call app env)))))
 *web*)

なんてしてみたものの変化なし。

試しに直にclack.session.statesession-keyの値を書き換えたらcookieの値も変わりました。

(defclass <clack-session-state> ()
     ((session-key :type keyword
                   :initarg :session-key
                   :initform :myapp.session ;; :clack.session
                   :accessor session-key)
      (sid-generator :type function
                     :initarg :sid-generator
                     :initform
                     #'(lambda (&rest args)
                         @ignore args
                         (clack.util:generate-random-id))
                     :accessor sid-generator)
      (sid-validator :type function
                     :initarg :sid-validator
                     :initform
                     #'(lambda (sid)
                         (not (null (ppcre:scan "\\A[0-9a-f]{40}\\Z" sid))))
                     :accessor sid-validator)))

=> MYAPP.SESSION e3d5067aceb466a9b01a04deb2170137c8bec3b0

CLOS自体も大分忘れてるので混乱中…
とりあえずもうちょっとソース読み込みます…

###追記(2015-01-05-1310)###
builderを以下の様に書き換えたらできました。

(builder
 (<clack-middleware-static>
  :path (lambda (path)
          (if (ppcre:scan "^(?:/images/|/css/|/js/|/robot\\.txt$|/favicon.ico$)" path)
              path
              nil))
  :root *static-directory*)
 (if (productionp)
     nil
     (make-instance '<clack-middleware-accesslog>))
 (if (getf (config) :error-log)
     (make-instance '<clack-middleware-backtrace>
                    :output (getf (config) :error-log))
     nil)
 ;; <clack-middleware-session>
 (<myapp-clack-middleware-session>
  :state (make-instance '<myapp-clack-session-state-cookie>))
 ;; <myapp-clack-middleware-session>
 (if (productionp)
     nil
     (lambda (app)
       (lambda (env)
         (let ((datafly:*trace-sql* t))
           (call app env)))))
 *web*)

<myapp-clack-middleware-session>:initformが効いてない??

とりあえず出来たけど疑問が残ってます。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?