@@ -32,7 +32,15 @@ public function __construct(
32
32
}
33
33
34
34
private function createProxyResponse (string $ path , IResponse $ response , $ cache = true ): ProxyResponse {
35
+ $ headersToIgnore = ['aa-version ' , 'ex-app-id ' , 'authorization-app-api ' , 'ex-app-version ' , 'aa-request-id ' ];
36
+ $ responseHeaders = [];
37
+ foreach ($ response ->getHeaders () as $ key => $ value ) {
38
+ if (!in_array (strtolower ($ key ), $ headersToIgnore )) {
39
+ $ responseHeaders [$ key ] = $ value [0 ];
40
+ }
41
+ }
35
42
$ content = $ response ->getBody ();
43
+
36
44
$ isHTML = pathinfo ($ path , PATHINFO_EXTENSION ) === 'html ' ;
37
45
if ($ isHTML ) {
38
46
$ nonce = $ this ->nonceManager ->getNonce ();
@@ -43,29 +51,18 @@ private function createProxyResponse(string $path, IResponse $response, $cache =
43
51
);
44
52
}
45
53
46
- $ mime = $ response ->getHeader ('content-type ' );
47
- if (empty ($ mime )) {
54
+ if (empty ($ response ->getHeader ('content-type ' ))) {
48
55
$ mime = $ this ->mimeTypeHelper ->detectPath ($ path );
49
56
if (pathinfo ($ path , PATHINFO_EXTENSION ) === 'wasm ' ) {
50
57
$ mime = 'application/wasm ' ;
51
58
}
52
- }
53
-
54
- $ proxyResponse = new ProxyResponse (
55
- data: $ content ,
56
- length: strlen ($ content ),
57
- mimeType: $ mime ,
58
- );
59
-
60
- $ headersToCopy = ['Content-Disposition ' , 'Last-Modified ' , 'Etag ' ];
61
- foreach ($ headersToCopy as $ element ) {
62
- $ headerValue = $ response ->getHeader ($ element );
63
- if (empty ($ headerValue )) {
64
- $ proxyResponse ->addHeader ($ element , $ headerValue );
59
+ if (!empty ($ mime ) && $ mime != 'application/octet-stream ' ) {
60
+ $ responseHeaders ['Content-Type ' ] = $ mime ;
65
61
}
66
62
}
67
63
68
- if ($ cache && !$ isHTML ) {
64
+ $ proxyResponse = new ProxyResponse ($ response ->getStatusCode (), $ responseHeaders , $ content );
65
+ if ($ cache && !$ isHTML && empty ($ response ->getHeader ('cache-control ' ))) {
69
66
$ proxyResponse ->cacheFor (3600 );
70
67
}
71
68
return $ proxyResponse ;
@@ -75,19 +72,15 @@ private function createProxyResponse(string $path, IResponse $response, $cache =
75
72
#[NoCSRFRequired]
76
73
public function ExAppGet (string $ appId , string $ other ): Response {
77
74
$ exApp = $ this ->exAppService ->getExApp ($ appId );
78
- if ($ exApp === null ) {
79
- return new NotFoundResponse ();
80
- }
81
- if (!$ exApp ->getEnabled ()) {
75
+ if ($ exApp === null || !$ exApp ->getEnabled ()) {
82
76
return new NotFoundResponse ();
83
77
}
84
78
85
79
$ response = $ this ->service ->requestToExApp (
86
80
$ exApp , '/ ' . $ other , $ this ->userId , 'GET ' , request: $ this ->request
87
81
);
88
82
if (is_array ($ response )) {
89
- $ error_response = new Response ();
90
- return $ error_response ->setStatus (500 );
83
+ return (new Response ())->setStatus (500 );
91
84
}
92
85
return $ this ->createProxyResponse ($ other , $ response );
93
86
}
@@ -96,21 +89,16 @@ public function ExAppGet(string $appId, string $other): Response {
96
89
#[NoCSRFRequired]
97
90
public function ExAppPost (string $ appId , string $ other ): Response {
98
91
$ exApp = $ this ->exAppService ->getExApp ($ appId );
99
- if ($ exApp === null ) {
100
- return new NotFoundResponse ();
101
- }
102
- if (!$ exApp ->getEnabled ()) {
92
+ if ($ exApp === null || !$ exApp ->getEnabled ()) {
103
93
return new NotFoundResponse ();
104
94
}
105
95
106
96
$ response = $ this ->service ->aeRequestToExApp (
107
97
$ exApp , '/ ' . $ other , $ this ->userId ,
108
- params: $ this ->request ->getParams (),
109
- request: $ this ->request
98
+ params: $ this ->request ->getParams (), request: $ this ->request
110
99
);
111
100
if (is_array ($ response )) {
112
- $ error_response = new Response ();
113
- return $ error_response ->setStatus (500 );
101
+ return (new Response ())->setStatus (500 );
114
102
}
115
103
return $ this ->createProxyResponse ($ other , $ response );
116
104
}
@@ -119,21 +107,15 @@ public function ExAppPost(string $appId, string $other): Response {
119
107
#[NoCSRFRequired]
120
108
public function ExAppPut (string $ appId , string $ other ): Response {
121
109
$ exApp = $ this ->exAppService ->getExApp ($ appId );
122
- if ($ exApp === null ) {
123
- return new NotFoundResponse ();
124
- }
125
- if (!$ exApp ->getEnabled ()) {
110
+ if ($ exApp === null || !$ exApp ->getEnabled ()) {
126
111
return new NotFoundResponse ();
127
112
}
128
113
129
114
$ response = $ this ->service ->aeRequestToExApp (
130
- $ exApp , '/ ' . $ other , $ this ->userId , 'PUT ' ,
131
- params: $ this ->request ->getParams (),
132
- request: $ this ->request
115
+ $ exApp , '/ ' . $ other , $ this ->userId , 'PUT ' , $ this ->request ->getParams (), request: $ this ->request
133
116
);
134
117
if (is_array ($ response )) {
135
- $ error_response = new Response ();
136
- return $ error_response ->setStatus (500 );
118
+ return (new Response ())->setStatus (500 );
137
119
}
138
120
return $ this ->createProxyResponse ($ other , $ response );
139
121
}
@@ -142,21 +124,15 @@ public function ExAppPut(string $appId, string $other): Response {
142
124
#[NoCSRFRequired]
143
125
public function ExAppDelete (string $ appId , string $ other ): Response {
144
126
$ exApp = $ this ->exAppService ->getExApp ($ appId );
145
- if ($ exApp === null ) {
146
- return new NotFoundResponse ();
147
- }
148
- if (!$ exApp ->getEnabled ()) {
127
+ if ($ exApp === null || !$ exApp ->getEnabled ()) {
149
128
return new NotFoundResponse ();
150
129
}
151
130
152
131
$ response = $ this ->service ->aeRequestToExApp (
153
- $ exApp , '/ ' . $ other , $ this ->userId , 'DELETE ' ,
154
- params: $ this ->request ->getParams (),
155
- request: $ this ->request
132
+ $ exApp , '/ ' . $ other , $ this ->userId , 'DELETE ' , $ this ->request ->getParams (), request: $ this ->request
156
133
);
157
134
if (is_array ($ response )) {
158
- $ error_response = new Response ();
159
- return $ error_response ->setStatus (500 );
135
+ return (new Response ())->setStatus (500 );
160
136
}
161
137
return $ this ->createProxyResponse ($ other , $ response );
162
138
}
0 commit comments