MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / useContentView

Function useContentView

web/src/js/components/contentviews/useContentView.tsx:31–61  ·  view source on GitHub ↗
(
    flow: Flow,
    part: HTTPMessage | "request" | "response" | "messages",
    view?: string,
    lines?: number,
    hash?: string,
)

Source from the content-addressed store, hash-verified

29): ContentViewData | undefined;
30
31export function useContentView(
32 flow: Flow,
33 part: HTTPMessage | "request" | "response" | "messages",
34 view?: string,
35 lines?: number,
36 hash?: string,
37): ContentViewData | ContentViewData[] | undefined {
38 const url = MessageUtils.getContentURL(flow, part, view, lines);
39 const cv_json = useContent(url, hash);
40 return useMemo<ContentViewData | undefined>(() => {
41 if (cv_json) {
42 try {
43 return JSON.parse(cv_json);
44 } catch {
45 const err: ContentViewData = {
46 text: cv_json,
47 description: "Network Error",
48 syntax_highlight: "error",
49 view_name: "raw",
50 };
51 if (part === "messages") {
52 return [err];
53 } else {
54 return err;
55 }
56 }
57 } else {
58 return undefined;
59 }
60 }, [cv_json]);
61}

Callers 2

HttpMessageViewFunction · 0.90
MessagesFunction · 0.90

Calls 3

useContentFunction · 0.90
getContentURLMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…