net.lightbody.bmp.core.har.HarEntry Java Examples

The following examples show how to use net.lightbody.bmp.core.har.HarEntry. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpConnectHarCaptureFilter.java    From CapturePacket with MIT License 6 votes vote down vote up
@Override
public void serverToProxyResponseTimedOut() {
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getResponseTimedOutErrorMessage());
    har.getLog().addEntry(harEntry);

    // include this timeout time in the HarTimings object
    long timeoutTimestampNanos = System.nanoTime();

    // if the proxy started to send the request but has not yet finished, we are currently "sending"
    if (sendStartedNanos > 0L && sendFinishedNanos == 0L) {
        harEntry.getTimings().setSend(timeoutTimestampNanos - sendStartedNanos, TimeUnit.NANOSECONDS);
    }
    // if the entire request was sent but the proxy has not begun receiving the response, we are currently "waiting"
    else if (sendFinishedNanos > 0L && responseReceiveStartedNanos == 0L) {
        harEntry.getTimings().setWait(timeoutTimestampNanos - sendFinishedNanos, TimeUnit.NANOSECONDS);
    }
    // if the proxy has already begun to receive the response, we are currenting "receiving"
    else if (responseReceiveStartedNanos > 0L) {
        harEntry.getTimings().setReceive(timeoutTimestampNanos - responseReceiveStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #2
Source File: HttpConnectHarCaptureFilter.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
@Override
public void serverToProxyResponseTimedOut() {
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getResponseTimedOutErrorMessage());
    har.getLog().addEntry(harEntry);

    // include this timeout time in the HarTimings object
    long timeoutTimestampNanos = System.nanoTime();

    // if the proxy started to send the request but has not yet finished, we are currently "sending"
    if (sendStartedNanos > 0L && sendFinishedNanos == 0L) {
        harEntry.getTimings().setSend(timeoutTimestampNanos - sendStartedNanos, TimeUnit.NANOSECONDS);
    }
    // if the entire request was sent but the proxy has not begun receiving the response, we are currently "waiting"
    else if (sendFinishedNanos > 0L && responseReceiveStartedNanos == 0L) {
        harEntry.getTimings().setWait(timeoutTimestampNanos - sendFinishedNanos, TimeUnit.NANOSECONDS);
    }
    // if the proxy has already begun to receive the response, we are currenting "receiving"
    else if (responseReceiveStartedNanos > 0L) {
        harEntry.getTimings().setReceive(timeoutTimestampNanos - responseReceiveStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #3
Source File: ClosestHarEntryElectorImpl.java    From bobcat with Apache License 2.0 6 votes vote down vote up
/**
 * This method returns the most similar entry described by predicate.
 * It is using and algorithm, that filters all requests that doesn't have match with url prefix
 * and finds the best parameters match by checking how many parameters have the same value that
 * predicate defines. The most similar request is elected to being the best match. However, if
 * all requests will be filtered, then null is returned.
 *
 * @param harEntries List of entries to be searched
 * @return bestEntry The most similar entry or null if no request's url match url prefix
 */
@Override
public HarEntry findSimilarEntry(List<HarEntry> harEntries) {
  HarEntry bestEntry = null;
  int bestScore = 0;

  List<HarEntry> matchingUrl = findEntriesWithUrl(predicate, harEntries);

  for (HarEntry harEntry : matchingUrl) {
    QueryStringParameters parametrizable =
        new QueryStringParameters(harEntry.getRequest());
    int harEntryScore = predicate.calculateScore(parametrizable.retrieve());
    if (harEntryScore > bestScore) {
      bestScore = harEntryScore;
      bestEntry = harEntry;
    }
  }
  return bestEntry;
}
 
Example #4
Source File: EntryTabDelegate.java    From CapturePacket with MIT License 6 votes vote down vote up
void showHarEntry(HarEntry harEntry) {
    if (mHarEntry != harEntry) {
        if (mHarEntry != null && mRefreshHandler != null) {
            Message msg = Message.obtain();
            msg.what = CaptureListFragment.RefreshHandler.WHAT_HAR_ENTRY_CHANGED_2;
            msg.obj = mHarEntry;
            mRefreshHandler.sendMessage(msg);
        }
        mHarEntry = harEntry;
        initTab();
        int selectedTabPosition = mTabLayout.getSelectedTabPosition();
        if (selectedTabPosition >= 0) {
            onTabSelected(mTabLayout.getTabAt(selectedTabPosition));
        } else {
            mTabLayout.getTabAt(0).select();
        }
    }

}
 
Example #5
Source File: ContentTabHolder.java    From CapturePacket with MIT License 6 votes vote down vote up
private List<? extends INameValue> getOverViewList(HarEntry harEntry) {
    ArrayList<HarNameValuePair> pairs = new ArrayList<>();
    HarRequest harRequest = harEntry.getRequest();
    HarResponse harResponse = harEntry.getResponse();
    if (harRequest != null) {
        String url = harRequest.getUrl();
        try {
            url = URLDecoder.decode(url, "utf-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        pairs.add(new HarNameValuePair("URL", url));

        pairs.add(new HarNameValuePair("Method", harRequest.getMethod()));
    }
    if (harResponse != null) {
        pairs.add(new HarNameValuePair("Code", harResponse.getStatus() + ""));
        pairs.add(new HarNameValuePair("Size", harResponse.getBodySize() + "Bytes"));
    }
    pairs.add(new HarNameValuePair("TotalTime", harEntry.getTime() + "ms"));
    return pairs;
}
 
Example #6
Source File: JsonPreviewActivity.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_json);
        ButterKnife.bind(this);
//
//        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        setSupportActionBar(toolbar);

        setupActionBar();

        try {
            int pos = getIntent().getIntExtra("pos",-1);
            if(pos > -1){
                HarLog harLog = ((SysApplication) getApplication()).proxy.getHar().getLog();
                HarEntry harEntry = harLog.getEntries().get(pos);
                content = harEntry.getResponse().getContent().getText();
                initViewDelay(content);
            }else{
                finish();
            }
        } catch (Exception e) {
            e.printStackTrace();
            finish();
        }
    }
 
Example #7
Source File: PreviewFragment.java    From AndroidHttpCapture with MIT License 6 votes vote down vote up
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    HarEntry harEntry = harEntryList.get(position);
    holder.rootView.setOnClickListener(new ClickListner(harEntry));
    holder.tv.setText(harEntry.getRequest().getUrl());
    if(harEntry.getResponse().getStatus()>400){
        holder.iconView.setImageDrawable(getResources().getDrawable(R.drawable.ic_error_black_24dp));
    }else if(harEntry.getResponse().getStatus()>300){
        holder.iconView.setImageDrawable(getResources().getDrawable(R.drawable.ic_directions_black_24dp));
    }else if(harEntry.getResponse().getContent().getMimeType().contains("image")) {
        holder.iconView.setImageDrawable(getResources().getDrawable(R.drawable.ic_photo_black_24dp));
    }else{
        holder.iconView.setImageDrawable(getResources().getDrawable(R.drawable.ic_description_black_24dp));
    }
    holder.detailTextView.setText("Status:" + harEntry.getResponse().getStatus() +
            " Size:" + harEntry.getResponse().getBodySize() +
            "Bytes Time:" + harEntry.getTime() + "ms");
}
 
Example #8
Source File: HttpConnectHarCaptureFilter.java    From Dream-Catcher with MIT License 6 votes vote down vote up
@Override
public void serverToProxyResponseTimedOut() {
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getResponseTimedOutErrorMessage());
    har.getLog().addEntry(harEntry);

    // include this timeout time in the HarTimings object
    long timeoutTimestampNanos = System.nanoTime();

    // if the proxy started to send the request but has not yet finished, we are currently "sending"
    if (sendStartedNanos > 0L && sendFinishedNanos == 0L) {
        harEntry.getTimings().setSend(timeoutTimestampNanos - sendStartedNanos, TimeUnit.NANOSECONDS);
    }
    // if the entire request was sent but the proxy has not begun receiving the response, we are currently "waiting"
    else if (sendFinishedNanos > 0L && responseReceiveStartedNanos == 0L) {
        harEntry.getTimings().setWait(timeoutTimestampNanos - sendFinishedNanos, TimeUnit.NANOSECONDS);
    }
    // if the proxy has already begun to receive the response, we are currenting "receiving"
    else if (responseReceiveStartedNanos > 0L) {
        harEntry.getTimings().setReceive(timeoutTimestampNanos - responseReceiveStartedNanos, TimeUnit.NANOSECONDS);
    }
}
 
Example #9
Source File: HttpConnectHarCaptureFilter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
/**
 * Populates timing information in the specified harEntry for failed rquests. Populates as much timing information
 * as possible, up to the point of failure.
 *
 * @param harEntry HAR entry to populate timing information in
 */
private void populateTimingsForFailedCONNECT(HarEntry harEntry) {
    HarTimings timings = harEntry.getTimings();

    if (connectionQueuedNanos > 0L && dnsResolutionStartedNanos > 0L) {
        timings.setBlocked(dnsResolutionStartedNanos - connectionQueuedNanos, TimeUnit.NANOSECONDS);
    }

    if (dnsResolutionStartedNanos > 0L && dnsResolutionFinishedNanos > 0L) {
        timings.setDns(dnsResolutionFinishedNanos - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS);
    }

    if (connectionStartedNanos > 0L && connectionSucceededTimeNanos > 0L) {
        timings.setConnect(connectionSucceededTimeNanos - connectionStartedNanos, TimeUnit.NANOSECONDS);

        if (sslHandshakeStartedNanos > 0L) {
            timings.setSsl(connectionSucceededTimeNanos - this.sslHandshakeStartedNanos, TimeUnit.NANOSECONDS);
        }
    }

    if (sendStartedNanos > 0L && sendFinishedNanos >= 0L) {
        timings.setSend(sendFinishedNanos - sendStartedNanos, TimeUnit.NANOSECONDS);
    }

    if (sendFinishedNanos > 0L && responseReceiveStartedNanos >= 0L) {
        timings.setWait(responseReceiveStartedNanos - sendFinishedNanos, TimeUnit.NANOSECONDS);
    }

    // since this method is for HTTP CONNECT failures only, we can't populate a "received" time, since that would
    // require the CONNECT to be successful, in which case this method wouldn't be called.
}
 
Example #10
Source File: ProxyBasedIT.java    From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License 5 votes vote down vote up
private int getHTTPStatusCode(String expectedURL, Har httpArchive) {
    for (HarEntry entry : httpArchive.getLog().getEntries()) {
        if (entry.getRequest().getUrl().equals(expectedURL)) {
            return entry.getResponse().getStatus();
        }
    }

    return 0;
}
 
Example #11
Source File: BrowserMobProxyIT.java    From Mastering-Selenium-WebDriver-3.0-Second-Edition with MIT License 5 votes vote down vote up
private int getHTTPStatusCode(String expectedURL, Har httpArchive) {
    for (HarEntry entry : httpArchive.getLog().getEntries()) {
        if (entry.getRequest().getUrl().equals(expectedURL)) {
            return entry.getResponse().getStatus();
        }
    }

    return 0;
}
 
Example #12
Source File: TrafficLogContains.java    From bobcat with Apache License 2.0 5 votes vote down vote up
private boolean harEntryMatchesPredicates(HarEntry entry) {
  for (Predicate<HarEntry> predicate : predicates) {
    if (!predicate.apply(entry)) {
      LOG.debug("HarEntry {} discarded by {}", entry.getRequest().getUrl(), predicate);
      return false;
    }
  }
  return true;
}
 
Example #13
Source File: QueryParametersPredicate.java    From bobcat with Apache License 2.0 5 votes vote down vote up
@Override
public boolean apply(HarEntry input) {
  List<HarNameValuePair> inputParams = input.getRequest().getQueryString();
  for (Entry<String, String> expectedParam : expectedParams.entrySet()) {
    if (!isPresent(expectedParam.getKey(), expectedParam.getValue(), inputParams)) {
      return false;
    }
  }
  return true;
}
 
Example #14
Source File: HttpConnectHarCaptureFilter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void proxyToServerResolutionFailed(String hostAndPort) {
    // since this is a CONNECT, which is not handled by the HarCaptureFilter, we need to create and populate the
    // entire HarEntry and add it to this har.
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getResolutionFailedErrorMessage(hostAndPort));
    har.getLog().addEntry(harEntry);

    // record the amount of time we attempted to resolve the hostname in the HarTimings object
    if (dnsResolutionStartedNanos > 0L) {
        harEntry.getTimings().setDns(System.nanoTime() - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS);
    }

    httpConnectTimes.remove(clientAddress);
}
 
Example #15
Source File: HttpConnectHarCaptureFilter.java    From Dream-Catcher with MIT License 5 votes vote down vote up
@Override
public void proxyToServerConnectionFailed() {
    // since this is a CONNECT, which is not handled by the HarCaptureFilter, we need to create and populate the
    // entire HarEntry and add it to this har.
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getConnectionFailedErrorMessage());
    har.getLog().addEntry(harEntry);

    // record the amount of time we attempted to connect in the HarTimings object
    if (connectionStartedNanos > 0L) {
        harEntry.getTimings().setConnect(System.nanoTime() - connectionStartedNanos, TimeUnit.NANOSECONDS);
    }

    httpConnectTimes.remove(clientAddress);
}
 
Example #16
Source File: HttpConnectHarCaptureFilter.java    From CapturePacket with MIT License 5 votes vote down vote up
@Override
public void proxyToServerConnectionFailed() {
    // since this is a CONNECT, which is not handled by the HarCaptureFilter, we need to create and populate the
    // entire HarEntry and add it to this har.
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getConnectionFailedErrorMessage());
    har.getLog().addEntry(harEntry);

    // record the amount of time we attempted to connect in the HarTimings object
    if (connectionStartedNanos > 0L) {
        harEntry.getTimings().setConnect(System.nanoTime() - connectionStartedNanos, TimeUnit.NANOSECONDS);
    }

    httpConnectTimes.remove(clientAddress);
}
 
Example #17
Source File: HttpConnectHarCaptureFilter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
@Override
public void proxyToServerResolutionFailed(String hostAndPort) {
    // since this is a CONNECT, which is not handled by the HarCaptureFilter, we need to create and populate the
    // entire HarEntry and add it to this har.
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getResolutionFailedErrorMessage(hostAndPort));
    har.getLog().addEntry(harEntry);

    // record the amount of time we attempted to resolve the hostname in the HarTimings object
    if (dnsResolutionStartedNanos > 0L) {
        harEntry.getTimings().setDns(System.nanoTime() - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS);
    }

    httpConnectTimes.remove(clientAddress);
}
 
Example #18
Source File: HttpConnectHarCaptureFilter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
@Override
public void proxyToServerConnectionFailed() {
    // since this is a CONNECT, which is not handled by the HarCaptureFilter, we need to create and populate the
    // entire HarEntry and add it to this har.
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getConnectionFailedErrorMessage());
    har.getLog().addEntry(harEntry);

    // record the amount of time we attempted to connect in the HarTimings object
    if (connectionStartedNanos > 0L) {
        harEntry.getTimings().setConnect(System.nanoTime() - connectionStartedNanos, TimeUnit.NANOSECONDS);
    }

    httpConnectTimes.remove(clientAddress);
}
 
Example #19
Source File: HttpConnectHarCaptureFilter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
/**
 * Populates timing information in the specified harEntry for failed rquests. Populates as much timing information
 * as possible, up to the point of failure.
 *
 * @param harEntry HAR entry to populate timing information in
 */
private void populateTimingsForFailedCONNECT(HarEntry harEntry) {
    HarTimings timings = harEntry.getTimings();

    if (connectionQueuedNanos > 0L && dnsResolutionStartedNanos > 0L) {
        timings.setBlocked(dnsResolutionStartedNanos - connectionQueuedNanos, TimeUnit.NANOSECONDS);
    }

    if (dnsResolutionStartedNanos > 0L && dnsResolutionFinishedNanos > 0L) {
        timings.setDns(dnsResolutionFinishedNanos - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS);
    }

    if (connectionStartedNanos > 0L && connectionSucceededTimeNanos > 0L) {
        timings.setConnect(connectionSucceededTimeNanos - connectionStartedNanos, TimeUnit.NANOSECONDS);

        if (sslHandshakeStartedNanos > 0L) {
            timings.setSsl(connectionSucceededTimeNanos - this.sslHandshakeStartedNanos, TimeUnit.NANOSECONDS);
        }
    }

    if (sendStartedNanos > 0L && sendFinishedNanos >= 0L) {
        timings.setSend(sendFinishedNanos - sendStartedNanos, TimeUnit.NANOSECONDS);
    }

    if (sendFinishedNanos > 0L && responseReceiveStartedNanos >= 0L) {
        timings.setWait(responseReceiveStartedNanos - sendFinishedNanos, TimeUnit.NANOSECONDS);
    }

    // since this method is for HTTP CONNECT failures only, we can't populate a "received" time, since that would
    // require the CONNECT to be successful, in which case this method wouldn't be called.
}
 
Example #20
Source File: HarCaptureFilter.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
/**
 * Create a new instance of the HarCaptureFilter that will capture request and response information. If no har is specified in the
 * constructor, this filter will do nothing.
 * <p/>
 * Regardless of the CaptureTypes specified in <code>dataToCapture</code>, the HarCaptureFilter will always capture:
 * <ul>
 *     <li>Request and response sizes</li>
 *     <li>HTTP request and status lines</li>
 *     <li>Page timing information</li>
 * </ul>
 *
 * @param originalRequest the original HttpRequest from the HttpFiltersSource factory
 * @param har a reference to the ProxyServer's current HAR file at the time this request is received (can be null if HAR capture is not required)
 * @param currentPageRef the ProxyServer's currentPageRef at the time this request is received from the client
 * @param dataToCapture the data types to capture for this request. null or empty set indicates only basic information will be
 *                      captured (see {@link net.lightbody.bmp.proxy.CaptureType} for information on data collected for each CaptureType)
 */
public HarCaptureFilter(HttpRequest originalRequest, ChannelHandlerContext ctx, Har har, String currentPageRef, Set<CaptureType> dataToCapture) {
    super(originalRequest, ctx);

    if (har == null) {
        throw new IllegalStateException("Attempted har capture when har is null");
    }

    if (ProxyUtils.isCONNECT(originalRequest)) {
        throw new IllegalStateException("Attempted har capture for HTTP CONNECT request");
    }

    this.clientAddress = (InetSocketAddress) ctx.channel().remoteAddress();

    if (dataToCapture != null && !dataToCapture.isEmpty()) {
        this.dataToCapture = EnumSet.copyOf(dataToCapture);
    } else {
        this.dataToCapture = EnumSet.noneOf(CaptureType.class);
    }

    // we may need to capture both the request and the response, so set up the request/response filters and delegate to them when
    // the corresponding filter methods are invoked. to save time and memory, only set up the capturing filters when
    // we actually need to capture the data.
    if (this.dataToCapture.contains(CaptureType.REQUEST_CONTENT) || this.dataToCapture.contains(CaptureType.REQUEST_BINARY_CONTENT)) {
        requestCaptureFilter = new ClientRequestCaptureFilter(originalRequest);
    } else {
        requestCaptureFilter = null;
    }

    if (this.dataToCapture.contains(CaptureType.RESPONSE_CONTENT) || this.dataToCapture.contains(CaptureType.RESPONSE_BINARY_CONTENT)) {
        responseCaptureFilter = new ServerResponseCaptureFilter(originalRequest, true);
    } else {
        responseCaptureFilter = null;
    }

    this.har = har;

    this.harEntry = new HarEntry(currentPageRef);
}
 
Example #21
Source File: HttpConnectHarCaptureFilter.java    From CapturePacket with MIT License 5 votes vote down vote up
@Override
public void proxyToServerResolutionFailed(String hostAndPort) {
    // since this is a CONNECT, which is not handled by the HarCaptureFilter, we need to create and populate the
    // entire HarEntry and add it to this har.
    HarEntry harEntry = createHarEntryForFailedCONNECT(HarCaptureUtil.getResolutionFailedErrorMessage(hostAndPort));
    har.getLog().addEntry(harEntry);

    // record the amount of time we attempted to resolve the hostname in the HarTimings object
    if (dnsResolutionStartedNanos > 0L) {
        harEntry.getTimings().setDns(System.nanoTime() - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS);
    }

    httpConnectTimes.remove(clientAddress);
}
 
Example #22
Source File: CaptureListAdapter.java    From CapturePacket with MIT License 5 votes vote down vote up
public void onHarEntryChanged(HarEntry entry) {
    if (mHarEntries != null) {
        int index = mHarEntries.indexOf(entry);
        if (index != -1) {
            notifyItemChanged(index);
        }
    }
}
 
Example #23
Source File: CaptureListAdapter.java    From CapturePacket with MIT License 5 votes vote down vote up
public int addHarEntry(HarEntry entry) {
    if (mHarEntries != null) {
        mHarEntries.add(entry);
        int position = mHarEntries.size() - 1;
        notifyItemInserted(position);
        return position;
    }
    return -1;
}
 
Example #24
Source File: SaveHarTask.java    From CapturePacket with MIT License 5 votes vote down vote up
@Override
protected File doInBackground(HarEntry... harEntries) {
    try {
        harEntries[0].writeTo(mOutFile);
        return mOutFile;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #25
Source File: CaptureListAdapter.java    From CapturePacket with MIT License 5 votes vote down vote up
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
    if (results != null) {
        mHarEntries = (List<HarEntry>) results.values;
        notifyDataSetChanged();
        if (mHarEntries == null || mHarEntries.isEmpty() || !mHarEntries.contains(mEntryTabDelegate.mHarEntry)) {
            mEntryTabDelegate.showHarEntry(null);
        }
    }
}
 
Example #26
Source File: HarCaptureFilter.java    From CapturePacket with MIT License 5 votes vote down vote up
/**
 * Create a new instance of the HarCaptureFilter that will capture request and response information. If no har is specified in the
 * constructor, this filter will do nothing.
 * <p/>
 * Regardless of the CaptureTypes specified in <code>dataToCapture</code>, the HarCaptureFilter will always capture:
 * <ul>
 *     <li>Request and response sizes</li>
 *     <li>HTTP request and status lines</li>
 *     <li>Page timing information</li>
 * </ul>
 *
 * @param originalRequest the original HttpRequest from the HttpFiltersSource factory
 * @param har a reference to the ProxyServer's current HAR file at the time this request is received (can be null if HAR capture is not required)
 * @param currentPageRef the ProxyServer's currentPageRef at the time this request is received from the client
 * @param dataToCapture the data types to capture for this request. null or empty set indicates only basic information will be
 *                      captured (see {@link net.lightbody.bmp.proxy.CaptureType} for information on data collected for each CaptureType)
 */
public HarCaptureFilter(HttpRequest originalRequest, ChannelHandlerContext ctx, Har har, String currentPageRef, Set<CaptureType> dataToCapture) {
    super(originalRequest, ctx);

    if (har == null) {
        throw new IllegalStateException("Attempted har capture when har is null");
    }

    if (ProxyUtils.isCONNECT(originalRequest)) {
        throw new IllegalStateException("Attempted har capture for HTTP CONNECT request");
    }

    this.clientAddress = (InetSocketAddress) ctx.channel().remoteAddress();

    if (dataToCapture != null && !dataToCapture.isEmpty()) {
        this.dataToCapture = EnumSet.copyOf(dataToCapture);
    } else {
        this.dataToCapture = EnumSet.noneOf(CaptureType.class);
    }

    // we may need to capture both the request and the response, so set up the request/response filters and delegate to them when
    // the corresponding filter methods are invoked. to save time and memory, only set up the capturing filters when
    // we actually need to capture the data.
    if (this.dataToCapture.contains(CaptureType.REQUEST_CONTENT) || this.dataToCapture.contains(CaptureType.REQUEST_BINARY_CONTENT)) {
        requestCaptureFilter = new ClientRequestCaptureFilter(originalRequest);
    } else {
        requestCaptureFilter = null;
    }

    if (this.dataToCapture.contains(CaptureType.RESPONSE_CONTENT) || this.dataToCapture.contains(CaptureType.RESPONSE_BINARY_CONTENT)) {
        responseCaptureFilter = new ServerResponseCaptureFilter(originalRequest, true);
    } else {
        responseCaptureFilter = null;
    }

    this.har = har;

    this.harEntry = new HarEntry(currentPageRef);
}
 
Example #27
Source File: HttpConnectHarCaptureFilter.java    From CapturePacket with MIT License 5 votes vote down vote up
/**
 * Populates timing information in the specified harEntry for failed rquests. Populates as much timing information
 * as possible, up to the point of failure.
 *
 * @param harEntry HAR entry to populate timing information in
 */
private void populateTimingsForFailedCONNECT(HarEntry harEntry) {
    HarTimings timings = harEntry.getTimings();

    if (connectionQueuedNanos > 0L && dnsResolutionStartedNanos > 0L) {
        timings.setBlocked(dnsResolutionStartedNanos - connectionQueuedNanos, TimeUnit.NANOSECONDS);
    }

    if (dnsResolutionStartedNanos > 0L && dnsResolutionFinishedNanos > 0L) {
        timings.setDns(dnsResolutionFinishedNanos - dnsResolutionStartedNanos, TimeUnit.NANOSECONDS);
    }

    if (connectionStartedNanos > 0L && connectionSucceededTimeNanos > 0L) {
        timings.setConnect(connectionSucceededTimeNanos - connectionStartedNanos, TimeUnit.NANOSECONDS);

        if (sslHandshakeStartedNanos > 0L) {
            timings.setSsl(connectionSucceededTimeNanos - this.sslHandshakeStartedNanos, TimeUnit.NANOSECONDS);
        }
    }

    if (sendStartedNanos > 0L && sendFinishedNanos >= 0L) {
        timings.setSend(sendFinishedNanos - sendStartedNanos, TimeUnit.NANOSECONDS);
    }

    if (sendFinishedNanos > 0L && responseReceiveStartedNanos >= 0L) {
        timings.setWait(responseReceiveStartedNanos - sendFinishedNanos, TimeUnit.NANOSECONDS);
    }

    // since this method is for HTTP CONNECT failures only, we can't populate a "received" time, since that would
    // require the CONNECT to be successful, in which case this method wouldn't be called.
}
 
Example #28
Source File: CaptureListFragment.java    From CapturePacket with MIT License 5 votes vote down vote up
@Override
public void onAddEntry(HarEntry harEntry, int position) {
    if (mHandler != null) {
        Message msg = Message.obtain();
        msg.what = RefreshHandler.WHAT_HAR_ENTRY_ADD;
        msg.obj = harEntry;
        mHandler.sendMessage(msg);
    }
}
 
Example #29
Source File: CaptureListFragment.java    From CapturePacket with MIT License 5 votes vote down vote up
@Override
public void onEntryChanged(HarEntry harEntry,int changeItem) {
    if (mHandler != null) {
        Message msg = Message.obtain();
        msg.what = RefreshHandler.WHAT_HAR_ENTRY_CHANGED;
        msg.obj = harEntry;
        msg.arg1 = changeItem;
        mHandler.sendMessage(msg);
    }
}
 
Example #30
Source File: CaptureListFragment.java    From CapturePacket with MIT License 5 votes vote down vote up
private void saveLog() {
    if (mAdapter != null) {
        HarEntry harEntry = mAdapter.getSelectedHarEntry();
        if (harEntry != null) {
            SaveLogDialog dialog = new SaveLogDialog();
            dialog.setHarEntry(harEntry);
            dialog.show(getChildFragmentManager(),SaveLogDialog.TAG);

        }
    }
}