Skip to content

Commit 8fcc366

Browse files
committed
update for v0.4.4
1 parent 34c0c99 commit 8fcc366

19 files changed

+338
-74
lines changed

Configuration.md

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,79 @@ For Clojure
691691
(assoc! response-headers "Server" "My-Test-Server")
692692
phase-done)
693693
```
694-
694+
695+
2.8 Nginx Body Filter
696+
-----------------
697+
698+
We can use nginx body filter to change the response body.
699+
700+
* **Java**
701+
702+
A stream faced Java body filter should implement the interface NginxJavaBodyFilter which has this method:
703+
```java
704+
public Object[] doFilter(Map<String, Object> request, InputStream bodyChunk, boolean isLast) throws IOException;
705+
```
706+
707+
For one request this method can be invoked multiple times and at the last time the argument
708+
`isLast` will be true. Note that `bodyChunk` is valid only at its call scope and can
709+
not be stored for later usage.
710+
The result returned must be an array which has three elements viz. {status, headers, filtered_chunk}.
711+
If `status` is not null `filtered_chunk` will be used as the final chunk. `status` and `headers` will
712+
be ignored when the response headers has been sent already.
713+
`filtered_chunk` can be either of
714+
715+
1. File, viz. java.io.File
716+
1. String
717+
1. InputStream
718+
1. Array/Iterable, e.g. Array/List/Set of above types
719+
720+
A string faced Java body filter should extends the class StringFacedJavaBodyFilter which has one protected method to be overriden:
721+
```java
722+
protected Object[] doFilter(Map<String, Object> request, String body, boolean isLast) throws IOException
723+
```
724+
This method has the same return value with `NginxJavaBodyFilter.doFilter`.
725+
726+
e.g.
727+
728+
```nginx
729+
location /hello {
730+
body_filter_type java;
731+
body_filter_name mytest.StringFacedUppercaseBodyFilter;
732+
}
733+
734+
```
735+
736+
```java
737+
public static class StringFacedUppercaseBodyFilter extends StringFacedJavaBodyFilter {
738+
@Override
739+
protected Object[] doFilter(Map<String, Object> request, String body, boolean isLast) throws IOException {
740+
if (isLast) {
741+
return new Object[] {200, null, body.toUpperCase()};
742+
}else {
743+
return new Object[] {null, null, body.toUpperCase()};
744+
}
745+
}
746+
}
747+
```
748+
749+
* **Clojure**
750+
751+
```nginx
752+
location /hello {
753+
body_filter_type clojure;
754+
body_filter_name mytest/uppercase-filter;
755+
}
756+
757+
```
758+
759+
```clojure
760+
(defn uppercase-filter [request body-chunk last?]
761+
(let [upper-body (.toUpperCase body-chunk)]
762+
(if last? {:status 200 :body upper-body}
763+
{:body upper-body})))
764+
```
765+
766+
695767
[nginx-clojure broadcast API]: https://github.com/nginx-clojure/nginx-clojure/issues/38
696768
[Shared Map]: https://nginx-clojure.github.io/sharedmap.html
697769
[Chronicle Map]: https://github.com/OpenHFT/Chronicle-Map

Configuration.md.html

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,3 +691,71 @@ <h2>
691691
(<span class="pl-en">assoc!</span> response-headers <span class="pl-s"><span class="pl-pds">"</span>Xfeep-Header<span class="pl-pds">"</span></span> <span class="pl-s"><span class="pl-pds">"</span>Hello2!<span class="pl-pds">"</span></span>)
692692
(<span class="pl-en">assoc!</span> response-headers <span class="pl-s"><span class="pl-pds">"</span>Server<span class="pl-pds">"</span></span> <span class="pl-s"><span class="pl-pds">"</span>My-Test-Server<span class="pl-pds">"</span></span>)
693693
phase-done)</pre></div>
694+
695+
<h2>
696+
<a id="user-content-28-nginx-body-filter" class="anchor" href="#28-nginx-body-filter" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>2.8 Nginx Body Filter</h2>
697+
698+
<p>We can use nginx body filter to change the response body.</p>
699+
700+
<ul>
701+
<li><strong>Java</strong></li>
702+
</ul>
703+
704+
<p>A stream faced Java body filter should implement the interface NginxJavaBodyFilter which has this method:</p>
705+
706+
<div class="highlight highlight-source-java"><pre><span class="pl-k">public</span> <span class="pl-k">Object</span>[] doFilter(<span class="pl-k">Map&lt;<span class="pl-smi">String</span>, <span class="pl-smi">Object</span>&gt;</span> request, <span class="pl-smi">InputStream</span> bodyChunk, <span class="pl-k">boolean</span> isLast) throws <span class="pl-smi">IOException</span>;</pre></div>
707+
708+
<p>For one request this method can be invoked multiple times and at the last time the argument
709+
<code>isLast</code> will be true. Note that <code>bodyChunk</code> is valid only at its call scope and can
710+
not be stored for later usage.
711+
The result returned must be an array which has three elements viz. {status, headers, filtered_chunk}.
712+
If <code>status</code> is not null <code>filtered_chunk</code> will be used as the final chunk. <code>status</code> and <code>headers</code> will
713+
be ignored when the response headers has been sent already.
714+
<code>filtered_chunk</code> can be either of </p>
715+
716+
<ol>
717+
<li>File, viz. java.io.File</li>
718+
<li>String</li>
719+
<li>InputStream</li>
720+
<li>Array/Iterable, e.g. Array/List/Set of above types</li>
721+
</ol>
722+
723+
<p>A string faced Java body filter should extends the class StringFacedJavaBodyFilter which has one protected method to be overriden:</p>
724+
725+
<div class="highlight highlight-source-java"><pre><span class="pl-k">protected</span> <span class="pl-k">Object</span>[] doFilter(<span class="pl-k">Map&lt;<span class="pl-smi">String</span>, <span class="pl-smi">Object</span>&gt;</span> request, <span class="pl-smi">String</span> body, <span class="pl-k">boolean</span> isLast) throws <span class="pl-smi">IOException</span></pre></div>
726+
727+
<p>This method has the same return value with <code>NginxJavaBodyFilter.doFilter</code>.</p>
728+
729+
<p>e.g.</p>
730+
731+
<div class="highlight highlight-source-nginx"><pre><span class="pl-k">location</span> <span class="pl-en">/hello </span>{
732+
<span class="pl-k">body_filter_type</span> java;
733+
<span class="pl-k">body_filter_name</span> mytest.StringFacedUppercaseBodyFilter;
734+
}
735+
</pre></div>
736+
737+
<div class="highlight highlight-source-java"><pre><span class="pl-k">public</span> <span class="pl-k">static</span> <span class="pl-k">class</span> <span class="pl-en">StringFacedUppercaseBodyFilter</span> <span class="pl-k">extends</span> <span class="pl-e">StringFacedJavaBodyFilter</span> {
738+
<span class="pl-k">@Override</span>
739+
<span class="pl-k">protected</span> <span class="pl-k">Object</span>[] <span class="pl-en">doFilter</span>(<span class="pl-k">Map&lt;<span class="pl-smi">String</span>, <span class="pl-smi">Object</span>&gt;</span> <span class="pl-v">request</span>, <span class="pl-smi">String</span> <span class="pl-v">body</span>, <span class="pl-k">boolean</span> <span class="pl-v">isLast</span>) <span class="pl-k">throws</span> <span class="pl-smi">IOException</span> {
740+
<span class="pl-k">if</span> (isLast) {
741+
<span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-smi">Object</span>[] {<span class="pl-c1">200</span>, <span class="pl-c1">null</span>, body<span class="pl-k">.</span>toUpperCase()};
742+
}<span class="pl-k">else</span> {
743+
<span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-smi">Object</span>[] {<span class="pl-c1">null</span>, <span class="pl-c1">null</span>, body<span class="pl-k">.</span>toUpperCase()};
744+
}
745+
}
746+
}</pre></div>
747+
748+
<ul>
749+
<li><strong>Clojure</strong></li>
750+
</ul>
751+
752+
<div class="highlight highlight-source-nginx"><pre><span class="pl-k">location</span> <span class="pl-en">/hello </span>{
753+
<span class="pl-k">body_filter_type</span> clojure;
754+
<span class="pl-k">body_filter_name</span> mytest/uppercase-filter;
755+
}
756+
</pre></div>
757+
758+
<div class="highlight highlight-source-clojure"><pre>(<span class="pl-k">defn</span> <span class="pl-e">uppercase-filter</span> [request body-chunk last?]
759+
(<span class="pl-k">let</span> [upper-body (<span class="pl-en">.toUpperCase</span> body-chunk)]
760+
(<span class="pl-k">if</span> last? {<span class="pl-c1">:status</span> <span class="pl-c1">200</span> <span class="pl-c1">:body</span> upper-body}
761+
{<span class="pl-c1">:body</span> upper-body})))</pre></div>

CoreFeatures.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
Core Features
22
=================
33

4-
The latest release is v0.4.3, more detail changes about it can be found from [Release History](//nginx-clojure.github.io/downloads.html).
4+
The latest release is v0.4.4, more detail changes about it can be found from [Release History](//nginx-clojure.github.io/downloads.html).
55

66
1. Compatible with [Ring](https://github.com/ring-clojure/ring/blob/master/SPEC) and obviously supports those Ring based frameworks, such as Compojure etc.
77
1. Http Services by using Clojure / Java / Groovy to write simple handlers for http services.
88
1. Nginx Access Handler by Clojure / Java / Groovy
99
1. Nginx Header Filter by Clojure / Java / Groovy
10-
1. **_NEW_**: Pub/Sub Among Nginx Worker Processes
11-
1. **_NEW_**: Shared Map based on shared memory & Shared Map based Ring session store
12-
1. **_NEW_**: Support Sente, see [this PR](https://github.com/ptaoussanis/sente/pull/160)
13-
1. **_NEW_**: Support Per-message Compression Extensions (PMCEs) for WebSocket
10+
1. **_NEW_**: Nginx Body Filter by Clojure / Java / Groovy
11+
1. Pub/Sub Among Nginx Worker Processes
12+
1. Shared Map based on shared memory & Shared Map based Ring session store
13+
1. Support Sente, see [this PR](https://github.com/ptaoussanis/sente/pull/160)
14+
1. Support Per-message Compression Extensions (PMCEs) for WebSocket
1415
1. APIs for Embedding Nginx-Clojure into a Standard Clojure/Java/Groovy App
1516
1. Server Side Websocket
1617
1. A build-in Jersey container to support java standard RESTful web services (JAX-RS 2.0)
@@ -30,7 +31,6 @@ With this feature one java main thread can handle thousands of connections.
3031
1. Supports Linux x64, Linux x86 32bit, Win32, Win64 and Mac OS X. Freebsd version can also be got from Freebsd ports.
3132

3233
By the way it is very fast, the benchmarks can be found [HERE(with wrk2)](https://github.com/ptaoussanis/clojure-web-server-benchmarks/).
33-
3434
Jar Repository
3535
================
3636

@@ -43,19 +43,19 @@ Nginx-Clojure has already been published to https://clojars.org/ whose maven rep
4343
</repository>
4444
```
4545

46-
After adding clojars repository, you can reference nginx-clojure 0.4.3 , e.g.
46+
After adding clojars repository, you can reference nginx-clojure 0.4.4 , e.g.
4747

4848
Leiningen (clojure, no need to add clojars repository which is a default repository for Leiningen)
4949
-----------------
5050

5151
```clojure
52-
[nginx-clojure "0.4.3"]
52+
[nginx-clojure "0.4.4"]
5353
```
5454
Gradle (groovy/java)
5555
-----------------
5656

5757
```
58-
compile "nginx-clojure:nginx-clojure:0.4.3"
58+
compile "nginx-clojure:nginx-clojure:0.4.4"
5959
```
6060
Maven
6161
-----------------
@@ -64,10 +64,16 @@ Maven
6464
<dependency>
6565
<groupId>nginx-clojure</groupId>
6666
<artifactId>nginx-clojure</artifactId>
67-
<version>0.4.3</version>
67+
<version>0.4.4</version>
6868
</dependency>
6969
```
7070

71+
More Documents
72+
=================
73+
74+
More Documents can be found from its web site [nginx-clojure.github.io](http://nginx-clojure.github.io/)
75+
76+
7177
License
7278
=================
7379
Copyright © 2013-2016 Zhang, Yuexiang (xfeep) and released under the BSD 3-Clause license.

CoreFeatures.md.html

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
<h1>
22
<a id="user-content-core-features" class="anchor" href="#core-features" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Core Features</h1>
33

4-
<p>The latest release is v0.4.3, more detail changes about it can be found from <a href="//nginx-clojure.github.io/downloads.html">Release History</a>.</p>
4+
<p>The latest release is v0.4.4, more detail changes about it can be found from <a href="//nginx-clojure.github.io/downloads.html">Release History</a>.</p>
55

66
<ol>
77
<li>Compatible with <a href="https://github.com/ring-clojure/ring/blob/master/SPEC">Ring</a> and obviously supports those Ring based frameworks, such as Compojure etc.</li>
88
<li>Http Services by using Clojure / Java / Groovy to write simple handlers for http services.</li>
99
<li>Nginx Access Handler by Clojure / Java / Groovy</li>
1010
<li>Nginx Header Filter by Clojure / Java / Groovy</li>
1111
<li>
12-
<strong><em>NEW</em></strong>: Pub/Sub Among Nginx Worker Processes</li>
13-
<li>
14-
<strong><em>NEW</em></strong>: Shared Map based on shared memory &amp; Shared Map based Ring session store</li>
15-
<li>
16-
<strong><em>NEW</em></strong>: Support Sente, see <a href="https://github.com/ptaoussanis/sente/pull/160">this PR</a>
12+
<strong><em>NEW</em></strong>: Nginx Body Filter by Clojure / Java / Groovy</li>
13+
<li>Pub/Sub Among Nginx Worker Processes</li>
14+
<li>Shared Map based on shared memory &amp; Shared Map based Ring session store</li>
15+
<li>Support Sente, see <a href="https://github.com/ptaoussanis/sente/pull/160">this PR</a>
1716
</li>
18-
<li>
19-
<strong><em>NEW</em></strong>: Support Per-message Compression Extensions (PMCEs) for WebSocket</li>
17+
<li>Support Per-message Compression Extensions (PMCEs) for WebSocket</li>
2018
<li>APIs for Embedding Nginx-Clojure into a Standard Clojure/Java/Groovy App</li>
2119
<li>Server Side Websocket</li>
2220
<li>A build-in Jersey container to support java standard RESTful web services (JAX-RS 2.0)</li>
@@ -48,17 +46,17 @@ <h1>
4846
&lt;<span class="pl-ent">url</span>&gt;http://clojars.org/repo&lt;/<span class="pl-ent">url</span>&gt;
4947
&lt;/<span class="pl-ent">repository</span>&gt;</pre></div>
5048

51-
<p>After adding clojars repository, you can reference nginx-clojure 0.4.3 , e.g.</p>
49+
<p>After adding clojars repository, you can reference nginx-clojure 0.4.4 , e.g.</p>
5250

5351
<h2>
5452
<a id="user-content--leiningen-clojure-no-need-to-add-clojars-repository-which-is-a-default-repository-for-leiningen-" class="anchor" href="#-leiningen-clojure-no-need-to-add-clojars-repository-which-is-a-default-repository-for-leiningen-" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a> Leiningen (clojure, no need to add clojars repository which is a default repository for Leiningen) </h2>
5553

56-
<div class="highlight highlight-source-clojure"><pre>[nginx-clojure <span class="pl-s"><span class="pl-pds">"</span>0.4.3<span class="pl-pds">"</span></span>]</pre></div>
54+
<div class="highlight highlight-source-clojure"><pre>[nginx-clojure <span class="pl-s"><span class="pl-pds">"</span>0.4.4<span class="pl-pds">"</span></span>]</pre></div>
5755

5856
<h2>
5957
<a id="user-content-gradle-groovyjava" class="anchor" href="#gradle-groovyjava" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Gradle (groovy/java)</h2>
6058

61-
<pre><code>compile "nginx-clojure:nginx-clojure:0.4.3"
59+
<pre><code>compile "nginx-clojure:nginx-clojure:0.4.4"
6260
</code></pre>
6361

6462
<h2>
@@ -67,9 +65,14 @@ <h2>
6765
<div class="highlight highlight-text-xml"><pre>&lt;<span class="pl-ent">dependency</span>&gt;
6866
&lt;<span class="pl-ent">groupId</span>&gt;nginx-clojure&lt;/<span class="pl-ent">groupId</span>&gt;
6967
&lt;<span class="pl-ent">artifactId</span>&gt;nginx-clojure&lt;/<span class="pl-ent">artifactId</span>&gt;
70-
&lt;<span class="pl-ent">version</span>&gt;0.4.3&lt;/<span class="pl-ent">version</span>&gt;
68+
&lt;<span class="pl-ent">version</span>&gt;0.4.4&lt;/<span class="pl-ent">version</span>&gt;
7169
&lt;/<span class="pl-ent">dependency</span>&gt;</pre></div>
7270

71+
<h1>
72+
<a id="user-content-more-documents" class="anchor" href="#more-documents" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>More Documents</h1>
73+
74+
<p>More Documents can be found from its web site <a href="http://nginx-clojure.github.io/">nginx-clojure.github.io</a></p>
75+
7376
<h1>
7477
<a id="user-content-license" class="anchor" href="#license" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>License</h1>
7578

HISTORY.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Downloads & Release History
44
1. [Binaries of Releases](http://sourceforge.net/projects/nginx-clojure/files/)
55
1. [Sources of Releases](https://github.com/nginx-clojure/nginx-clojure/releases)
66

7+
## 0.4.4 (2016-03-04)
8+
9+
1. New Feature: experimental nginx body filter by Java/Clojure/Groovy (issue #107)
10+
1. New Feature: read request body by event callback (issue #109)
11+
1. Bug Fix: 500 (internal server error) returns when committing 2000+ files to nginx as a proxy for apache mod_dav_svn (issue #106)
12+
713
## 0.4.3 (2015-10-25)
814
1. New Feature: Add directive [jvm_classpath][] which supports wildcard character * (issue #95)
915
1. New Feature: Add directive [jvm_classpath_check][] which is enabled by default and when it is enabled access permission about classpaths will be checked.
@@ -166,10 +172,6 @@ Make Clojure/Java/Groovy handler configurations have the same form. e.g. The old
166172
1. Supports Java Thread Pool for handle request
167173
1. Fast Static File Service
168174

169-
[jvm_classpath_check]: //nginx-clojure.github.io/directives.html#jvm_classpath_check
170-
[jvm_classpath]: //nginx-clojure.github.io/directives.html#jvm_classpath
171-
[NginxPubSubTopic(Java)/PubSubTopic(Clojure)]: //nginx-clojure.github.io/subpub.html
172-
[an example project about clojure web dev]: https://github.com/nginx-clojure/nginx-clojure/tree/master/example-projects/clojure-web-example
173175
[jvm_classpath_check]: //nginx-clojure.github.io/directives.html#jvm_classpath_check
174176
[jvm_classpath]: //nginx-clojure.github.io/directives.html#jvm_classpath
175177
[NginxPubSubTopic(Java)/PubSubTopic(Clojure)]: //nginx-clojure.github.io/subpub.html

0 commit comments

Comments
 (0)