Skip to content

Commit

Permalink
add/improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding committed Mar 21, 2022
1 parent 3dfaf14 commit 796df1d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/proxy/lib/http/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const READONLY_MIDDLEWARE_KEYS: (keyof HttpMiddlewareThis<{}>)[] = [
'skipMiddleware',
]

type HttpMiddlewareThis<T> = HttpMiddlewareCtx<T> & ServerCtx & Readonly<{
export type HttpMiddlewareThis<T> = HttpMiddlewareCtx<T> & ServerCtx & Readonly<{
buffers: HttpBuffers

next: () => void
Expand Down
20 changes: 15 additions & 5 deletions packages/proxy/lib/http/response-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import type { CookieOptions } from 'express'
import { cors, concatStream, httpUtils, uri } from '@packages/network'
import type { CypressIncomingRequest, CypressOutgoingResponse } from '@packages/proxy'
import debugModule from 'debug'
import type { HttpMiddleware } from '.'
import type { HttpMiddleware, HttpMiddlewareThis } from '.'
import iconv from 'iconv-lite'
import type { IncomingMessage, IncomingHttpHeaders } from 'http'
import { InterceptResponse } from '@packages/net-stubbing'
import { PassThrough, Readable } from 'stream'
import * as rewriter from './util/rewriter'
import zlib from 'zlib'
import { URL } from 'url'
import type { Browser } from '@packages/server/lib/browsers/types'

export type ResponseMiddleware = HttpMiddleware<{
interface ResponseMiddlewareProps {
/**
* Before using `res.incomingResStream`, `prepareResStream` can be used
* to remove any encoding that prevents it from being returned as plain text.
Expand All @@ -24,7 +25,9 @@ export type ResponseMiddleware = HttpMiddleware<{
isGunzipped: boolean
incomingRes: IncomingMessage
incomingResStream: Readable
}>
}

export type ResponseMiddleware = HttpMiddleware<ResponseMiddlewareProps>

const debug = debugModule('cypress:proxy:http:response-middleware')

Expand Down Expand Up @@ -382,7 +385,7 @@ const MaybePreventCaching: ResponseMiddleware = function () {
this.next()
}

const determineIfNeedsMultiDomainHandling = (ctx) => {
const determineIfNeedsMultiDomainHandling = (ctx: HttpMiddlewareThis<ResponseMiddlewareProps>) => {
const previousAUTRequestUrl = ctx.getPreviousAUTRequestUrl()

// A cookie needs multi-domain handling if it's an AUT request and
Expand All @@ -399,11 +402,18 @@ const determineIfNeedsMultiDomainHandling = (ctx) => {
)
}

interface EnsureSameSiteNoneProps {
cookie: string
browser: Browser | { family: string | null }
isLocalhost: boolean
url: URL
}

const cookieSameSiteRegex = /SameSite=(\w+)/i
const cookieSecureRegex = /Secure/i
const cookieSecureSemicolonRegex = /;\s*Secure/i

const ensureSameSiteNone = ({ cookie, browser, isLocalhost, url }) => {
const ensureSameSiteNone = ({ cookie, browser, isLocalhost, url }: EnsureSameSiteNoneProps) => {
debug('original cookie: %s', cookie)

if (cookieSameSiteRegex.test(cookie)) {
Expand Down

0 comments on commit 796df1d

Please sign in to comment.