compojure-api로 놀고있어 간단한 웹 응용 프로그램의 Content-Type을 관리하려고 할 때 막혔습니다. 내가 원하는 것은 평범한/텍스트 인 HTTP 응답을 내보내는 것이지만 어떻게 든 Compojure-API는 그것을 "application/json"으로 설정한다.어떻게 compojure 응답에 콘텐츠 유형을 명시 적으로 설정할 수 있습니까?
(POST "/echo" []
:new-relic-name "/v1/echo"
:summary "info log the input message and echo it back"
:description nil
:return String
:form-params [message :- String]
(log/infof "/v1/echo message: %s" message)
(let [resp (-> (resp/response message)
(resp/status 200)
(resp/header "Content-Type" "text/plain"))]
(log/infof "response is %s" resp)
resp))
그러나 curl은 서버가 Content-Type : application/json으로 응답 한 것을 보여줍니다.
$ curl -X POST -i --header 'Content-Type: application/x-www-form-urlencoded' -d 'message=frickin compojure-api' 'http://localhost:8080/v1/echo'
HTTP/1.1 200 OK
Date: Fri, 13 Jan 2017 02:04:47 GMT
Content-Type: application/json; charset=utf-8
x-http-request-id: 669dee08-0c92-4fb4-867f-67ff08d7b72f
x-http-caller-id: UNKNOWN_CALLER
Content-Length: 23
Server: Jetty(9.2.10.v20150310)
내 로깅은 해당 기능이 "일반/텍스트"를 요청했지만 프레임 워크가 그것을 넘어 섰다는 것을 보여줍니다.
2017-01-12 18:04:47,581 INFO [qtp789647098-46]kthxbye.v1.api [669dee08-0c92-4fb4-867f-67ff08d7b72f] - response is {:status 200, :headers {"Content-Type" "text/plain"}, :body "frickin compojure-api"}
어떻게 Compojure-API 링 응용 프로그램에서 Content-Type을 제어 할 수 있습니까?
아닌데 REPL에
데모/붙여 넣기와
. 기쁨이 없습니다. 나는 같은 결과를 얻는다. 어떤 미들웨어는 이것을 망쳐 놓고있다. Grrrrr. –
흠. 사실상 미들웨어 여야 만하지만, 나는 그 방법을 알 수 없다. https://github.com/metosin/compojure-api#api-with-schema--swagger-docs 예제처럼이 동작을 유도 할 수 있습니다. 이 스택의 버그와 같은 느낌입니다. 핸들러가 설정 한 컨텐트 유형 헤더를 존중하지 않습니다. 내 코드의 논리가 잘못되었습니다. 나는 Content-Type만큼 단순한 것이 어떤 종류의 도전이라 여기고 매우 놀랐습니다. 그래도 도움을 주셔서 감사합니다. –
다음을보십시오 : https://github.com/ngrunwald/ring-middleware-format/blob/master/src/ring/middleware/format_response.clj#L187. 원하는 엔코더 또는 일치하는 엔코더가없는 경우 첫 번째 엔코더를 선택합니다. compojure-api는 일반/텍스트를 지원하지 않으므로 첫 번째 JSON 인 https : // github을 사용합니다.com/metosin/compojure-api/blob/59b5d2271ac952ee6a7d3bad484f4e1510b18a59/src/compojure/fire/fire. clj # L26 –