-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix "direct buffer access" issue for Plugin SDK (#2511)
* Add test for direct buffer in request * Safely access request byte buffer * Fix formatting --------- Co-authored-by: Naman Nandan <namankt55@gmail.com>
- Loading branch information
1 parent
53ff6a5
commit 34617bb
Showing
3 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
frontend/server/src/test/java/org/pytorch/serve/util/PluginSdkTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.pytorch.serve.util; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
import io.netty.handler.codec.http.*; | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import org.pytorch.serve.servingsdk.http.Request; | ||
import org.pytorch.serve.servingsdk.impl.ModelServerRequest; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
public class PluginSdkTest { | ||
@Test | ||
public void testReadRequestBodyFromPlugin() throws IOException { | ||
ByteBuf buf = Unpooled.directBuffer(); | ||
buf.writeBytes("test".getBytes()); | ||
FullHttpRequest req = | ||
new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "", buf); | ||
Request request = new ModelServerRequest(req, new QueryStringDecoder("")); | ||
String line = | ||
new BufferedReader(new InputStreamReader(request.getInputStream())).readLine(); | ||
Assert.assertEquals(line, "test"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters