Skip to content

Commit 5fef764

Browse files
Merge pull request #428 from shapehq/proxy-fixed-content-type
Respond with text/plain from /api/proxy and /api/blob
2 parents 59803bb + 9d979c5 commit 5fef764

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

__test__/common/github/RepoRestrictedGitHubClient.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
GetRepositoryContentRequest,
88
GraphQLQueryRequest,
99
UpdatePullRequestCommentRequest,
10-
GitHubClient
1110
} from "@/common";
1211
import { jest } from '@jest/globals';
1312

@@ -37,7 +36,7 @@ describe('RepoRestrictedGitHubClient', () => {
3736
expect(gitHubClient.graphql).toHaveBeenCalledWith(request);
3837
});
3938

40-
it('should check suffix for getRepositoryContent', async () => {
39+
it('should delegate getRepositoryContent to the underlying client', async () => {
4140
const request: GetRepositoryContentRequest = {
4241
repositoryName: 'repo-suffix', path: '',
4342
repositoryOwner: '',
@@ -56,7 +55,7 @@ describe('RepoRestrictedGitHubClient', () => {
5655
await expect(client.getRepositoryContent(request)).rejects.toThrow("Invalid repository name");
5756
});
5857

59-
it('should check suffix for getPullRequestFiles', async () => {
58+
it('should delegate getPullRequestFiles to the underlying client', async () => {
6059
const request: GetPullRequestFilesRequest = {
6160
repositoryName: 'repo-suffix', pullRequestNumber: 1,
6261
appInstallationId: 0,
@@ -75,7 +74,7 @@ describe('RepoRestrictedGitHubClient', () => {
7574
await expect(client.getPullRequestFiles(request)).rejects.toThrow("Invalid repository name");
7675
});
7776

78-
it('should check suffix for getPullRequestComments', async () => {
77+
it('should delegate getPullRequestComments to the underlying client', async () => {
7978
const request: GetPullRequestCommentsRequest = {
8079
repositoryName: 'repo-suffix', pullRequestNumber: 1,
8180
appInstallationId: 0,
@@ -94,7 +93,7 @@ describe('RepoRestrictedGitHubClient', () => {
9493
await expect(client.getPullRequestComments(request)).rejects.toThrow("Invalid repository name");
9594
});
9695

97-
it('should check suffix for addCommentToPullRequest', async () => {
96+
it('should delegate addCommentToPullRequest to the underlying client', async () => {
9897
const request: AddCommentToPullRequestRequest = {
9998
repositoryName: 'repo-suffix', pullRequestNumber: 1, body: '',
10099
appInstallationId: 0,
@@ -113,7 +112,7 @@ describe('RepoRestrictedGitHubClient', () => {
113112
await expect(client.addCommentToPullRequest(request)).rejects.toThrow("Invalid repository name");
114113
});
115114

116-
it('should check suffix for updatePullRequestComment', async () => {
115+
it('should delegate updatePullRequestComment to the underlying client', async () => {
117116
const request: UpdatePullRequestCommentRequest = {
118117
repositoryName: 'repo-suffix', commentId: 1, body: '',
119118
appInstallationId: 0,

src/app/api/blob/[owner]/[repository]/[...path]/route.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export async function GET(req: NextRequest, { params }: { params: GetBlobParams
2828
const cacheExpirationInSeconds = 60 * 60 * 24 * 30 // 30 days
2929
headers.set("Content-Type", "image/*");
3030
headers.set("Cache-Control", `max-age=${cacheExpirationInSeconds}`)
31+
} else {
32+
headers.set("Content-Type", "text/plain");
3133
}
3234
return new NextResponse(file, { status: 200, headers })
3335
}

src/app/api/proxy/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export async function GET(req: NextRequest) {
3030
const maxBytes = maxMegabytes * 1024 * 1024
3131
const fileText = await downloadFile({ url, maxBytes, timeoutInSeconds })
3232
checkIfJsonOrYaml(fileText)
33-
return new NextResponse(fileText, { status: 200 })
33+
return new NextResponse(fileText, { status: 200, headers: { "Content-Type": "text/plain" } })
3434
} catch (error) {
3535
if (error instanceof Error == false) {
3636
return makeAPIErrorResponse(500, "An unknown error occurred.")

0 commit comments

Comments
 (0)