-
Notifications
You must be signed in to change notification settings - Fork 173
Save Response Headers into the ResponseOnSingleTask #24
Comments
Is there any workaround to get the headers from the ResponseOnSingleTask? |
@brunoribeiro thanks so much for trying parallec. The code changes should be straightforward, but I do not see a workaround directly. How soon will you need this feature? Let me plan the dev work accordingly. |
@jeffpeiyt Thank you for the quick reply. I would love to have it before November, as i'm evaluating parallec for a new feature to be release in December. |
EDITED. Sure. Roughly the following. I will see if I can get them by the end of this week.
etc. |
@brunoribeiro One concern is that saving all the headers will take quite some spaces in memory. Are you looking for a specific pair in the header or want to check all of them? |
@jeffpeiyt the one I am looking is specific to my server implementation, maybe we could pass a list of header keys to be returned if present, but this will surely make it slower as it need to check all them to find the matches. |
@brunoribeiro yes. I am thinking the same way. As long as the needed keys are provided, it is O(K) to get it out where K is the number of needed keys. Most time we may be just interested in 1 or 2 keys in the headers. (K is very small) So I wound not worry much. Also by default we do not fetch this; and this is done in parallel (http worker). |
Done features and basic test @Test
public void hitWebsitesMinSyncWithAllResponses() {
Map<String, Object> responseContext = new HashMap<String, Object>();
pc
.prepareHttpGet("/validateInternals.html")
.setConcurrency(1700)
.handleInWorker()
.saveResponseHeaders(new ResponseHeaderMeta(null, true))
.setTargetHostsFromString(
"www.parallec.io www.jeffpei.com www.restcommander.com")
.execute(new ParallecResponseHandler() {
@Override
public void onCompleted(ResponseOnSingleTask res,
Map<String, Object> responseContext) {
Map<String, List<String>> responseHeaders = res.getResponseHeaders();
for(Entry<String, List<String>> entry: responseHeaders.entrySet()){
logger.info("response header: {} - {}", entry.getKey(), entry.getValue());
}
responseContext.put(res.getHost(), responseHeaders.size());
logger.debug(res.toString());
}
});
for (Object o : responseContext.values()) {
int headerKeySize = Integer.parseInt((String) o);
Asserts.check(headerKeySize > 0,
" Fail to extract http header");
}
//logger.info("Task Pretty Print: \n{}", task.prettyPrintInfo());
}
|
@brunoribeiro ok, a very simple way for the case insensitiveness is to save with all with lower cases. The logs have been updated as above. Are you good with this? responseHeaders.put(key.toLowerCase(Locale.ROOT),
response.getHeaders().get(key)); |
perfect, thank you so much. On Thu, Sep 29, 2016 at 10:03 PM, Yuanteng (Jeff) Pei <
Bruno Ribeiro |
@brunoribeiro thank you for the confirmation. Will add more tests cases / docs and update here after a release |
@brunoribeiro released in version 0.10.1-beta; please let me know for any more questions. |
The response headers are not commonly used. However this may be useful when checking content type or keep alive etc.
The text was updated successfully, but these errors were encountered: