Skip to content
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

Support Content-Length and Last-Modified for webview local resources #125994

Merged
merged 1 commit into from
Jun 11, 2021

Conversation

Vtec234
Copy link
Contributor

@Vtec234 Vtec234 commented Jun 11, 2021

Closes #125992

To test (steps from @mjbvz):

  1. At the top of your workspace, create markdown
  2. Also create an image called img.png
  3. In markdown preview, add the content:
<script>
  fetch('img.png', {
    method: 'HEAD'
}).then(async (e) => {
    console.log(e.status);
    console.log(e.headers.get('content-type'));
    console.log(e.headers.get('content-length'));
    console.log(e.headers.get('last-modified'));
})
</script> 
  1. Open the markdown preview and make sure scripts are enabled (there should be a warning if they are not)
  2. Open the developer tools, check that the header contents have been printed and are correct
  3. Same steps for a GET request

@ghost
Copy link

ghost commented Jun 11, 2021

CLA assistant check
All CLA requirements met.

@@ -100,7 +100,9 @@ class RequestStore {

/**
* Map of requested paths to responses.
* @typedef {{ type: 'response', body: any, mime: string, etag: string | undefined, } | { type: 'not-modified', mime: string } | undefined} ResourceResponse
* @typedef {{ type: 'response', body: Uint8Array, mime: string, etag: string | undefined, mtime: number | undefined } |
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note the stronger type on body: Uint8Array. AFAICT that's the only type which is ever passed through in a response and rely on it being so to call Uint8Array.byteLength.

@@ -233,15 +235,19 @@ async function processResourceRequest(event, requestUrl) {
}
}

/** @type {Record<String, string>} */
/** @type {Record<string, string>} */
Copy link
Contributor Author

Choose a reason for hiding this comment

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

typo?

@@ -50,7 +52,7 @@ export async function loadLocalResource(
logService: ILogService,
token: CancellationToken,
): Promise<WebviewResourceResponse.StreamResponse> {
logService.debug(`loadLocalResource - being. requestUri=${requestUri}`);
logService.debug(`loadLocalResource - begin. requestUri=${requestUri}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

typo?

@mjbvz mjbvz added this to the June 2021 milestone Jun 11, 2021
@mjbvz mjbvz merged commit 28f0fc4 into microsoft:main Jun 11, 2021
@mjbvz
Copy link
Collaborator

mjbvz commented Jun 11, 2021

Thanks! Will be in the next VS Code insiders build and is scheduled for 1.58

@Vtec234
Copy link
Contributor Author

Vtec234 commented Jun 12, 2021

Thanks! Is the macOS test failure not a concern?

@github-actions github-actions bot locked and limited conversation to collaborators Jul 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide Last-Modified and Content-Length information for webview local resources
2 participants