当前位置:Gxlcms > html代码 > 304CORS_html/css_WEB-ITnose

304CORS_html/css_WEB-ITnose

时间:2021-07-01 10:21:17 帮助过:13人阅读

304响应, CORS问题: 没有 Access-Control-Allow-Origin 这个头信息时,以前次返回的200请求为准。

示例:可能已被删除
http://7af3zm.com1.z0.glb.clouddn.com/ajax_304_cors.html

附上源码:
html

	

clojure

(ns base-web.handler  (:require [compojure.core :refer :all]            [compojure.route :as route]            [ring.middleware.defaults :refer [wrap-defaults site-defaults]]            [clojure.pprint :as log]))(def my-route    (-> site-defaults        (assoc-in [:security :anti-forgery] false)        (assoc-in [:params] false)        ))(defn print-req [req]    (println )    (log/pprint my-route)    (log/pprint req)    (log/pprint (slurp (:body req)))    (println "done"))(defn access-200 [req]    (let [etag "e-access-200"]    (if (not= etag (get-in req [:headers "if-none-match"]))        (do (println "200")            {:status 200,             :headers {"Content-Type" "application/json", "Access-Control-Allow-Origin" "*", "ETag" etag}             :body "{\"success\":true, \"frame\": \"ring\"}"})         (do (println "304")            {:status 304,                :headers {"Content-Type" "application/json", "ETag" etag}}))))(defn access-non [req]    (let [etag "e-access-non"]    (if (not= etag (get-in req [:headers "if-none-match"]))        (do (println "200")            {:status 200,             :headers {"Content-Type" "application/json", "ETag" etag}             :body "{\"success\":true, \"frame\": \"ring\"}"})         (do (println "304")            {:status 304,                :headers {"Content-Type" "application/json", "ETag" etag}}))))(defn access [req]    (let [etag "e-access"]    (if (not= etag (get-in req [:headers "if-none-match"]))        (do (println "200")            {:status 200,             :headers {"Content-Type" "application/json", "Access-Control-Allow-Origin" "*", "ETag" etag}             :body "{\"success\":true, \"frame\": \"ring\"}"})         (do (println "304")            {:status 304,                :headers {"Content-Type" "application/json", "ETag" etag}}))))(defroutes app-routes  (GET "/access-200" req (access-200 req) )  (GET "/access-non" req (access-non req) )  (GET "/access" req (access req) )  (ANY "*" req    (print-req req)    "{\"success\":true, \"frame\": \"compojure\"}")  (route/not-found "Not Found"))(def app  (wrap-defaults app-routes my-route));; lein ring server []

人气教程排行