Skip to content

Fixed buffer size issue #901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,12 @@ public interface BrowserMobProxy {
*/
void addResponseFilter(ResponseFilter filter);

/**
* Adds a new ResponseFilter that can be used to examine and manipulate the response before sending it to the client.
*
* @param filter filter instance
*/
void addResponseFilterWithCustomBufferSize(ResponseFilter filter, int size);
/**
* Adds a new RequestFilter that can be used to examine and manipulate the request before sending it to the server.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,16 @@ public void addResponseFilter(ResponseFilter filter) {
addLastHttpFilterFactory(new ResponseFilterAdapter.FilterSource(filter));
}

/**
* <b>Note:</b> The current implementation of this method forces a maximum response size of 2 MiB. To adjust the maximum response size, or
* to disable aggregation (which disallows access to the {@link net.lightbody.bmp.util.HttpMessageContents}), you may add the filter source
* directly: <code>addFirstHttpFilterFactory(new ResponseFilterAdapter.FilterSource(filter, bufferSizeInBytes));</code>
*/
@Override
public void addResponseFilterWithCustomBufferSize(ResponseFilter filter, int bufferSize) {
addLastHttpFilterFactory(new ResponseFilterAdapter.FilterSource(filter, bufferSize));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's difference between addLast or addFirst ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For modifying request we use addFirstHttpFilterFactory and for modifying response we used addLastHttpFilterFactory

}

/**
* <b>Note:</b> The current implementation of this method forces a maximum request size of 2 MiB. To adjust the maximum request size, or
* to disable aggregation (which disallows access to the {@link net.lightbody.bmp.util.HttpMessageContents}), you may add the filter source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,11 @@ public void addResponseFilter(ResponseFilter filter) {
LOG.warn("The legacy ProxyServer implementation does not support addRequestFilter and addResponseFilter. Use addRequestInterceptor/addResponseInterceptor instead.");
}

@Override
public void addResponseFilterWithCustomBufferSize(ResponseFilter filter, int bufferSize) {
LOG.warn("The legacy ProxyServer implementation does not support addResquestFilterWithCustomBufferSize and addResponseFilterWithCustomBufferSize. Use addRequestInterceptor/addResponseInterceptor instead.");
}

@Override
public void addRequestFilter(RequestFilter filter) {
LOG.warn("The legacy ProxyServer implementation does not support addRequestFilter and addResponseFilter. Use addRequestInterceptor/addResponseInterceptor instead.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,17 @@ public Reply<?> addResponseFilter(@Named("port") int port, Request<String> reque
String script = getEntityBodyFromRequest(request);
requestResponseFilter.setResponseFilterScript(script);

proxy.addResponseFilter(requestResponseFilter);
String bufferSize = request.param("bufferSize");
if (bufferSize != null && !bufferSize.isEmpty()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return early instead of conditional checks, and writing repeated code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't return early, because we need to perform some actions depending on this condition.

try {
proxy.addResponseFilterWithCustomBufferSize(requestResponseFilter, Integer.parseInt(bufferSize));
} catch(Exception e) {
proxy.addResponseFilter(requestResponseFilter);
}
}
else {
proxy.addResponseFilter(requestResponseFilter);
}

return Reply.saying().ok();
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>

<log4j.version>2.9.0</log4j.version>
<log4j.version>2.16.0</log4j.version>

<groovy.version>2.4.12</groovy.version>
<groovy-eclipse-batch.version>2.4.3-01</groovy-eclipse-batch.version>
Expand Down